mirror of
https://github.com/samba-team/samba.git
synced 2025-03-27 22:50:26 +03:00
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 <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
parent
accaa2f1f6
commit
0a459c6b2d
@ -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",
|
||||
|
@ -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);
|
||||
|
106
source3/torture/test_matching.c
Normal file
106
source3/torture/test_matching.c
Normal file
@ -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;
|
||||
}
|
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user