From: Samuel Cabrero Date: Thu, 28 Jan 2021 11:37:30 +0000 (+0100) Subject: s4-torture: Add a test for GUID_from_data_blob X-Git-Tag: tevent-0.11.0~1881 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15934ace717a73e270c2e5ac4fb3d306885b195c;p=thirdparty%2Fsamba.git s4-torture: Add a test for GUID_from_data_blob Signed-off-by: Samuel Cabrero Reviewed-by: Volker Lendecke --- diff --git a/source4/torture/ndr/ndr.c b/source4/torture/ndr/ndr.c index 690301f31b1..dd2cad15e29 100644 --- a/source4/torture/ndr/ndr.c +++ b/source4/torture/ndr/ndr.c @@ -477,11 +477,12 @@ 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] = { + const char *guids[5] = { "00000001-0002-0003-0405-060708090a0b", "{00000001-0002-0003-0405-060708090a0b}", "{00000001-0002-0003-0405-060708090a0B}", /* mixed */ "00000001-0002-0003-0405-060708090A0B", /* upper */ + "01000000020003000405060708090a0b", /* hex string */ }; int i; @@ -510,6 +511,45 @@ static bool test_guid_from_string(struct torture_context *tctx) return true; } +static bool test_guid_from_data_blob(struct torture_context *tctx) +{ + struct GUID g1, exp; + const uint8_t bin[16] = { + 0x01, 0x00, 0x00, 0x00, + 0x02, 0x00, + 0x03, 0x00, + 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b }; + const char *hexstr = "01000000020003000405060708090a0b"; + const DATA_BLOB blobs[2] = { + data_blob_const(bin, sizeof(bin)), + data_blob_string_const(hexstr), + }; + int i; + + exp.time_low = 1; + exp.time_mid = 2; + exp.time_hi_and_version = 3; + exp.clock_seq[0] = 4; + exp.clock_seq[1] = 5; + exp.node[0] = 6; + exp.node[1] = 7; + exp.node[2] = 8; + exp.node[3] = 9; + exp.node[4] = 10; + exp.node[5] = 11; + + for (i = 1; i < ARRAY_SIZE(blobs); i++) { + torture_assert_ntstatus_ok(tctx, + GUID_from_data_blob(&blobs[i], &g1), + "invalid return code"); + torture_assert(tctx, GUID_equal(&g1, &exp), + "UUID parsed incorrectly"); + } + + return true; +} + static bool test_guid_string_valid(struct torture_context *tctx) { struct GUID g; @@ -719,6 +759,9 @@ struct torture_suite *torture_local_ndr(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "guid_from_string", test_guid_from_string); + torture_suite_add_simple_test(suite, "guid_from_data_blob", + test_guid_from_data_blob); + torture_suite_add_simple_test(suite, "guid_from_string_invalid", test_guid_from_string_invalid);