tests: Add a test for the NS record handling.
authorRichard Sharpe <rsharpe@samba.org>
Fri, 20 May 2016 13:36:05 +0000 (06:36 -0700)
committerAndreas Schneider <asn@samba.org>
Tue, 24 May 2016 14:35:51 +0000 (16:35 +0200)
Signed-off-by: Richard Sharpe <rsharpe@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jakub Hrozek <jakub.hrozek@posteo.se>
tests/fake_hosts.in
tests/test_real_res_query.c

index e441f0e9b5843d6bc53a53362496bf5980c46300..19f75510a98c146a4945643b7f23cec239f52aa4 100644 (file)
@@ -1,3 +1,5 @@
+NS cwrap.org ns1.cwrap.org
+NS cwrap.org ns2.cwrap.org
 A brokenrecord.com
 A cwrap.org 127.0.0.21
 AAAA cwrap6.org 2a00:1450:4013:c01::63
@@ -8,3 +10,5 @@ CNAME rwrap.org web.cwrap.org
 CNAME web.cwrap.org www.cwrap.org
 A www.cwrap.org 127.0.0.22
 A krb5.cwrap.org 127.0.0.23
+A ns1.cwrap.org 127.0.0.24
+A ns2.cwrap.org 127.0.0.25
index f563a3d8a6c821f1b4fcfb713a03421a4107dd76..1d688c4792ecd4e120dc8a62812091308abe09e2 100644 (file)
@@ -130,6 +130,42 @@ static void test_res_query_a_record(void **state)
        assert_string_equal(addr, "78.46.80.163");
 }
 
+static void test_res_query_ns_record(void **state)
+{
+       int rv;
+       struct __res_state dnsstate;
+       unsigned char answer[ANSIZE] = { 0 };
+       char addr[INET_ADDRSTRLEN];
+       ns_msg handle;
+       ns_rr rr;   /* expanded resource record */
+
+       (void) state; /* unused */
+
+       memset(&dnsstate, 0, sizeof(struct __res_state));
+       rv = res_ninit(&dnsstate);
+       assert_int_equal(rv, 0);
+
+       rv = res_nquery(&dnsstate, "cwrap.org", ns_c_in, ns_t_ns,
+                       answer, sizeof(answer));
+       assert_in_range(rv, 1, 150);
+
+       printf("dump answer:\n");
+       dump_data(answer, rv);
+
+       ns_initparse(answer, sizeof(answer), &handle);
+       /* The query must finish w/o an error, have two answers and the answer
+        * must be a parseable RR of type A and have the address that our
+        * fake hosts file contains
+        */
+       assert_int_equal(ns_msg_getflag(handle, ns_f_rcode), ns_r_noerror);
+       assert_int_equal(ns_msg_count(handle, ns_s_an), 2);
+       assert_int_equal(ns_parserr(&handle, ns_s_an, 0, &rr), 0);
+       assert_int_equal(ns_rr_type(rr), ns_t_ns);
+       assert_non_null(inet_ntop(AF_INET, ns_rr_rdata(rr),
+                       addr, sizeof(addr)));
+       /*assert_string_equal(addr, "3.110.115.50");*/
+}
+
 static void test_res_query_srv_record(void **state)
 {
        int rv;
@@ -191,6 +227,7 @@ int main(void)
 
        const struct CMUnitTest real_tests[] = {
                cmocka_unit_test(test_res_query_a_record),
+               cmocka_unit_test(test_res_query_ns_record),
                cmocka_unit_test(test_res_query_srv_record),
        };