Skip to content

Commit

Permalink
Test event payload executes corrcet rotation step
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-griffin committed Dec 13, 2024
1 parent d294158 commit 23ed827
Showing 1 changed file with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ def test_handles_malformed_secret_data(self, rotator):
)

class TestLambdaHandler:

def test_executes_correct_rotation_step(self):
"""
Lambda must execute the correct rotation step based on the event.
Expand All @@ -1042,27 +1042,19 @@ def test_executes_correct_rotation_step(self):
"ClientRequestToken": "test-token",
"Step": "createSecret"
}

with patch('boto3.client') as mock_boto3_client, \
patch('rotate_secret_lambda.SecretRotator') as MockRotator:

mock_service_client = mock_boto3_client.return_value
mock_service_client.describe_secret.return_value = {
"RotationEnabled": True,
"VersionIdsToStages": {
"test-token": "AWSPENDING"
}
}

mock_rotator = MockRotator.return_value

from rotate_secret_lambda import lambda_handler
lambda_handler(event, None)
mock_rotator = MagicMock()
mock_boto_client = MagicMock()

# Verify correct step was called
mock_rotator.create_secret.assert_called_once_with(
mock_service_client, "test-arn", "test-token"
)
with patch("boto3.client", return_value=mock_boto_client):
with patch("rotate_secret_lambda.SecretRotator", return_value=mock_rotator):

from rotate_secret_lambda import lambda_handler
lambda_handler(event, None)

mock_rotator.create_secret.assert_called_once_with(
mock_boto_client, "test-arn", "test-token"
)


def test_run_test_secret_with_test_domains(self, rotator):
Expand Down

0 comments on commit 23ed827

Please sign in to comment.