summaryrefslogtreecommitdiffstats
path: root/test/asn1_time_test.c
diff options
context:
space:
mode:
authorArmin Fuerst <armin@fuerst.priv.at>2022-02-04 20:35:54 +0100
committerTomas Mraz <tomas@openssl.org>2022-02-14 10:18:46 +0100
commit065121ff198a84106023013420dedd57ac4ff53a (patch)
treeff7da729a33d0380267dbc080a528b3d0f1cf6a9 /test/asn1_time_test.c
parentc920020f0bb13f0d2bf0fcad5c7ee63458b633b4 (diff)
Add tests for do_updatedb
Fixes #13944 Moved "opt_printf_stderr" out of apps.c to avoid duplicate definition in tests. Added function "asn1_string_to_time_t" including tests. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17645)
Diffstat (limited to 'test/asn1_time_test.c')
-rw-r--r--test/asn1_time_test.c65
1 files changed, 64 insertions, 1 deletions
diff --git a/test/asn1_time_test.c b/test/asn1_time_test.c
index 9dbad22a2d..2383ec25c9 100644
--- a/test/asn1_time_test.c
+++ b/test/asn1_time_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1999-2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -12,6 +12,7 @@
#include <stdio.h>
#include <string.h>
+#include <crypto/asn1.h>
#include <openssl/asn1.h>
#include <openssl/evp.h>
#include <openssl/objects.h>
@@ -28,6 +29,53 @@ struct testdata {
int convert_result; /* conversion result */
};
+struct TESTDATA_asn1_to_utc {
+ char *input;
+ time_t expected;
+};
+
+static const struct TESTDATA_asn1_to_utc asn1_to_utc[] = {
+ {
+ /*
+ * last second of standard time in central Europe in 2021
+ * specified in GMT
+ */
+ "210328005959Z",
+ 1616893199,
+ },
+ {
+ /*
+ * first second of daylight saving time in central Europe in 2021
+ * specified in GMT
+ */
+ "210328010000Z",
+ 1616893200,
+ },
+ {
+ /*
+ * last second of standard time in central Europe in 2021
+ * specified in offset to GMT
+ */
+ "20210328015959+0100",
+ 1616893199,
+ },
+ {
+ /*
+ * first second of daylight saving time in central Europe in 2021
+ * specified in offset to GMT
+ */
+ "20210328030000+0200",
+ 1616893200,
+ },
+ {
+ /*
+ * Invalid strings should get -1 as a result
+ */
+ "INVALID",
+ -1,
+ },
+};
+
static struct testdata tbl_testdata_pos[] = {
{ "0", V_ASN1_GENERALIZEDTIME, V_ASN1_GENERALIZEDTIME, 0, 0, 0, 0, }, /* Bad time */
{ "ABCD", V_ASN1_GENERALIZEDTIME, V_ASN1_GENERALIZEDTIME, 0, 0, 0, 0, },
@@ -379,6 +427,20 @@ static int test_time_dup(void)
return ret;
}
+static int convert_asn1_to_time_t(int idx)
+{
+ time_t testdateutc;
+
+ testdateutc = asn1_string_to_time_t(asn1_to_utc[idx].input);
+
+ if (!TEST_time_t_eq(testdateutc, asn1_to_utc[idx].expected)) {
+ TEST_info("asn1_string_to_time_t (%s) failed: expected %li, got %li\n",
+ asn1_to_utc[idx].input, asn1_to_utc[idx].expected, (signed long) testdateutc);
+ return 0;
+ }
+ return 1;
+}
+
int setup_tests(void)
{
/*
@@ -414,5 +476,6 @@ int setup_tests(void)
}
ADD_ALL_TESTS(test_table_compare, OSSL_NELEM(tbl_compare_testdata));
ADD_TEST(test_time_dup);
+ ADD_ALL_TESTS(convert_asn1_to_time_t, OSSL_NELEM(asn1_to_utc));
return 1;
}