Blame SOURCES/0016-tests-Generate-a-proper-not-valid-after-field.patch

235f5a
From 90f0b7c16c68d1dd876fc88b56b58c04bc565230 Mon Sep 17 00:00:00 2001
235f5a
From: Stanislav Levin <slev@altlinux.org>
235f5a
Date: Fri, 6 Nov 2020 15:18:33 +0300
235f5a
Subject: [PATCH] tests: Generate a proper `not-valid-after` field
235f5a
235f5a
Some tests assume that the mocked certificate will be valid in N
235f5a
days from now(). There was a hardcoded `not-valid-after` value
235f5a
which pointed to 20201205214850Z. So, from Nov 06 2020 the assertion
235f5a
20201205214850Z - now() < cert_expiration_days(30days) fails.
235f5a
235f5a
Fixes: https://github.com/freeipa/freeipa-healthcheck/issues/159
235f5a
Signed-off-by: Stanislav Levin <slev@altlinux.org>
235f5a
---
235f5a
 tests/mock_certmonger.py              | 18 ++++++++++++++++--
235f5a
 tests/test_ipa_expiration.py          |  8 ++++++--
235f5a
 3 files changed, 30 insertions(+), 8 deletions(-)
235f5a
235f5a
diff --git a/tests/mock_certmonger.py b/tests/mock_certmonger.py
235f5a
index ab53620..8fa4d36 100644
235f5a
--- a/tests/mock_certmonger.py
235f5a
+++ b/tests/mock_certmonger.py
235f5a
@@ -3,6 +3,7 @@
235f5a
 #
235f5a
 
235f5a
 import copy
235f5a
+from datetime import datetime, timedelta, timezone
235f5a
 
235f5a
 from ipaplatform.paths import paths
235f5a
 
235f5a
@@ -10,6 +11,8 @@ from ipaplatform.paths import paths
235f5a
 # distinct from the value from the overrident get_defaults() method.
235f5a
 template = paths.CERTMONGER_COMMAND_TEMPLATE
235f5a
 
235f5a
+CERT_EXPIRATION_DAYS = 30
235f5a
+
235f5a
 pristine_cm_requests = [
235f5a
     {
235f5a
         'nickname': '1234',
235f5a
@@ -20,7 +23,11 @@ pristine_cm_requests = [
235f5a
         'cert-storage': 'FILE',
235f5a
         'cert-presave-command': template % 'renew_ra_cert_pre',
235f5a
         'cert-postsave-command': template % 'renew_ra_cert',
235f5a
-        'not-valid-after': 1024,
235f5a
+        'not-valid-after': (
235f5a
+            int(
235f5a
+                datetime(1970, 1, 1, 0, 17, 4, tzinfo=timezone.utc).timestamp()
235f5a
+            )
235f5a
+        ),
235f5a
     },
235f5a
     {
235f5a
         'nickname': '5678',
235f5a
@@ -30,7 +37,14 @@ pristine_cm_requests = [
235f5a
         'template_profile': 'caIPAserviceCert',
235f5a
         'cert-storage': 'FILE',
235f5a
         'cert-postsave-command': template % 'restart_httpd',
235f5a
-        'not-valid-after': 1607204930,
235f5a
+        'not-valid-after': (
235f5a
+            int(
235f5a
+                (
235f5a
+                    datetime.now(timezone.utc) +
235f5a
+                    timedelta(days=CERT_EXPIRATION_DAYS + 1)
235f5a
+                ).timestamp()
235f5a
+            )
235f5a
+        ),
235f5a
     },
235f5a
 ]
235f5a
 
235f5a
diff --git a/tests/test_ipa_expiration.py b/tests/test_ipa_expiration.py
235f5a
index ff3564b..fb7105b 100644
235f5a
--- a/tests/test_ipa_expiration.py
235f5a
+++ b/tests/test_ipa_expiration.py
235f5a
@@ -11,7 +11,11 @@ from ipahealthcheck.ipa.certs import IPACertmongerExpirationCheck
235f5a
 from ipahealthcheck.ipa.certs import IPACAChainExpirationCheck
235f5a
 from unittest.mock import Mock, patch
235f5a
 from mock_certmonger import create_mock_dbus, _certmonger
235f5a
-from mock_certmonger import get_expected_requests, set_requests
235f5a
+from mock_certmonger import (
235f5a
+    get_expected_requests,
235f5a
+    set_requests,
235f5a
+    CERT_EXPIRATION_DAYS,
235f5a
+)
235f5a
 
235f5a
 from datetime import datetime, timedelta, timezone
235f5a
 
235f5a
@@ -67,7 +71,7 @@ class TestExpiration(BaseTest):
235f5a
         registry.initialize(framework, config.Config)
235f5a
         f = IPACertmongerExpirationCheck(registry)
235f5a
 
235f5a
-        f.config.cert_expiration_days = '30'
235f5a
+        f.config.cert_expiration_days = str(CERT_EXPIRATION_DAYS)
235f5a
         self.results = capture_results(f)
235f5a
 
235f5a
         assert len(self.results) == 2
235f5a
-- 
235f5a
2.31.1
235f5a