From: Stefan Metzmacher Date: Fri, 18 Jun 2021 21:54:27 +0000 (+0000) Subject: s3:torture: add STR-MATCH-MSWILD test for is_in_path() X-Git-Tag: tevent-0.11.0~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a459c6b2df45895c7a89a65ce736a1402a88dcc;p=thirdparty%2Fsamba.git s3:torture: add STR-MATCH-MSWILD test for is_in_path() 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 Reviewed-by: Ralph Boehme --- diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index 5e9bebdcbce..606e398ea6e 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -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", diff --git a/source3/torture/proto.h b/source3/torture/proto.h index dfcbd815af0..5b740e89b6a 100644 --- a/source3/torture/proto.h +++ b/source3/torture/proto.h @@ -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 index 00000000000..4764c64f296 --- /dev/null +++ b/source3/torture/test_matching.c @@ -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 . +*/ + +#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; +} diff --git a/source3/torture/torture.c b/source3/torture/torture.c index 892d6d6beab..05188019982 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -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, diff --git a/source3/wscript_build b/source3/wscript_build index 47fb2efc9a5..6130d1e3e99 100644 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -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