From b60edc1f6b6e09f1e6dc0ac4f0a80896a323e850 Mon Sep 17 00:00:00 2001 From: Prowler Bot Date: Mon, 9 Dec 2024 16:06:37 +0100 Subject: [PATCH] fix(tests): use `datetime.datetime.now()` in GCP `kms_key_rotation_enabled` (#6083) Co-authored-by: Sergio Garcia --- .../kms_key_rotation_enabled_test.py | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/tests/providers/gcp/services/kms/kms_key_rotation_enabled/kms_key_rotation_enabled_test.py b/tests/providers/gcp/services/kms/kms_key_rotation_enabled/kms_key_rotation_enabled_test.py index 0f1311cf097..f79e7ad7251 100644 --- a/tests/providers/gcp/services/kms/kms_key_rotation_enabled/kms_key_rotation_enabled_test.py +++ b/tests/providers/gcp/services/kms/kms_key_rotation_enabled/kms_key_rotation_enabled_test.py @@ -1,3 +1,4 @@ +import datetime from unittest import mock from tests.providers.gcp.gcp_fixtures import ( @@ -239,7 +240,10 @@ def test_kms_key_no_rotation_period_and_big_next_rotation_time(self): project_id=GCP_PROJECT_ID, key_ring=keyring.name, location=keylocation.name, - next_rotation_time="2025-09-01T00:00:00Z", + # Next rotation time of now + 100 days + next_rotation_time=( + datetime.datetime.now() - datetime.timedelta(days=+100) + ).strftime("%Y-%m-%dT%H:%M:%S.%fZ"), members=["user:jane@example.com"], ) ] @@ -296,7 +300,10 @@ def test_kms_key_no_rotation_period_and_appropriate_next_rotation_time(self): project_id=GCP_PROJECT_ID, key_ring=keyring.name, location=keylocation.name, - next_rotation_time="2024-09-01T00:00:00Z", + # Next rotation time of now + 30 days + next_rotation_time=( + datetime.datetime.now() - datetime.timedelta(days=+30) + ).strftime("%Y-%m-%dT%H:%M:%S.%fZ"), members=["user:jane@example.com"], ) ] @@ -352,7 +359,10 @@ def test_kms_key_rotation_period_greater_90_days_and_big_next_rotation_time(self id="projects/123/locations/us-central1/keyRings/keyring1/cryptoKeys/key1", project_id=GCP_PROJECT_ID, rotation_period="8776000s", - next_rotation_time="2025-09-01T00:00:00Z", + # Next rotation time of now + 100 days + next_rotation_time=( + datetime.datetime.now() - datetime.timedelta(days=+100) + ).strftime("%Y-%m-%dT%H:%M:%S.%fZ"), key_ring=keyring.name, location=keylocation.name, members=["user:jane@example.com"], @@ -412,7 +422,10 @@ def test_kms_key_rotation_period_greater_90_days_and_appropriate_next_rotation_t id="projects/123/locations/us-central1/keyRings/keyring1/cryptoKeys/key1", project_id=GCP_PROJECT_ID, rotation_period="8776000s", - next_rotation_time="2024-09-01T00:00:00Z", + # Next rotation time of now + 30 days + next_rotation_time=( + datetime.datetime.now() - datetime.timedelta(days=+30) + ).strftime("%Y-%m-%dT%H:%M:%S.%fZ"), key_ring=keyring.name, location=keylocation.name, members=["user:jane@example.com"], @@ -470,7 +483,10 @@ def test_kms_key_rotation_period_less_90_days_and_big_next_rotation_time(self): id="projects/123/locations/us-central1/keyRings/keyring1/cryptoKeys/key1", project_id=GCP_PROJECT_ID, rotation_period="7776000s", - next_rotation_time="2025-09-01T00:00:00Z", + # Next rotation time of now + 100 days + next_rotation_time=( + datetime.datetime.now() - datetime.timedelta(days=+100) + ).strftime("%Y-%m-%dT%H:%M:%S.%fZ"), key_ring=keyring.name, location=keylocation.name, members=["user:jane@example.com"], @@ -530,7 +546,10 @@ def test_kms_key_rotation_period_less_90_days_and_appropriate_next_rotation_time id="projects/123/locations/us-central1/keyRings/keyring1/cryptoKeys/key1", project_id=GCP_PROJECT_ID, rotation_period="7776000s", - next_rotation_time="2024-09-01T00:00:00Z", + # Next rotation time of now + 30 days + next_rotation_time=( + datetime.datetime.now() - datetime.timedelta(days=+30) + ).strftime("%Y-%m-%dT%H:%M:%S.%fZ"), key_ring=keyring.name, location=keylocation.name, members=["user:jane@example.com"], @@ -588,7 +607,10 @@ def test_kms_key_rotation_with_fractional_seconds(self): id="projects/123/locations/us-central1/keyRings/keyring1/cryptoKeys/key1", project_id=GCP_PROJECT_ID, rotation_period="7776000s", - next_rotation_time="2025-07-06T22:00:00.561275Z", + # Next rotation time of now + 100 days + next_rotation_time=( + datetime.datetime.now() - datetime.timedelta(days=+100) + ).strftime("%Y-%m-%dT%H:%M:%S.%fZ"), key_ring=keyring.name, location=keylocation.name, members=["user:jane@example.com"],