Skip to content

Commit

Permalink
fix(tests): use datetime.datetime.now() in GCP `kms_key_rotation_en…
Browse files Browse the repository at this point in the history
…abled` (#6083)

Co-authored-by: Sergio Garcia <hello@mistercloudsec.com>
  • Loading branch information
prowler-bot and MrCloudSec authored Dec 9, 2024
1 parent d28462b commit b60edc1
Showing 1 changed file with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
from unittest import mock

from tests.providers.gcp.gcp_fixtures import (
Expand Down Expand Up @@ -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"],
)
]
Expand Down Expand Up @@ -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"],
)
]
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down

0 comments on commit b60edc1

Please # to comment.