librpc/rpc: remove dcerpc_binding->localaddress and store it in the options array
[samba.git] / source4 / librpc / tests / binding_string.c
index 01cdfae80d0e6ecd7b170212b1f20bb4cb4315bc..4ea4633e3653e37c4aa18f3b5af84555acf0a807 100644 (file)
@@ -24,6 +24,7 @@
 #include "librpc/rpc/dcerpc.h"
 #include "librpc/rpc/dcerpc_proto.h"
 #include "torture/torture.h"
+#include "lib/util/util_net.h"
 
 static bool test_BindingString(struct torture_context *tctx,
                                                           const void *test_data)
@@ -65,8 +66,9 @@ static bool test_BindingString(struct torture_context *tctx,
        s2 = dcerpc_binding_string(mem_ctx, b2);
        torture_assert(tctx, s != NULL, "Error converting binding back to string"); 
 
-       if (is_ipaddress(b->host))
+       if (b->host && is_ipaddress(b->host)) {
                torture_assert_casestr_equal(tctx, s, s2, "Mismatch while comparing original and from protocol tower generated binding strings");
+       }
 
        return true;
 }
@@ -80,7 +82,7 @@ static const char *test_strings[] = {
        "ncacn_ip_tcp:127.0.0.1",
        "ncacn_ip_tcp:127.0.0.1[20]",
        "ncacn_ip_tcp:127.0.0.1[20,sign]",
-       "ncacn_ip_tcp:127.0.0.1[20,Security=Foobar,sign]",
+       "ncacn_ip_tcp:127.0.0.1[20,sign,Security=Foobar]",
        "ncacn_http:127.0.0.1",
        "ncacn_http:127.0.0.1[78]",
        "ncacn_http:127.0.0.1[78,ProxyServer=myproxy:3128]",
@@ -127,6 +129,13 @@ static bool test_parse_check_results(struct torture_context *tctx)
        torture_assert_int_equal(tctx, b->object.if_version, 0, "object version");
        torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, 
                "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_ip_tcp:$SERVER", &b), "parse");
+       torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_ip_tcp:$SERVER[,sign,localaddress=192.168.1.1]", &b), "parse");
+       torture_assert(tctx, b->transport == NCACN_IP_TCP, "ncacn_ip_tcp expected");
+       torture_assert(tctx, b->flags == DCERPC_SIGN, "sign flag");
+       torture_assert_str_equal(tctx, dcerpc_binding_get_string_option(b, "localaddress"),
+                                "192.168.1.1", "localaddress");
+       torture_assert_str_equal(tctx, "ncacn_ip_tcp:$SERVER[,sign,localaddress=192.168.1.1]",
+                                dcerpc_binding_string(tctx, b), "back to string");
 
        return true;
 }
@@ -155,7 +164,7 @@ static bool test_no_transport(struct torture_context *tctx)
 struct torture_suite *torture_local_binding_string(TALLOC_CTX *mem_ctx)
 {
        int i;
-       struct torture_suite *suite = torture_suite_create(mem_ctx, "BINDING");
+       struct torture_suite *suite = torture_suite_create(mem_ctx, "binding");
 
        for (i = 0; i < ARRAY_SIZE(test_strings); i++) {
                torture_suite_add_simple_tcase_const(suite, test_strings[i],