test(win_client): add test_client_certificate_validity_and_proactive_check in test_win_client.py
This commit is contained in:
@@ -209,6 +209,27 @@ class TestWinClientComponent(unittest.TestCase):
|
|||||||
finally:
|
finally:
|
||||||
shutil.rmtree(test_dir, ignore_errors=True)
|
shutil.rmtree(test_dir, ignore_errors=True)
|
||||||
|
|
||||||
|
def test_client_certificate_validity_and_proactive_check(self):
|
||||||
|
import shutil
|
||||||
|
test_dir = "test_win_client_validity"
|
||||||
|
os.makedirs(test_dir, exist_ok=True)
|
||||||
|
try:
|
||||||
|
from src import server_enrollment as se
|
||||||
|
ca_cert, ca_key, _, _ = se.generate_ca_if_needed(test_dir)
|
||||||
|
client_cert_pem, client_key_pem = se.issue_client_cert("win-validity-test", ca_cert, ca_key, days_valid=365)
|
||||||
|
cert_path = os.path.join(test_dir, "client.crt")
|
||||||
|
with open(cert_path, "w", encoding="utf-8") as f:
|
||||||
|
f.write(client_cert_pem)
|
||||||
|
|
||||||
|
# Newly issued cert (365 days) is not expiring soon at 30 days
|
||||||
|
self.assertFalse(Win_Client.is_cert_expiring_soon(cert_path, threshold_days=30))
|
||||||
|
# Large threshold (500 days) reports expiring soon
|
||||||
|
self.assertTrue(Win_Client.is_cert_expiring_soon(cert_path, threshold_days=500))
|
||||||
|
# Non-existent file reports expiring / missing
|
||||||
|
self.assertTrue(Win_Client.is_cert_expiring_soon(os.path.join(test_dir, "missing.crt")))
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(test_dir, ignore_errors=True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user