mirror of
https://github.com/samba-team/samba.git
synced 2025-02-23 09:57:40 +03:00
s4-torture: better, failing, tests for GUID_from_string
These tests reveal that the current implementation accepts all kinds of invalid GUIDs. In particular, we fail on these ones: "00000001-0002-0003-0405--060708090a0" "-0000001-0002-0003-0405-060708090a0b" "-0000001-0002-0003-04-5-060708090a0b" "d0000001-0002-0003-0405-060708090a-b" "00000001- -2-0003-0405-060708090a0b" "00000001-0002-0003-0405- 060708090a0" "0x000001-0002-0003-0405-060708090a0b" "00000001-0x02-0x03-0405-060708090a0b" This test is added to selftest/knownfail. The test for valid string GUIDs is extended to test upper and mixed case GUIDs. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
c0549aea68
commit
6c9a185be2
@ -309,3 +309,4 @@
|
||||
^samba.tests.dcerpc.dnsserver.samba.tests.dcerpc.dnsserver.DnsserverTests.test_add_duplicate_different_type.*
|
||||
^samba.tests.dcerpc.dnsserver.samba.tests.dcerpc.dnsserver.DnsserverTests.test_rank_none.*
|
||||
^samba.tests.dcerpc.dnsserver.samba.tests.dcerpc.dnsserver.DnsserverTests.test_security_descriptor.*
|
||||
^samba4.local.ndr.*.guid_from_string_invalid
|
||||
|
@ -296,17 +296,61 @@ static bool test_guid_from_string_null(struct torture_context *tctx)
|
||||
static bool test_guid_from_string_invalid(struct torture_context *tctx)
|
||||
{
|
||||
struct GUID g1;
|
||||
torture_assert_ntstatus_equal(tctx, NT_STATUS_INVALID_PARAMETER,
|
||||
GUID_from_string("bla", &g1),
|
||||
"parameter not invalid");
|
||||
bool failed = false;
|
||||
int i;
|
||||
const char *bad_guids[] = {
|
||||
"bla",
|
||||
"",
|
||||
/*
|
||||
"00000001-0002-0003-0405-060708090a0b", correct
|
||||
*/
|
||||
"00000001-0002-0003-0405-060708090a0b1", /* too long */
|
||||
"00000001-0002-0003-0405-060708090a0", /* too short */
|
||||
"00000001-0002-0003-0405--060708090a0", /* negative */
|
||||
"00000001-0002-0003--0405-060708090a0", /* negative */
|
||||
"-0000001-0002-0003-0405-060708090a0b", /* negative */
|
||||
"-0000001-0002-0003-04-5-060708090a0b", /* negative */
|
||||
"d0000001-0002-0003-0405-060708090a-b", /* negative */
|
||||
"00000001- -2-0003-0405-060708090a0b", /* negative, space */
|
||||
"00000001-0002-0003-0405- 060708090a0", /* whitespace */
|
||||
" 0000001-0002-0003--0405-060708090a0", /* whitespace */
|
||||
"00000001-0002-0003--0405-060708090a ", /* whitespace */
|
||||
"0000001-00002-0003-04050-60708090a0b", /* misshapen */
|
||||
"00000010-0002-0003-04050-60708090a0b", /* misshapen */
|
||||
"00000001-0002-0003-0405-0z0708090a0b", /* bad char */
|
||||
"00000001-00x2-0x03-0405-060708090a0b", /* bad char (00x) */
|
||||
"0x000001-0002-0003-0405-060708090a0b", /* 0x char */
|
||||
"00000001-0x02-0x03-0405-060708090a0b", /* 0x char */
|
||||
};
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bad_guids); i++) {
|
||||
NTSTATUS status = GUID_from_string(bad_guids[i], &g1);
|
||||
if (! NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
|
||||
torture_comment(tctx, "bad guid %s parsed as OK\n",
|
||||
bad_guids[i]);
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
if (failed) {
|
||||
torture_fail(tctx, "wrongly allowing invalid guids");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool test_guid_from_string(struct torture_context *tctx)
|
||||
{
|
||||
struct GUID g1, exp;
|
||||
/* we are asserting all these guids are valid and equal */
|
||||
const char *guids[4] = {
|
||||
"00000001-0002-0003-0405-060708090a0b",
|
||||
"{00000001-0002-0003-0405-060708090a0b}",
|
||||
"{00000001-0002-0003-0405-060708090a0B}", /* mixed */
|
||||
"00000001-0002-0003-0405-060708090A0B", /* upper */
|
||||
};
|
||||
int i;
|
||||
|
||||
torture_assert_ntstatus_ok(tctx,
|
||||
GUID_from_string("00000001-0002-0003-0405-060708090a0b", &g1),
|
||||
GUID_from_string(guids[0], &g1),
|
||||
"invalid return code");
|
||||
exp.time_low = 1;
|
||||
exp.time_mid = 2;
|
||||
@ -319,12 +363,14 @@ static bool test_guid_from_string(struct torture_context *tctx)
|
||||
exp.node[3] = 9;
|
||||
exp.node[4] = 10;
|
||||
exp.node[5] = 11;
|
||||
torture_assert(tctx, GUID_equal(&g1, &exp), "UUID parsed incorrectly");
|
||||
torture_assert_ntstatus_ok(tctx,
|
||||
GUID_from_string("{00000001-0002-0003-0405-060708090a0b}", &g1),
|
||||
"invalid return code");
|
||||
torture_assert(tctx, GUID_equal(&g1, &exp), "UUID parsed incorrectly");
|
||||
|
||||
for (i = 1; i < ARRAY_SIZE(guids); i++) {
|
||||
torture_assert_ntstatus_ok(tctx,
|
||||
GUID_from_string(guids[i], &g1),
|
||||
"invalid return code");
|
||||
torture_assert(tctx, GUID_equal(&g1, &exp),
|
||||
"UUID parsed incorrectly");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user