diff options
author | Mark Karpilovskij <mark.karpilovskij@nic.cz> | 2018-08-16 17:27:23 +0200 |
---|---|---|
committer | Mark Karpilovskij <mark.karpilovskij@nic.cz> | 2018-08-18 15:12:56 +0200 |
commit | ca2f2ea0472adf80a5204ff87cf1cb6c7844b90c (patch) | |
tree | c34f1222c32da4643dc860783a6234e42be200af /tests/libdnssec | |
parent | dnssec_nsec_bitmap_contains(): fixup errors (diff) | |
download | knot-ca2f2ea0472adf80a5204ff87cf1cb6c7844b90c.tar.xz knot-ca2f2ea0472adf80a5204ff87cf1cb6c7844b90c.zip |
tests/libdnssec: Rewrite NSEC bitmap test and make it extensible.
Diffstat (limited to 'tests/libdnssec')
-rw-r--r-- | tests/libdnssec/test_nsec_bitmap.c | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/tests/libdnssec/test_nsec_bitmap.c b/tests/libdnssec/test_nsec_bitmap.c index cf52269bb..37676fe0a 100644 --- a/tests/libdnssec/test_nsec_bitmap.c +++ b/tests/libdnssec/test_nsec_bitmap.c @@ -23,51 +23,80 @@ #include "nsec.h" #include "libknot/descriptor.h" +#define TEST_BITMAP_SIZE 18 + int main(void) { plan_lazy(); + // Which rrtypes will be contained in the bitmap. + int test_contains_count = 8; + enum knot_rr_type test_contains[] = { + KNOT_RRTYPE_A, + KNOT_RRTYPE_NS, + KNOT_RRTYPE_SOA, + KNOT_RRTYPE_RRSIG, + KNOT_RRTYPE_NSEC, + KNOT_RRTYPE_DNSKEY, + KNOT_RRTYPE_SPF, + KNOT_RRTYPE_CAA + }; + + // Which rrtypes will not be contained in the bitmap. + int test_not_contains_count = 4; + enum knot_rr_type test_not_contains[] = { + KNOT_RRTYPE_AAAA, + KNOT_RRTYPE_MX, + KNOT_RRTYPE_AXFR, + KNOT_RRTYPE_CNAME + }; + + // Allocate new bitmap. dnssec_nsec_bitmap_t *bitmap = dnssec_nsec_bitmap_new(); ok(bitmap != NULL, "allocate bitmap"); if (!bitmap) { return 1; } - dnssec_nsec_bitmap_add(bitmap, 1); // A - dnssec_nsec_bitmap_add(bitmap, 2); // NS - dnssec_nsec_bitmap_add(bitmap, 6); // SOA - dnssec_nsec_bitmap_add(bitmap, 15); // MX - dnssec_nsec_bitmap_add(bitmap, 16); // TXT - dnssec_nsec_bitmap_add(bitmap, 28); // AAAA - dnssec_nsec_bitmap_add(bitmap, 44); // SSHFP - dnssec_nsec_bitmap_add(bitmap, 46); // RRSIG - dnssec_nsec_bitmap_add(bitmap, 47); // NSEC - dnssec_nsec_bitmap_add(bitmap, 48); // DNSKEY + // Add the desired RR types to bitmap. + for (int i = 0; i < test_contains_count; i++) { + dnssec_nsec_bitmap_add(bitmap, test_contains[i]); + } size_t size = dnssec_nsec_bitmap_size(bitmap); - ok(size == 9, "valid bitmap size"); - if (size != 9) { + ok(size == TEST_BITMAP_SIZE, "valid bitmap size"); + if (size != TEST_BITMAP_SIZE) { dnssec_nsec_bitmap_free(bitmap); return 1; } - const uint8_t expected[9] = { - 0x00, 0x07, 0x62, 0x01, 0x80, 0x08, 0x00, 0x0b, 0x80 + const uint8_t expected[TEST_BITMAP_SIZE] = { + 0x00, 0x0D, 0x62, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x01, 0x01, 0x40 }; - uint8_t encoded[9] = { 0 }; + uint8_t encoded[TEST_BITMAP_SIZE] = { 0 }; dnssec_nsec_bitmap_write(bitmap, encoded); - ok(memcmp(encoded, expected, 9) == 0, "valid bitmap"); + ok(memcmp(encoded, expected, TEST_BITMAP_SIZE) == 0, "valid bitmap"); - bool contains = dnssec_nsec_bitmap_contains(expected, 9, KNOT_RRTYPE_AAAA); - ok(contains, "bitmap contains AAAA"); - contains = dnssec_nsec_bitmap_contains(expected, 9, KNOT_RRTYPE_CNAME); - ok(!contains, "bitmap does not contain CNAME"); + // Test contained types. + char rrtype_str[50]; + for (int i = 0; i < test_contains_count; i++) { + bool contains = dnssec_nsec_bitmap_contains(encoded, size, test_contains[i]); + (void)knot_rrtype_to_string(test_contains[i], rrtype_str, 50); + ok(contains, "bitmap contains %s", rrtype_str); + } + + // Test not contained types. + for (int i = 0; i < test_not_contains_count; i++) { + bool contains = dnssec_nsec_bitmap_contains(encoded, size, test_not_contains[i]); + (void)knot_rrtype_to_string(test_not_contains[i], rrtype_str, 50); + ok(!contains, "bitmap does not contain %s", rrtype_str); + } dnssec_nsec_bitmap_clear(bitmap); ok(dnssec_nsec_bitmap_size(bitmap) == 0, "bitmap clear"); dnssec_nsec_bitmap_free(bitmap); - return 0; } |