summaryrefslogtreecommitdiff
path: root/source4/librpc/tests
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-03-02 14:53:09 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:49:05 -0500
commit1afda7bdde90948027e3230c19753280afb16e96 (patch)
treedda7b444c717d1b2fbabdb18194e4373102176b1 /source4/librpc/tests
parentf653871d770006620533b7dc50f350991d567712 (diff)
downloadsamba-1afda7bdde90948027e3230c19753280afb16e96.tar.gz
samba-1afda7bdde90948027e3230c19753280afb16e96.tar.bz2
samba-1afda7bdde90948027e3230c19753280afb16e96.zip
r21656: Move tests a bit closer to the things they test, should make syncing with samba3 easier.
(This used to be commit 4d755fb5d7adedd1dd8bad917b921324411bfd59)
Diffstat (limited to 'source4/librpc/tests')
-rw-r--r--source4/librpc/tests/binding_string.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/source4/librpc/tests/binding_string.c b/source4/librpc/tests/binding_string.c
new file mode 100644
index 0000000000..f6bf35671e
--- /dev/null
+++ b/source4/librpc/tests/binding_string.c
@@ -0,0 +1,111 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ local testing of RPC binding string parsing
+
+ Copyright (C) Jelmer Vernooij 2004
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "librpc/gen_ndr/epmapper.h"
+#include "librpc/rpc/dcerpc.h"
+#include "torture/torture.h"
+
+static bool test_BindingString(struct torture_context *tctx,
+ const void *test_data)
+{
+ const char *binding = test_data;
+ struct dcerpc_binding *b, *b2;
+ const char *s, *s2;
+ struct epm_tower tower;
+ TALLOC_CTX *mem_ctx = tctx;
+
+ /* Parse */
+ torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(mem_ctx, binding, &b),
+ "Error parsing binding string");
+
+ s = dcerpc_binding_string(mem_ctx, b);
+ torture_assert(tctx, s != NULL, "Error converting binding back to string");
+
+ torture_assert_casestr_equal(tctx, binding, s,
+ "Mismatch while comparing original and regenerated binding strings");
+
+ /* Generate protocol towers */
+ torture_assert_ntstatus_ok(tctx, dcerpc_binding_build_tower(mem_ctx, b, &tower),
+ "Error generating protocol tower");
+
+ /* Convert back to binding and then back to string and compare */
+
+ torture_assert_ntstatus_ok(tctx, dcerpc_binding_from_tower(mem_ctx, &tower, &b2),
+ "Error generating binding from tower for original binding");
+
+ /* Compare to a stripped down version of the binding string because
+ * the protocol tower doesn't contain the extra option data */
+ b->options = NULL;
+
+ b->flags = 0;
+
+ s = dcerpc_binding_string(mem_ctx, b);
+ torture_assert(tctx, s != NULL, "Error converting binding back to string for (stripped down)");
+
+ s2 = dcerpc_binding_string(mem_ctx, b2);
+ torture_assert(tctx, s != NULL, "Error converting binding back to string");
+
+ if (is_ipaddress(b->host))
+ torture_assert_casestr_equal(tctx, s, s2, "Mismatch while comparing original and from protocol tower generated binding strings");
+
+ return true;
+}
+
+static const char *test_strings[] = {
+ "ncacn_np:",
+ "ncalrpc:",
+ "ncalrpc:[,Security=Sane]",
+ "ncacn_np:[rpcecho]",
+ "ncacn_np:127.0.0.1[rpcecho]",
+ "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_http:127.0.0.1",
+ "ncacn_http:127.0.0.1[78]",
+ "ncacn_http:127.0.0.1[78,ProxyServer=myproxy:3128]",
+ "ncacn_np:localhost[rpcecho]",
+ "ncacn_np:[/pipe/rpcecho]",
+ "ncacn_np:localhost[/pipe/rpcecho,sign,seal]",
+ "ncacn_np:[,sign]",
+ "ncadg_ip_udp:",
+ "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_np:localhost",
+ "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_ip_tcp:127.0.0.1",
+ "ncacn_unix_stream:[/tmp/epmapper]",
+ "ncalrpc:[IDENTIFIER]",
+ "ncacn_unix_stream:[/tmp/epmapper,sign]",
+};
+
+struct torture_suite *torture_local_binding_string(TALLOC_CTX *mem_ctx)
+{
+ int i;
+ struct torture_suite *suite = torture_suite_create(mem_ctx,
+ "BINDING");
+
+ for (i = 0; i < ARRAY_SIZE(test_strings); i++) {
+ torture_suite_add_simple_tcase(suite, test_strings[i],
+ test_BindingString, test_strings[i]);
+ }
+
+ return suite;
+}