]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:torture: add STR-MATCH-MSWILD test for is_in_path()
authorStefan Metzmacher <metze@samba.org>
Fri, 18 Jun 2021 21:54:27 +0000 (21:54 +0000)
committerStefan Metzmacher <metze@samba.org>
Thu, 1 Jul 2021 13:02:31 +0000 (13:02 +0000)
I want to assert at least some of the behavior as the
next commits will add a new abstraction that should
at least partly behave the same.

Note: case_[in]sensitive_idx is the index to the patterns
in the namelist, set to -1 on non-match, otherwise to
a value >= 0.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/selftest/tests.py
source3/torture/proto.h
source3/torture/test_matching.c [new file with mode: 0644]
source3/torture/torture.c
source3/wscript_build

index 5e9bebdcbce83c35fff1301038543d11e2f3e3f1..606e398ea6e760f21a0ae77e44baadecabe2af5b 100755 (executable)
@@ -281,6 +281,7 @@ local_tests = [
     "LOCAL-RBTREE",
     "LOCAL-MEMCACHE",
     "LOCAL-STREAM-NAME",
+    "LOCAL-STR-MATCH-MSWILD",
     "LOCAL-string_to_sid",
     "LOCAL-sid_to_string",
     "LOCAL-binary_to_sid",
index dfcbd815af095f0b0b390fcd22679ef75d5035e1..5b740e89b6ac96c4d9cc34982e615c1715459d78 100644 (file)
@@ -101,6 +101,7 @@ bool run_nbench2(int dummy);
 bool run_async_echo(int dummy);
 bool run_smb_any_connect(int dummy);
 bool run_addrchange(int dummy);
+bool run_str_match_mswild(int dummy);
 bool run_notify_online(int dummy);
 bool run_nttrans_create(int dummy);
 bool run_nttrans_fsctl(int dummy);
diff --git a/source3/torture/test_matching.c b/source3/torture/test_matching.c
new file mode 100644 (file)
index 0000000..4764c64
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+   Unix SMB/CIFS implementation.
+   Samba utility tests
+   Copyright (C) Stefan Metzmacher 2021
+
+   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 "includes.h"
+#include "proto.h"
+
+bool run_str_match_mswild(int dummy)
+{
+       const char *namelist = "/abc*.txt/xyz*.dat/a0123456789Z/";
+       name_compare_entry *name_entries = NULL;
+       const struct test_name {
+               const char *name;
+               ssize_t case_sensitive_idx;
+               ssize_t case_insensitive_idx;
+       } names[] = {{
+               .name = "/dir/abc123.txt",
+               .case_sensitive_idx = 0,
+               .case_insensitive_idx = 0,
+       },{
+               .name = "/dir/AbC123.TxT",
+               .case_sensitive_idx = -1,
+               .case_insensitive_idx = 0,
+       },{
+               .name = "/dir/xyz123.dat",
+               .case_sensitive_idx = 1,
+               .case_insensitive_idx = 1,
+       },{
+               .name = "/dir/XyZ123.DaT",
+               .case_sensitive_idx = -1,
+               .case_insensitive_idx = 1,
+       },{
+               .name = "/dir/aaa123.jpg",
+               .case_sensitive_idx = -1,
+               .case_insensitive_idx = -1,
+       },{
+               .name = "/dir/a0123456789Z",
+               .case_sensitive_idx = 2,
+               .case_insensitive_idx = 2,
+       },{
+               .name = "/dir/A0123456789z",
+               .case_sensitive_idx = -1,
+               .case_insensitive_idx = 2,
+       }};
+       size_t i;
+       bool ret = true;
+
+       d_fprintf(stderr, "namelist: %s\n", namelist);
+
+       set_namearray(&name_entries, namelist);
+       SMB_ASSERT(name_entries != NULL);
+
+       for (i = 0; i < ARRAY_SIZE(names); i++) {
+               const struct test_name *n = &names[i];
+               bool case_sensitive_match;
+               bool case_insensitive_match;
+               bool ok = true;
+
+               case_sensitive_match = is_in_path(n->name,
+                                                 name_entries,
+                                                 true);
+               if (n->case_sensitive_idx != -1) {
+                       ok &= case_sensitive_match;
+               } else {
+                       ok &= !case_sensitive_match;
+               }
+               case_insensitive_match = is_in_path(n->name,
+                                                   name_entries,
+                                                   false);
+               if (n->case_insensitive_idx != -1) {
+                       ok &= case_insensitive_match;
+               } else {
+                       ok &= !case_insensitive_match;
+               }
+
+               d_fprintf(stderr, "name[%s] "
+                         "case_sensitive[TIDX=%zd;MATCH=%u] "
+                         "case_insensitive[TIDX=%zd;MATCH=%u] "
+                         "%s\n",
+                         n->name,
+                         n->case_sensitive_idx,
+                         case_sensitive_match,
+                         n->case_insensitive_idx,
+                         case_insensitive_match,
+                         ok ? "OK" : "FAIL");
+
+               ret &= ok;
+       }
+
+       return ret;
+}
index 892d6d6beabc32bf9118f1333791c5e7f49e75da..051880199821b60e68c30fb889160a695c56022e 100644 (file)
@@ -15345,6 +15345,10 @@ static struct {
                .name  = "LOCAL-STREAM-NAME",
                .fn    = run_local_stream_name,
        },
+       {
+               .name  = "LOCAL-STR-MATCH-MSWILD",
+               .fn    = run_str_match_mswild,
+       },
        {
                .name  = "WBCLIENT-MULTI-PING",
                .fn    = run_wbclient_multi_ping,
index 47fb2efc9a5d38d395c8286e3f8a5e13b12449ba..6130d1e3e9959d6b3ad40403d58b85ac82ebbe3b 100644 (file)
@@ -1179,6 +1179,7 @@ bld.SAMBA3_BINARY('smbtorture' + bld.env.suffix3,
                         torture/nbench.c
                         torture/test_async_echo.c
                         torture/test_addrchange.c
+                        torture/test_matching.c
                         torture/test_posix_append.c
                         torture/test_posix.c
                         torture/test_nttrans_create.c