dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0018-TESTS-dyndns-tests-support-AAAA-addresses.patch

6cf099
From 73047b51048037689b21925f7d480ffd72a50485 Mon Sep 17 00:00:00 2001
6cf099
From: Pavel Reichl <preichl@redhat.com>
6cf099
Date: Wed, 15 Jul 2015 10:58:38 -0400
6cf099
Subject: [PATCH 18/19] TESTS: dyndns tests support AAAA addresses
6cf099
6cf099
Resolves:
6cf099
https://fedorahosted.org/sssd/ticket/2558
6cf099
---
6cf099
 src/tests/cmocka/test_dyndns.c | 51 +++++++++++++++++++++++++++++++-----------
6cf099
 1 file changed, 38 insertions(+), 13 deletions(-)
6cf099
6cf099
diff --git a/src/tests/cmocka/test_dyndns.c b/src/tests/cmocka/test_dyndns.c
6cf099
index 3214e90c063ea9a4cf6f6bc6507bf4e37b7d23a4..e9d42cea37472b38ae2eb900368f2ce3f409fefc 100644
6cf099
--- a/src/tests/cmocka/test_dyndns.c
6cf099
+++ b/src/tests/cmocka/test_dyndns.c
6cf099
@@ -97,7 +97,9 @@ int __wrap_getifaddrs(struct ifaddrs **_ifap)
6cf099
     struct ifaddrs *ifap_head = NULL;
6cf099
     char *name;
6cf099
     char *straddr;
6cf099
+    int ad_family;
6cf099
     struct sockaddr_in *sa;
6cf099
+    void *dst;
6cf099
 
6cf099
     while ((name = sss_mock_ptr_type(char *)) != NULL) {
6cf099
         straddr = sss_mock_ptr_type(char *);
6cf099
@@ -105,6 +107,7 @@ int __wrap_getifaddrs(struct ifaddrs **_ifap)
6cf099
             errno = EINVAL;
6cf099
             goto fail;
6cf099
         }
6cf099
+        ad_family = sss_mock_type(int);
6cf099
 
6cf099
         ifap = talloc_zero(global_mock_context, struct ifaddrs);
6cf099
         if (ifap == NULL) {
6cf099
@@ -127,15 +130,33 @@ int __wrap_getifaddrs(struct ifaddrs **_ifap)
6cf099
 
6cf099
         /* Do not alocate directly on ifap->ifa_addr to
6cf099
          * avoid alignment warnings */
6cf099
-        sa = talloc(ifap, struct sockaddr_in);
6cf099
+        if (ad_family == AF_INET) {
6cf099
+            sa = talloc(ifap, struct sockaddr_in);
6cf099
+        } else if (ad_family == AF_INET6) {
6cf099
+            sa = (struct sockaddr_in *) talloc(ifap, struct sockaddr_in6);
6cf099
+        } else {
6cf099
+            errno = EINVAL;
6cf099
+            goto fail;
6cf099
+        }
6cf099
+
6cf099
         if (sa == NULL) {
6cf099
             errno = ENOMEM;
6cf099
             goto fail;
6cf099
         }
6cf099
-        sa->sin_family = AF_INET;
6cf099
+
6cf099
+        sa->sin_family = ad_family;
6cf099
+
6cf099
+        if (ad_family == AF_INET) {
6cf099
+            dst = &sa->sin_addr;
6cf099
+        } else if (ad_family == AF_INET6) {
6cf099
+            dst = &((struct sockaddr_in6 *)sa)->sin6_addr;
6cf099
+        } else {
6cf099
+            errno = EINVAL;
6cf099
+            goto fail;
6cf099
+        }
6cf099
 
6cf099
         /* convert straddr into ifa_addr */
6cf099
-        if (inet_pton(AF_INET, straddr, &sa->sin_addr) != 1) {
6cf099
+        if (inet_pton(ad_family, straddr, dst) != 1) {
6cf099
             goto fail;
6cf099
         }
6cf099
 
6cf099
@@ -167,12 +188,16 @@ static void dyndns_test_done(struct tevent_req *req)
6cf099
     ctx->tctx->done = true;
6cf099
 }
6cf099
 
6cf099
-void will_return_getifaddrs(const char *ifname, const char *straddr)
6cf099
+void will_return_getifaddrs(const char *ifname, const char *straddr,
6cf099
+                            int af_family)
6cf099
 {
6cf099
     will_return(__wrap_getifaddrs, ifname);
6cf099
     if (ifname) {
6cf099
         will_return(__wrap_getifaddrs, straddr);
6cf099
     }
6cf099
+    if (straddr) {
6cf099
+        will_return(__wrap_getifaddrs, af_family);
6cf099
+    }
6cf099
 }
6cf099
 
6cf099
 void dyndns_test_get_ifaddr(void **state)
6cf099
@@ -182,9 +207,9 @@ void dyndns_test_get_ifaddr(void **state)
6cf099
     char straddr[128];
6cf099
 
6cf099
     check_leaks_push(dyndns_test_ctx);
6cf099
-    will_return_getifaddrs("eth0", "192.168.0.1");
6cf099
-    will_return_getifaddrs("eth1", "192.168.0.2");
6cf099
-    will_return_getifaddrs(NULL, NULL); /* sentinel */
6cf099
+    will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
6cf099
+    will_return_getifaddrs("eth1", "192.168.0.2", AF_INET);
6cf099
+    will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
6cf099
     ret = sss_iface_addr_list_get(dyndns_test_ctx, "eth0", &addrlist);
6cf099
     assert_int_equal(ret, EOK);
6cf099
 
6cf099
@@ -212,9 +237,9 @@ void dyndns_test_get_multi_ifaddr(void **state)
6cf099
     char straddr[128];
6cf099
 
6cf099
     check_leaks_push(dyndns_test_ctx);
6cf099
-    will_return_getifaddrs("eth0", "192.168.0.2");
6cf099
-    will_return_getifaddrs("eth0", "192.168.0.1");
6cf099
-    will_return_getifaddrs(NULL, NULL); /* sentinel */
6cf099
+    will_return_getifaddrs("eth0", "192.168.0.2", AF_INET);
6cf099
+    will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
6cf099
+    will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
6cf099
     ret = sss_iface_addr_list_get(dyndns_test_ctx, "eth0", &addrlist);
6cf099
     assert_int_equal(ret, EOK);
6cf099
 
6cf099
@@ -253,9 +278,9 @@ void dyndns_test_get_ifaddr_enoent(void **state)
6cf099
     struct sss_iface_addr *addrlist = NULL;
6cf099
 
6cf099
     check_leaks_push(dyndns_test_ctx);
6cf099
-    will_return_getifaddrs("eth0", "192.168.0.1");
6cf099
-    will_return_getifaddrs("eth1", "192.168.0.2");
6cf099
-    will_return_getifaddrs(NULL, NULL); /* sentinel */
6cf099
+    will_return_getifaddrs("eth0", "192.168.0.1", AF_INET);
6cf099
+    will_return_getifaddrs("eth1", "192.168.0.2", AF_INET);
6cf099
+    will_return_getifaddrs(NULL, NULL, 0); /* sentinel */
6cf099
     ret = sss_iface_addr_list_get(dyndns_test_ctx, "non_existing_interface",
6cf099
                                   &addrlist);
6cf099
     assert_int_equal(ret, ENOENT);
6cf099
-- 
6cf099
2.4.3
6cf099