From 1fec7bea51f6537276aef9d5d95d67b11d7be907 Mon Sep 17 00:00:00 2001
From: Theo Buehler <tb@openbsd.org>
Date: Sun, 26 May 2024 07:23:36 +0200
Subject: Make RFC 5280 test xfail on 32-bit time_t systems

---
 patches/rfc5280.c.patch      | 48 --------------------------------------------
 tests/CMakeLists.txt         |  3 +++
 tests/Makefile.am            |  6 ++++++
 tests/rfc5280time_small.test | 10 +++++++++
 4 files changed, 19 insertions(+), 48 deletions(-)
 delete mode 100644 patches/rfc5280.c.patch
 create mode 100755 tests/rfc5280time_small.test

diff --git a/patches/rfc5280.c.patch b/patches/rfc5280.c.patch
deleted file mode 100644
index 9807f00..0000000
--- a/patches/rfc5280.c.patch
+++ /dev/null
@@ -1,48 +0,0 @@
---- tests/rfc5280time.c.orig	Mon Nov  2 20:00:31 2015
-+++ tests/rfc5280time.c	Mon Nov  2 20:03:12 2015
-@@ -91,6 +91,7 @@
- 		.data = "20150923032700Z",
- 		.time = 1442978820,
- 	},
-+#if SIZEOF_TIME_T == 8
- 	{
- 		/* (times before 2050 must be UTCTIME) Per RFC 5280 4.1.2.5 */
- 		.str = "00000101000000Z",
-@@ -103,6 +104,7 @@
- 		.data = "20491231235959Z",
- 		.time = 2524607999LL,
- 	},
-+#endif
- 	{
- 		/* (times before 2050 must be UTCTIME) Per RFC 5280 4.1.2.5 */
- 		.str = "19500101000000Z",
-@@ -112,6 +114,7 @@
- };
- 
- struct rfc5280_time_test rfc5280_gentime_tests[] = {
-+#if SIZEOF_TIME_T == 8
- 	{
- 		/* Biggest RFC 5280 time */
- 		.str = "99991231235959Z",
-@@ -129,6 +132,7 @@
- 		.data = "20500101000000Z",
- 		.time =  2524608000LL,
- 	},
-+#endif
- };
- struct rfc5280_time_test rfc5280_utctime_tests[] = {
- 	{
-@@ -141,11 +145,13 @@
- 		.data = "540226230640Z",
- 		.time = -500000000,
- 	},
-+#if SIZEOF_TIME_T == 8
- 	{
- 		.str = "491231235959Z",
- 		.data = "491231235959Z",
- 		.time = 2524607999LL,
- 	},
-+#endif
- 	{
- 		.str = "700101000000Z",
- 		.data = "700101000000Z",
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 3497cb5..f39eb20 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -588,6 +588,9 @@ add_test(rfc3779 rfc3779)
 add_executable(rfc5280time rfc5280time.c)
 target_link_libraries(rfc5280time ${OPENSSL_TEST_LIBS})
 add_test(rfc5280time rfc5280time)
+if(SMALL_TIME_T)
+	set_property(TEST rfc5280time PROPERTY WILL_FAIL TRUE)
+endif()
 
 # rmd_test
 add_executable(rmd_test rmd_test.c)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0e19106..629dbcb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -624,7 +624,13 @@ rfc3779_SOURCES = rfc3779.c
 # rfc5280time
 check_PROGRAMS += rfc5280time
 rfc5280time_SOURCES = rfc5280time.c
+if SMALL_TIME_T
+TESTS += rfc5280time_small.test
+XFAIL_TESTS += rfc5280time_small.test
+else
 TESTS += rfc5280time
+endif
+EXTRA_DIST += rfc5280time_small.test
 
 # rmd_test
 TESTS += rmd_test
diff --git a/tests/rfc5280time_small.test b/tests/rfc5280time_small.test
new file mode 100755
index 0000000..61e5a05
--- /dev/null
+++ b/tests/rfc5280time_small.test
@@ -0,0 +1,10 @@
+#!/bin/sh
+echo 1..1
+TEST=./rfc5280
+if [ -e ./rfc5280.exe ]; then
+	TEST=./rfc5280.exe
+fi
+
+# map test failure to XFAIL and success to XPASS
+$TEST || echo -n "not "
+echo "ok # this system is unable to represent times past 2038"
-- 
cgit v1.2.3-55-g6feb