diff options
author | Gary Lockyer <gary@catalyst.net.nz> | 2020-03-03 10:44:47 +1300 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2020-03-07 06:37:09 +0000 |
commit | d2d2329b11968c000b81b22909f6c4234fc8d101 (patch) | |
tree | d0380f73d24d75f5bbea901640cbb3c7f796930d /lib/audit_logging | |
parent | 56e466b4b849b7269add03faebeb0a63f9cda827 (diff) | |
download | samba-d2d2329b11968c000b81b22909f6c4234fc8d101.tar.gz |
audit_logging tests: Fix timezone validation
test_audit_get_timestamp used the "%Z" format specifier in strptime,
this is non-portable. Updated tests now explicitly set the time zone to
"UTC".
Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Sat Mar 7 06:37:09 UTC 2020 on sn-devel-184
Diffstat (limited to 'lib/audit_logging')
-rw-r--r-- | lib/audit_logging/tests/audit_logging_test.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/audit_logging/tests/audit_logging_test.c b/lib/audit_logging/tests/audit_logging_test.c index 1efb03b0b51..8c949e5f8fc 100644 --- a/lib/audit_logging/tests/audit_logging_test.c +++ b/lib/audit_logging/tests/audit_logging_test.c @@ -796,15 +796,35 @@ static void test_audit_get_timestamp(_UNUSED_ void **state) time_t before; time_t after; time_t actual; + char *env_tz = NULL; + char *orig_tz = NULL; TALLOC_CTX *ctx = talloc_new(NULL); + /* + * Explicitly set the time zone to UTC to make the test easier + */ + env_tz = getenv("TZ"); + if (env_tz != NULL) { + orig_tz = talloc_strdup(ctx, env_tz); + } + setenv("TZ", "UTC", 1); + before = time(NULL); t = audit_get_timestamp(ctx); after = time(NULL); - c = strptime(t, "%a, %d %b %Y %H:%M:%S", &tm); + + /* + * Restore the time zone if we changed it + */ + if (orig_tz != NULL) { + setenv("TZ", orig_tz, 1); + TALLOC_FREE(orig_tz); + } + + assert_non_null(c); tm.tm_isdst = -1; if (c != NULL && *c == '.') { char *e; @@ -812,10 +832,9 @@ static void test_audit_get_timestamp(_UNUSED_ void **state) c = e; } if (c != NULL && *c == ' ') { - struct tm tz; - c = strptime(c, " %Z", &tz); + assert_string_equal(" UTC", c); + c += 4; } - assert_non_null(c); assert_int_equal(0, strlen(c)); actual = mktime(&tm); |