aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Sharpe <rsharpe@samba.org>2016-05-20 06:36:05 -0700
committerAndreas Schneider <asn@samba.org>2016-05-24 16:35:51 +0200
commitb89bc402bbc183d5ed2b54862c7229e2ab1d6629 (patch)
tree4d6db8c4ee53206072450419137e2d6c75c260d6
parentcf5b0fa7b6aa76531c8b57e4f0a0c6dab36a8000 (diff)
downloadresolv_wrapper-b89bc402bbc183d5ed2b54862c7229e2ab1d6629.tar.gz
resolv_wrapper-b89bc402bbc183d5ed2b54862c7229e2ab1d6629.tar.xz
resolv_wrapper-b89bc402bbc183d5ed2b54862c7229e2ab1d6629.zip
tests: Add a test for the NS record handling.
Signed-off-by: Richard Sharpe <rsharpe@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jakub Hrozek <jakub.hrozek@posteo.se>
-rw-r--r--tests/fake_hosts.in4
-rw-r--r--tests/test_real_res_query.c37
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/fake_hosts.in b/tests/fake_hosts.in
index e441f0e..19f7551 100644
--- a/tests/fake_hosts.in
+++ b/tests/fake_hosts.in
@@ -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
diff --git a/tests/test_real_res_query.c b/tests/test_real_res_query.c
index f563a3d..1d688c4 100644
--- a/tests/test_real_res_query.c
+++ b/tests/test_real_res_query.c
@@ -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),
};