test_semantic_check.in 4.32 KB
Newer Older
Vitezslav Kriz's avatar
Vitezslav Kriz committed
1 2
#!/bin/sh

3 4
KZONECHECK="@top_builddir@/src/kzonecheck"
DATA="@top_srcdir@/tests/semantic_check_data"
Vitezslav Kriz's avatar
Vitezslav Kriz committed
5

6
. "@top_srcdir@/libtap/tap/libtap.sh"
Vitezslav Kriz's avatar
Vitezslav Kriz committed
7

8
TMPDIR=$(test_tmpdir)
9
LOG="$TMPDIR/log"
10
#param zonefile fatal_error expected_erros_count semcheck_err_msg
11
expect_error()
Vitezslav Kriz's avatar
Vitezslav Kriz committed
12
{
13
	if [ ! -r "$DATA/$1" ]; then
14 15 16
		skip_block 4 "missing zone file for test"
		return
	fi
17
	"$KZONECHECK" -o example.com "$DATA/$1" > "$LOG"
18
	ret=$?
19 20 21
	
	ok "$1 - program return code" test $ret -eq 1

22 23

	grep "error.*(semantic check)" $LOG > /dev/null
24
	ok "$1 - check fatal" test $? -ne $2
25

26
	grep -E "^record '[^']+': ${4}$" $LOG > /dev/null
27
	ok "$1 - check message" test $? -eq 0
28

29
	errors=$(grep "^record " $LOG | wc -l)
30
	ok "$1 - number of found errors" test $errors -eq $3
31 32 33
	if [ $errors != $3 ]; then
		diag "expected errors $3 but found $errors"
	fi
Vitezslav Kriz's avatar
Vitezslav Kriz committed
34 35
}

36 37 38 39 40 41 42
#param zonefile
test_correct()
{
	$KZONECHECK -o example.com "$DATA/$1" > /dev/null
	ok "$1 - correct zone, without error" test $? -eq 0
}

43 44 45
if [ ! -x $KZONECHECK ]; then
	skip_all "kzonecheck is missing or is not executable"
fi
Vitezslav Kriz's avatar
Vitezslav Kriz committed
46

47 48 49
# error messages
# exported from knot/src/zone/semantic-check.c
UNKNOWN="unknown error"
50 51 52 53 54 55 56 57
MISSING_SOA="missing SOA in zone apex"
MISSING_NS_DEL_POINT="missing NS in zone apex"
RRSIG_RDATA_TYPE_COVERED="wrong Type Covered in RRSIG"
RRSIG_RDATA_TTL="wrong Original TTL in RRSIG"
RRSIG_RDATA_EXPIRATION="expired RRSIG"
RRSIG_RDATA_LABELS="wrong Labels in RRSIG"
RRSIG_RDATA_DNSKEY_OWNER="wrong Signer's Name in RRSIG"
RRSIG_NO_RRSIG="missing RRSIG"
58
RRSIG_SIGNED="signed RRSIG"
59 60 61
RRSIG_TTL="wrong RRSIG TTL"
NO_NSEC="missing NSEC"
NSEC_RDATA_BITMAP="incorrect type bitmap in NSEC"
62
NSEC_RDATA_MULTIPLE="multiple NSEC records"
63 64 65 66 67 68 69 70
NSEC_RDATA_CHAIN="incoherent NSEC chain"
NSEC3_NOT_FOUND="missing NSEC3"
NSEC3_INSECURE_DELEGATION_OPT="insecure delegation outside NSEC3 opt-out"
NSEC3_TTL="wrong NSEC3 TLL"
NSEC3_RDATA_CHAIN="incoherent NSEC3 chain"
NSEC3_EXTRA_RECORD="invalid record type in NSEC3 chain"
CNAME_EXTRA_RECORDS="other records exist at CNAME"
DNAME_CHILDREN="child records exist under DNAME"
71 72
CNAME_MULTIPLE="multiple CNAME records"
DNAME_MULTIPLE="multiple DNAME records"
73 74 75
CNAME_WILDCARD_SELF="loop in CNAME processing"
DNAME_WILDCARD_SELF="loop in DNAME processing"
GLUE_RECORD="missing glue record"
76

77
plan_lazy
Vitezslav Kriz's avatar
Vitezslav Kriz committed
78

79
expect_error "cname_extra_01.zone"   1 1 "$CNAME_EXTRA_RECORDS"
80
expect_error "cname_extra_02.signed" 1 1 "$CNAME_EXTRA_RECORDS"
81 82 83
expect_error "cname_multiple.zone"   1 1 "$CNAME_MULTIPLE"
expect_error "dname_children.zone"   1 2 "$DNAME_CHILDREN \\(record is occluded by a parent DNAME\\)"
expect_error "dname_children.zone"   1 2 "$DNAME_CHILDREN \\(records exist below the DNAME\\)"
84

85 86 87 88 89 90 91 92
expect_error "missing_ns.zone" 0 1 "$MISSING_NS_DEL_POINT"
expect_error "missing_glue_01.zone" 0 2 "$GLUE_RECORD"
expect_error "missing_glue_02.zone" 0 1 "$GLUE_RECORD"
expect_error "missing_glue_03.zone" 0 1 "$GLUE_RECORD"
expect_error "different_signer_name.signed" 0 1 "$RRSIG_RDATA_DNSKEY_OWNER \\(record type 'NSEC'\\)"
expect_error "no_rrsig.signed" 0 2 "$RRSIG_NO_RRSIG \\(record type 'A'\\)"
expect_error "no_rrsig_with_delegation.signed" 0 1 "$RRSIG_NO_RRSIG \\(record type 'NSEC'\\)"
expect_error "nsec_broken_chain_01.signed" 0 1 "$NSEC_RDATA_CHAIN"
93
expect_error "nsec_broken_chain_02.signed" 0 1 "$NSEC_RDATA_CHAIN"
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
expect_error "nsec_missing.signed" 0 1 "$NO_NSEC"
expect_error "nsec_multiple.signed" 0 2 "$NSEC_RDATA_MULTIPLE"
expect_error "nsec_wrong_bitmap_01.signed" 0 1 "$NSEC_RDATA_BITMAP"
expect_error "nsec_wrong_bitmap_02.signed" 0 1 "$NSEC_RDATA_BITMAP"
expect_error "nsec3_missing.signed" 0 1 "$NSEC3_NOT_FOUND"
expect_error "nsec3_wrong_bitmap_01.signed" 0 1 "$NSEC_RDATA_BITMAP"
expect_error "nsec3_wrong_bitmap_02.signed" 0 1 "$NSEC_RDATA_BITMAP"
expect_error "nsec3_ds.signed" 0 1 "$NSEC3_NOT_FOUND"
expect_error "nsec3_optout.signed" 0 1 "$NSEC3_INSECURE_DELEGATION_OPT"
expect_error "nsec3_chain_01.signed" 0 1 "$NSEC3_RDATA_CHAIN"
expect_error "nsec3_chain_02.signed" 0 2 "$NSEC3_RDATA_CHAIN"
expect_error "nsec3_chain_03.signed" 0 2 "$NSEC3_RDATA_CHAIN"
expect_error "rrsig_signed.signed" 0 1 "$RRSIG_SIGNED"
expect_error "rrsig_ttl.signed" 0 1 "$RRSIG_TTL \\(record type 'A'\\)"
expect_error "rrsig_rdata_ttl.signed" 0 1 "$RRSIG_RDATA_TTL \\(record type 'A'\\)"
109

110 111
test_correct "no_error_delegaton_bitmap.signed"
test_correct "no_error_nsec3_delegation.signed"
112 113
test_correct "no_error_nsec3_optout.signed"
test_correct "no_error_wildcard_glue.zone"
114 115

rm $LOG