summaryrefslogtreecommitdiff
path: root/test/util_test.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-12-01 23:13:25 +0100
committerCarl Hetherington <cth@carlh.net>2019-12-01 23:13:25 +0100
commit9a5809be580c1a12864d751a710f6783363d3de7 (patch)
tree2039fc251ed6bb5abcfe2fd6daa2fe572fac144e /test/util_test.cc
parentc78523806e89e4c43015816fcd20db2549992464 (diff)
Check that KDM validity periods are safely within the validity periods
of the signing certificate chain. This does cause problems when you try to create a KDM for a certificate you just made (due to the fact that certificates always have a start-valid time of "now") but hopefully this can be fixed up in another commit.
Diffstat (limited to 'test/util_test.cc')
-rw-r--r--test/util_test.cc209
1 files changed, 207 insertions, 2 deletions
diff --git a/test/util_test.cc b/test/util_test.cc
index 15851ecd..d85b9b56 100644
--- a/test/util_test.cc
+++ b/test/util_test.cc
@@ -31,9 +31,10 @@
files in the program, then also delete it here.
*/
-#include <fstream>
-#include <boost/test/unit_test.hpp>
#include "util.h"
+#include "local_time.h"
+#include <boost/test/unit_test.hpp>
+#include <fstream>
using std::ifstream;
using std::string;
@@ -136,3 +137,207 @@ BOOST_AUTO_TEST_CASE (private_key_fingerprint_test)
{
BOOST_CHECK_EQUAL (dcp::private_key_fingerprint (dcp::file_to_string ("test/data/private.key")), "Jdz1bFpCcKI7R16Ccx9JHYytag0=");
}
+
+BOOST_AUTO_TEST_CASE (day_less_than_or_equal_test)
+{
+ {
+ /* equal */
+ struct tm a;
+ a.tm_mday = 5;
+ a.tm_mon = 3;
+ a.tm_year = 78;
+
+ dcp::LocalTime b ("1978-04-05T00:00:00");
+ BOOST_CHECK (day_less_than_or_equal(a, b));
+ }
+
+ {
+ /* every part of a less than b */
+ struct tm a;
+ a.tm_mday = 4;
+ a.tm_mon = 2;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1985-05-23T00:00:00");
+ BOOST_CHECK (day_less_than_or_equal(a, b));
+ }
+
+ {
+ /* years equal, other parts less */
+ struct tm a;
+ a.tm_mday = 4;
+ a.tm_mon = 2;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1981-05-10T00:00:00");
+ BOOST_CHECK (day_less_than_or_equal(a, b));
+ }
+
+ {
+ /* year and month equal, day less */
+ struct tm a;
+ a.tm_mday = 4;
+ a.tm_mon = 2;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1981-03-12T00:00:00");
+ BOOST_CHECK (day_less_than_or_equal(a, b));
+ }
+
+ {
+ /* year and month equal, day less */
+ struct tm a;
+ a.tm_mday = 1;
+ a.tm_mon = 2;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1981-03-04T00:00:00");
+ BOOST_CHECK (day_less_than_or_equal(a, b));
+ }
+
+ {
+ /* a one day later than b */
+ struct tm a;
+ a.tm_mday = 5;
+ a.tm_mon = 2;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1981-03-04T00:00:00");
+ BOOST_CHECK (!day_less_than_or_equal(a, b));
+ }
+
+ {
+ /* year and month same, day much later */
+ struct tm a;
+ a.tm_mday = 22;
+ a.tm_mon = 2;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1981-03-04T00:00:00");
+ BOOST_CHECK (!day_less_than_or_equal(a, b));
+ }
+
+ {
+ /* year same, month and day later */
+ struct tm a;
+ a.tm_mday = 22;
+ a.tm_mon = 5;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1981-02-04T00:00:00");
+ BOOST_CHECK (!day_less_than_or_equal(a, b));
+ }
+
+ {
+ /* all later */
+ struct tm a;
+ a.tm_mday = 22;
+ a.tm_mon = 5;
+ a.tm_year = 99;
+
+ dcp::LocalTime b ("1981-02-04T00:00:00");
+ BOOST_CHECK (!day_less_than_or_equal(a, b));
+ }
+}
+
+BOOST_AUTO_TEST_CASE (day_greater_than_or_equal_test)
+{
+ {
+ /* equal */
+ struct tm a;
+ a.tm_mday = 5;
+ a.tm_mon = 3;
+ a.tm_year = 78;
+
+ dcp::LocalTime b ("1978-04-05T00:00:00");
+ BOOST_CHECK (day_greater_than_or_equal(a, b));
+ }
+
+ {
+ /* every part of a less than b */
+ struct tm a;
+ a.tm_mday = 4;
+ a.tm_mon = 2;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1985-05-23T00:00:00");
+ BOOST_CHECK (!day_greater_than_or_equal(a, b));
+ }
+
+ {
+ /* years equal, other parts less */
+ struct tm a;
+ a.tm_mday = 4;
+ a.tm_mon = 2;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1981-05-10T00:00:00");
+ BOOST_CHECK (!day_greater_than_or_equal(a, b));
+ }
+
+ {
+ /* year and month equal, day less */
+ struct tm a;
+ a.tm_mday = 4;
+ a.tm_mon = 2;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1981-03-12T00:00:00");
+ BOOST_CHECK (!day_greater_than_or_equal(a, b));
+ }
+
+ {
+ /* year and month equal, day less */
+ struct tm a;
+ a.tm_mday = 1;
+ a.tm_mon = 2;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1981-03-04T00:00:00");
+ BOOST_CHECK (!day_greater_than_or_equal(a, b));
+ }
+
+ {
+ /* a one day later than b */
+ struct tm a;
+ a.tm_mday = 5;
+ a.tm_mon = 2;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1981-03-04T00:00:00");
+ BOOST_CHECK (day_greater_than_or_equal(a, b));
+ }
+
+ {
+ /* year and month same, day much later */
+ struct tm a;
+ a.tm_mday = 22;
+ a.tm_mon = 2;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1981-03-04T00:00:00");
+ BOOST_CHECK (day_greater_than_or_equal(a, b));
+ }
+
+ {
+ /* year same, month and day later */
+ struct tm a;
+ a.tm_mday = 22;
+ a.tm_mon = 5;
+ a.tm_year = 81;
+
+ dcp::LocalTime b ("1981-02-04T00:00:00");
+ BOOST_CHECK (day_greater_than_or_equal(a, b));
+ }
+
+ {
+ /* all later */
+ struct tm a;
+ a.tm_mday = 22;
+ a.tm_mon = 5;
+ a.tm_year = 99;
+
+ dcp::LocalTime b ("1981-02-04T00:00:00");
+ BOOST_CHECK (day_greater_than_or_equal(a, b));
+ }
+}