Commit 2f15ea87 authored by Ondřej Surý's avatar Ondřej Surý

Add new C TAP Harness based tests

parent d0729be1
check_PROGRAMS = tests/runtests tests/journal
# -*- mode: makefile; -*-
check_PROGRAMS = \
tests/runtests \
tests/journal \
tests/slab \
tests/hattrie \
tests/dthreads \
tests/events \
tests/acl \
tests/fdset \
tests/base64 \
tests/base32hex \
tests/descriptor \
tests/server \
tests/conf \
tests/rrl \
tests/wire \
tests/dname \
tests/ztree \
tests/dnssec_keys \
tests/dnssec_nsec3 \
tests/dnssec_sign \
tests/dnssec_zone_nsec \
tests/rrset
check_LIBRARIES = tests/tap/libtap.a
AM_CPPFLAGS = -I$(top_srcdir)/src \
-DSYSCONFDIR='"$(sysconfdir)"' -DSBINDIR='"$(sbindir)"'
AM_CPPFLAGS = \
-I$(top_srcdir)/src \
-DSYSCONFDIR='"$(sysconfdir)"' \
-DSBINDIR='"$(sbindir)"'
tests_runtests_CPPFLAGS = \
-DSOURCE='"$(abs_top_srcdir)/tests"' \
......@@ -17,7 +43,25 @@ tests_tap_libtap_a_SOURCES = \
check-local: $(check_PROGRAMS)
cd tests && ./runtests -l $(abs_top_srcdir)/tests/TESTS
tests_journal_LDADD = \
LDADD = \
tests/tap/libtap.a \
src/libknotd.la src/libknots.la \
@LIBOBJS@
EXTRA_DIST += \
tests/data/sample_conf
BUILT_SOURCES = \
tests/sample_conf.rc
CLEANFILES = \
tests/sample_conf.rc
tests_conf_SOURCES = \
tests/conf.c
nodist_tests_conf_SOURCES = \
tests/sample_conf.rc
tests/sample_conf.rc: tests/data/sample_conf
$(top_srcdir)/resource.sh $< >$@
journal
slab
hattrie
dthreads
events
acl
fdset
base64
base32hex
descriptor
server
conf
rrl
wire
dname
ztree
dnssec_keys
dnssec_nsec3
dnssec_sign
dnssec_zone_nsec
rrset
- reimplement lives_ok
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <tests/tap/basic.h>
#include "common/errcode.h"
#include "common/sockaddr.h"
#include "common/acl.h"
int main(int argc, char *argv[])
{
plan(19);
// 1. Create an ACL
acl_match_t *match = NULL;
acl_t *acl = acl_new();
ok(acl != 0, "acl: new");
// 2. Create IPv4 address
sockaddr_t test_v4;
int ret = sockaddr_set(&test_v4, AF_INET, "127.0.0.1", 12345);
ok(ret > 0, "acl: new IPv4 address");
// 3. Create IPv6 address
sockaddr_t test_v6;
ret = sockaddr_set(&test_v6, AF_INET6, "::1", 54321);
ok(ret > 0, "acl: new IPv6 address");
// 4. Create simple IPv4 rule
ret = acl_insert(acl, &test_v4, NULL);
ok(ret == KNOT_EOK, "acl: inserted IPv4 rule");
// 5. Create simple IPv6 rule
ret = acl_insert(acl, &test_v6, NULL);
ok(ret == KNOT_EOK, "acl: inserted IPv6 rule");
// 6. Create simple IPv4 'any port' rule
sockaddr_t test_v4a;
sockaddr_set(&test_v4a, AF_INET, "20.20.20.20", 0);
ret = acl_insert(acl, &test_v4a, NULL);
ok(ret == KNOT_EOK, "acl: inserted IPv4 'any port' rule");
// 7. Attempt to match unmatching address
sockaddr_t unmatch_v4;
sockaddr_set(&unmatch_v4, AF_INET, "10.10.10.10", 24424);
match = acl_find(acl, &unmatch_v4);
ok(match == NULL, "acl: matching non-existing address");
// 8. Attempt to match unmatching IPv6 address
sockaddr_t unmatch_v6;
sockaddr_set(&unmatch_v6, AF_INET6, "2001:db8::1428:57ab", 24424);
match = acl_find(acl, &unmatch_v6);
ok(match == NULL, "acl: matching non-existing IPv6 address");
// 9. Attempt to match matching address
match = acl_find(acl, &test_v4);
ok(match != NULL, "acl: matching existing address");
// 10. Attempt to match matching address
match = acl_find(acl, &test_v6);
ok(match != NULL, "acl: matching existing IPv6 address");
// 11. Attempt to match matching 'any port' address
sockaddr_t match_v4a;
sockaddr_set(&match_v4a, AF_INET, "20.20.20.20", 24424);
match = acl_find(acl, &match_v4a);
ok(match != NULL, "acl: matching existing IPv4 'any port' address");
// 12. Attempt to match matching address without matching port
// FIXME
skip("acl: matching address without matching port");
/* sockaddr_set(&unmatch_v4, AF_INET, "127.0.0.1", 54321);
match = acl_find(acl, &unmatch_v4);
ok(match == NULL, "acl: matching address without matching port"); */
// 13. Invalid parameters
// lives_ok({
acl_delete(0);
acl_insert(0, 0, NULL);
acl_find(0, 0);
acl_truncate(0);
// }, "acl: won't crash with NULL parameters");
ok(1, "acl: won't crash with NULL parameters");
// 14. Attempt to match subnet
sockaddr_t match_pf4, test_pf4;
sockaddr_set(&match_pf4, AF_INET, "192.168.1.0", 0);
sockaddr_setprefix(&match_pf4, 24);
acl_insert(acl, &match_pf4, NULL);
sockaddr_set(&test_pf4, AF_INET, "192.168.1.20", 0);
match = acl_find(acl, &test_pf4);
ok(match != NULL, "acl: searching address in matching prefix /24");
// 15. Attempt to search non-matching subnet
sockaddr_set(&test_pf4, AF_INET, "192.168.2.20", 0);
match = acl_find(acl, &test_pf4);
ok(match == NULL, "acl: searching address in non-matching prefix /24");
// 16. Attempt to match v6 subnet
sockaddr_t match_pf6, test_pf6;
sockaddr_set(&match_pf6, AF_INET6, "2001:0DB8:0400:000e:0:0:0:AB00", 0);
sockaddr_setprefix(&match_pf6, 120);
acl_insert(acl, &match_pf6, NULL);
sockaddr_set(&test_pf6, AF_INET6, "2001:0DB8:0400:000e:0:0:0:AB03", 0);
match = acl_find(acl, &test_pf6);
ok(match != NULL, "acl: searching v6 address in matching prefix /120");
// 17. Attempt to search non-matching subnet
sockaddr_set(&test_pf6, AF_INET6, "2001:0DB8:0400:000e:0:0:0:CCCC", 0);
match = acl_find(acl, &test_pf6);
ok(match == NULL, "acl: searching v6 address in non-matching prefix /120");
// 18. Add preferred node
sockaddr_set(&test_pf4, AF_INET, "192.168.0.0", 0);
sockaddr_setprefix(&test_pf4, 16);
acl_insert(acl, &test_pf4, NULL);
sockaddr_set(&match_pf4, AF_INET, "192.168.1.20", 0);
void *sval = (void*)0x1234;
acl_insert(acl, &match_pf4, sval);
match = acl_find(acl, &match_pf4);
ok(match && match->val == sval, "acl: search for preferred node");
// 19. Scenario after truncating
acl_truncate(acl);
sockaddr_set(&test_pf6, AF_INET6, "2001:a1b0:e11e:50d1::3:300", 0);
acl_insert(acl, &test_pf6, NULL);
sockaddr_set(&test_pf4, AF_INET, "231.17.67.223", 0);
acl_insert(acl, &test_pf4, NULL);
sockaddr_set(&test_pf4, AF_INET, "82.87.48.136", 0);
acl_insert(acl, &test_pf4, NULL);
sockaddr_set(&match_pf4, AF_INET, "82.87.48.136", 12345);
match = acl_find(acl, &match_pf4);
ok(match != NULL, "acl: scenario after truncating");
acl_delete(&acl);
// Return
return 0;
}
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <tests/tap/basic.h>
#include "common/errcode.h"
#include "common/base32hex.h"
#define BUF_LEN 256
int main(int argc, char *argv[])
{
plan(42);
int32_t ret;
uint8_t in[BUF_LEN], ref[BUF_LEN], out[BUF_LEN], out2[BUF_LEN];
uint32_t in_len, ref_len;
// 1. test vector -> ENC -> DEC
strcpy((char *)in, "");
in_len = strlen((char *)in);
strcpy((char *)ref, "");
ref_len = strlen((char *)ref);
ret = base32hex_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "1. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "1. test vector - ENC output content");
}
ret = base32hex_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "1. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "1. test vector - DEC output content");
}
// 2. test vector -> ENC -> DEC
strcpy((char *)in, "f");
in_len = strlen((char *)in);
strcpy((char *)ref, "CO======");
ref_len = strlen((char *)ref);
ret = base32hex_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "2. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "2. test vector - ENC output content");
}
ret = base32hex_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "2. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "2. test vector - DEC output content");
}
// 3. test vector -> ENC -> DEC
strcpy((char *)in, "fo");
in_len = strlen((char *)in);
strcpy((char *)ref, "CPNG====");
ref_len = strlen((char *)ref);
ret = base32hex_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "3. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "3. test vector - ENC output content");
}
ret = base32hex_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "3. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "3. test vector - DEC output content");
}
// 4. test vector -> ENC -> DEC
strcpy((char *)in, "foo");
in_len = strlen((char *)in);
strcpy((char *)ref, "CPNMU===");
ref_len = strlen((char *)ref);
ret = base32hex_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "4. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "4. test vector - ENC output content");
}
ret = base32hex_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "4. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "4. test vector - DEC output content");
}
// 5. test vector -> ENC -> DEC
strcpy((char *)in, "foob");
in_len = strlen((char *)in);
strcpy((char *)ref, "CPNMUOG=");
ref_len = strlen((char *)ref);
ret = base32hex_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "5. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "5. test vector - ENC output content");
}
ret = base32hex_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "5. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "5. test vector - DEC output content");
}
// 6. test vector -> ENC -> DEC
strcpy((char *)in, "fooba");
in_len = strlen((char *)in);
strcpy((char *)ref, "CPNMUOJ1");
ref_len = strlen((char *)ref);
ret = base32hex_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "6. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "6. test vector - ENC output content");
}
ret = base32hex_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "6. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "6. test vector - DEC output content");
}
// 7. test vector -> ENC -> DEC
strcpy((char *)in, "foobar");
in_len = strlen((char *)in);
strcpy((char *)ref, "CPNMUOJ1E8======");
ref_len = strlen((char *)ref);
ret = base32hex_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "7. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "7. test vector - ENC output content");
}
ret = base32hex_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "7. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "7. test vector - DEC output content");
}
// Bad paddings
ret = base32hex_decode((uint8_t *)"AAAAAA==", 8, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ECHAR, "Bad padding length 2");
ret = base32hex_decode((uint8_t *)"AAA=====", 8, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ECHAR, "Bad padding length 5");
ret = base32hex_decode((uint8_t *)"A======", 8, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ECHAR, "Bad padding length 7");
ret = base32hex_decode((uint8_t *)"=======", 8, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ECHAR, "Bad padding length 8");
// Bad data length
ret = base32hex_decode((uint8_t *)"A", 1, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ESIZE, "Bad data length 1");
ret = base32hex_decode((uint8_t *)"AA", 2, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ESIZE, "Bad data length 2");
ret = base32hex_decode((uint8_t *)"AAA", 3, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ESIZE, "Bad data length 3");
ret = base32hex_decode((uint8_t *)"AAAA", 4, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ESIZE, "Bad data length 4");
ret = base32hex_decode((uint8_t *)"AAAAA", 5, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ESIZE, "Bad data length 5");
ret = base32hex_decode((uint8_t *)"AAAAAA", 6, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ESIZE, "Bad data length 6");
ret = base32hex_decode((uint8_t *)"AAAAAAA", 7, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ESIZE, "Bad data length 7");
ret = base32hex_decode((uint8_t *)"AAAAAAAAA", 9, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ESIZE, "Bad data length 9");
// Bad data character
ret = base32hex_decode((uint8_t *)"AAAAAAA$", 8, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ECHAR, "Bad data character dollar");
ret = base32hex_decode((uint8_t *)"AAAAAAA ", 8, out, BUF_LEN);
ok(ret == KNOT_BASE32HEX_ECHAR, "Bad data character space");
return 0;
}
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <tests/tap/basic.h>
#include "common/errcode.h"
#include "common/base64.h"
#define BUF_LEN 256
int main(int argc, char *argv[])
{
plan(36);
int32_t ret;
uint8_t in[BUF_LEN], ref[BUF_LEN], out[BUF_LEN], out2[BUF_LEN];
uint32_t in_len, ref_len;
// 1. test vector -> ENC -> DEC
strcpy((char *)in, "");
in_len = strlen((char *)in);
strcpy((char *)ref, "");
ref_len = strlen((char *)ref);
ret = base64_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "1. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "1. test vector - ENC output content");
}
ret = base64_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "1. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "1. test vector - DEC output content");
}
// 2. test vector -> ENC -> DEC
strcpy((char *)in, "f");
in_len = strlen((char *)in);
strcpy((char *)ref, "Zg==");
ref_len = strlen((char *)ref);
ret = base64_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "2. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "2. test vector - ENC output content");
}
ret = base64_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "2. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "2. test vector - DEC output content");
}
// 3. test vector -> ENC -> DEC
strcpy((char *)in, "fo");
in_len = strlen((char *)in);
strcpy((char *)ref, "Zm8=");
ref_len = strlen((char *)ref);
ret = base64_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "3. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "3. test vector - ENC output content");
}
ret = base64_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "3. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "3. test vector - DEC output content");
}
// 4. test vector -> ENC -> DEC
strcpy((char *)in, "foo");
in_len = strlen((char *)in);
strcpy((char *)ref, "Zm9v");
ref_len = strlen((char *)ref);
ret = base64_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "4. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "4. test vector - ENC output content");
}
ret = base64_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "4. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "4. test vector - DEC output content");
}
// 5. test vector -> ENC -> DEC
strcpy((char *)in, "foob");
in_len = strlen((char *)in);
strcpy((char *)ref, "Zm9vYg==");
ref_len = strlen((char *)ref);
ret = base64_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "5. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "5. test vector - ENC output content");
}
ret = base64_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "5. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "5. test vector - DEC output content");
}
// 6. test vector -> ENC -> DEC
strcpy((char *)in, "fooba");
in_len = strlen((char *)in);
strcpy((char *)ref, "Zm9vYmE=");
ref_len = strlen((char *)ref);
ret = base64_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "6. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "6. test vector - ENC output content");
}
ret = base64_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "6. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "6. test vector - DEC output content");
}
// 7. test vector -> ENC -> DEC
strcpy((char *)in, "foobar");
in_len = strlen((char *)in);
strcpy((char *)ref, "Zm9vYmFy");
ref_len = strlen((char *)ref);
ret = base64_encode(in, in_len, out, BUF_LEN);
ok(ret == ref_len, "7. test vector - ENC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out, ref, ret) == 0, "7. test vector - ENC output content");
}
ret = base64_decode(out, ret, out2, BUF_LEN);
ok(ret == in_len, "7. test vector - DEC output length");
if (ret < 0) {
skip(NULL);
} else {
ok(memcmp(out2, in, ret) == 0, "7. test vector - DEC output content");
}
// Bad paddings
ret = base64_decode((uint8_t *)"A===", 4, out, BUF_LEN);
ok(ret == KNOT_BASE64_ECHAR, "Bad padding length 3");
ret = base64_decode((uint8_t *)"====", 4, out, BUF_LEN);
ok(ret == KNOT_BASE64_ECHAR, "Bad padding length 4");
// Bad data length
ret = base64_decode((uint8_t *)"A", 1, out, BUF_LEN);
ok(ret == KNOT_BASE64_ESIZE, "Bad data length 1");
ret = base64_decode((uint8_t *)"AA", 2, out, BUF_LEN);
ok(ret == KNOT_BASE64_ESIZE, "Bad data length 2");
ret = base64_decode((uint8_t *)"AAA", 3, out, BUF_LEN);
ok(ret == KNOT_BASE64_ESIZE, "Bad data length 3");
ret = base64_decode((uint8_t *)"AAAAA", 5, out, BUF_LEN);
ok(ret == KNOT_BASE64_ESIZE, "Bad data length 5");
// Bad data character
ret = base64_decode((uint8_t *)"AAA$", 4, out, BUF_LEN);
ok(ret == KNOT_BASE64_ECHAR, "Bad data character dollar");
ret = base64_decode((uint8_t *)"AAA ", 4, out, BUF_LEN);
ok(ret == KNOT_BASE64_ECHAR, "Bad data character space");
return 0;
}
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdio.h>
#include <tests/tap/basic.h>
#include "knot/conf/conf.h"
/* Resources. */
#include "sample_conf.rc"
/*! Run all scheduled tests for given parameters.
*/
int main(int argc, char *argv[])
{
plan(21);
// Test 1: Allocate new config
const char *config_fn = "rc:/sample_conf";
conf_t *conf = conf_new(config_fn);
ok(conf != 0, "config_new()");
// Test 2: Parse config
int ret = conf_parse_str(conf, sample_conf_rc);
ok(ret == 0, "parsing configuration file %s", config_fn);
if (ret != 0) {
skip_block(19, NULL);
goto skip_all;
}
// Test 3: Test server version (0-level depth)
is_string("Infinitesimal", conf->version, "server version loaded ok");
// Test 4: Test interfaces (1-level depth)
ok(!EMPTY_LIST(conf->ifaces), "configured interfaces exist");
// Test 5,6,7,8: Interfaces content (2-level depth)
struct node *n = HEAD(conf->ifaces);
conf_iface_t *iface = (conf_iface_t*)n;
is_string("10.10.1.1", iface->address, "interface0 address check");
ok(iface->port == 53531, "interface0 port check");
n = n->next;
iface = (conf_iface_t*)n;
is_string("::0", iface->address, "interface1 address check");
ok(iface->port == 53, "interface1 default port check");
// Test 9,10: Check server key
if(conf->key_count <= 0) {
ok(0, "TSIG key algorithm check - NO KEY FOUND");
ok(0, "TSIG key secret check - NO KEY FOUND");
} else {
knot_tsig_key_t *k = &((conf_key_t *)HEAD(conf->keys))->k;
uint8_t decoded_secret[] = { 0x5a };
ok(k->algorithm == KNOT_TSIG_ALG_HMAC_MD5,
"TSIG key algorithm check");
ok(k->secret.size == sizeof(decoded_secret)
&& memcmp