torture: start of a mdssvc packet (un)marshalling testsuite
authorRalph Boehme <slow@samba.org>
Sat, 4 May 2019 06:53:48 +0000 (08:53 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 8 Aug 2019 20:24:32 +0000 (20:24 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
selftest/knownfail.d/samba4.local.mdspkt [new file with mode: 0644]
source4/torture/local/local.c
source4/torture/local/mdspkt.c [new file with mode: 0644]
source4/torture/local/wscript_build
source4/torture/wscript_build

diff --git a/selftest/knownfail.d/samba4.local.mdspkt b/selftest/knownfail.d/samba4.local.mdspkt
new file mode 100644 (file)
index 0000000..fcfc083
--- /dev/null
@@ -0,0 +1 @@
+^samba4.local.mdspkt.empty_cnid_fm\(none\)
index acd88772ab7d042dc66ddb2044a85048d3ea4c97..0403e14697b20c6f2a92e38b44be5ee3fdd8e354 100644 (file)
@@ -77,6 +77,7 @@
        torture_local_fsrvp,
        torture_local_util_str_escape,
        torture_local_tfork,
+       torture_local_mdspkt,
        NULL
 };
 
diff --git a/source4/torture/local/mdspkt.c b/source4/torture/local/mdspkt.c
new file mode 100644 (file)
index 0000000..a73c176
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Tests for mdssvc packets (un)marshalling
+ *
+ * Copyright Ralph Boehme <slow@samba.org> 2019
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "replace.h"
+#include <talloc.h>
+#include "libcli/util/ntstatus.h"
+#include "lib/util/samba_util.h"
+#include "lib/torture/torture.h"
+#include "lib/util/data_blob.h"
+#include "torture/local/proto.h"
+#include "mdssvc/marshalling.h"
+
+static const unsigned char mdspkt_empty_cnid_fm[] = {
+       0x34, 0x33, 0x32, 0x31, 0x33, 0x30, 0x64, 0x6d,
+       0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
+       0x01, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00,
+       0x02, 0x00, 0x00, 0x84, 0x01, 0x00, 0x00, 0x00,
+       0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+       0x01, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00,
+       0x01, 0x00, 0x00, 0x87, 0x08, 0x00, 0x00, 0x00,
+       0x01, 0x00, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00,
+       0x01, 0x00, 0x00, 0x07, 0x08, 0x00, 0x00, 0x00,
+       0x04, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00,
+       0x02, 0x00, 0x00, 0x0a, 0x03, 0x00, 0x00, 0x00,
+       0x05, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00,
+       0x07, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x00
+};
+
+static const char *mdspkt_empty_cnid_fm_dump =
+"DALLOC_CTX(#1): {\n"
+"      sl_array_t(#3): {\n"
+"              uint64_t: 0x0023\n"
+"              CNIDs: unkn1: 0x0, unkn2: 0x0\n"
+"                      DALLOC_CTX(#0): {\n"
+"                      }\n"
+"              sl_filemeta_t(#0): {\n"
+"              }\n"
+"      }\n"
+"}\n";
+
+static bool test_mdspkt_empty_cnid_fm(struct torture_context *tctx)
+{
+       DALLOC_CTX *d = NULL;
+       sl_cnids_t *cnids = NULL;
+       char *dstr = NULL;
+       size_t ncnids;
+       bool ret = true;
+
+       d = dalloc_new(tctx);
+       torture_assert_not_null_goto(tctx, d, ret, done,
+                                    "dalloc_new failed\n");
+
+       ret = sl_unpack(d,
+                       (const char *)mdspkt_empty_cnid_fm,
+                       sizeof(mdspkt_empty_cnid_fm));
+       torture_assert_goto(tctx, ret, ret, done, "sl_unpack failed\n");
+
+       cnids = dalloc_get(d, "DALLOC_CTX", 0, "sl_cnids_t", 1);
+       torture_assert_not_null_goto(tctx, d, ret, done,
+                                    "dalloc_get cnids failed\n");
+
+       ncnids = dalloc_size(cnids->ca_cnids);
+       torture_assert_int_equal_goto(tctx, ncnids, 0, ret, done,
+                                     "Wrong number of CNIDs\n");
+
+       dstr = dalloc_dump(d, 0);
+       torture_assert_not_null_goto(tctx, dstr, ret, done,
+                                    "dalloc_dump failed\n");
+
+       torture_assert_str_equal_goto(tctx, dstr, mdspkt_empty_cnid_fm_dump,
+                                     ret, done, "Bad dump\n");
+
+done:
+       TALLOC_FREE(d);
+       return ret;
+}
+
+struct torture_suite *torture_local_mdspkt(TALLOC_CTX *mem_ctx)
+{
+       struct torture_suite *suite =
+               torture_suite_create(mem_ctx, "mdspkt");
+
+       torture_suite_add_simple_test(suite,
+                                     "empty_cnid_fm",
+                                     test_mdspkt_empty_cnid_fm);
+
+       return suite;
+}
index a79b6d9f10d192bebf616c2f868e3d103c4262b4..654b3f9c27182ca5262b7ce9976538ae8d0cb589 100644 (file)
@@ -27,6 +27,7 @@ TORTURE_LOCAL_SOURCE = '''../../../lib/util/charset/tests/iconv.c
        ../../../lib/util/tests/tfork.c
        verif_trailer.c
        nss_tests.c
+        mdspkt.c
        fsrvp_state.c'''
 
 TORTURE_LOCAL_DEPS = 'RPC_NDR_ECHO TDR LIBCLI_SMB MESSAGING iconv POPT_CREDENTIALS TORTURE_AUTH TORTURE_UTIL TORTURE_NDR TORTURE_LIBCRYPTO share torture_registry %s ldb samdb replace-test RPC_FSS_STATE util_str_escape' % provision
index 7dde54fefbaf25dcd2e9e867bc64e2e4438debed..cc9c26399a5b943193c7ceb1e2c4a68acad6e3d7 100644 (file)
@@ -193,6 +193,8 @@ bld.SAMBA_MODULE('torture_rpc',
                       RPC_NDR_WINSPOOL
                       IREMOTEWINSPOOL_COMMON
                       printer_driver
+                      RPC_NDR_MDSSVC
+                      mdssvc
                       ''' % samba_net + ntvfs_specific['deps'],
                  internal_module=True,
                  enabled=bld.PYTHON_BUILD_IS_ENABLED())