Skip to content

Commit 48d7163

Browse files
author
Mike Weeks
committed
Add Unencrypted Artifact Test
1 parent 3261114 commit 48d7163

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/unit/data_classes/_boto3/test_code_pipeline_job_event.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,51 @@ def put_object(
262262
)
263263

264264

265+
def test_code_pipeline_put_unencrypted_artifact(mocker: MockerFixture):
266+
267+
raw_content = json.dumps({"steve": "french"})
268+
artifact_content_type = "application/json"
269+
event_without_artifact_encryption = load_event("codePipelineEventData.json")
270+
event_without_artifact_encryption["CodePipeline.job"]["data"]["encryptionKey"] = None
271+
event = CodePipelineJobEvent(event_without_artifact_encryption)
272+
assert event.data.encryption_key is None
273+
artifact_name = event.data.output_artifacts[0].name
274+
275+
class MockClient:
276+
@staticmethod
277+
def put_object(
278+
Bucket: str,
279+
Key: str,
280+
ContentType: str,
281+
Body: str,
282+
BucketKeyEnabled: bool,
283+
):
284+
output_artifact = event.find_output_artifact(artifact_name)
285+
assert Bucket == output_artifact.location.s3_location.bucket_name
286+
assert Key == output_artifact.location.s3_location.key
287+
assert ContentType == artifact_content_type
288+
assert Body == raw_content
289+
assert BucketKeyEnabled is True
290+
291+
s3 = mocker.patch("boto3.client")
292+
s3.return_value = MockClient()
293+
294+
event.put_artifact(
295+
artifact_name=artifact_name,
296+
body=raw_content,
297+
content_type=artifact_content_type,
298+
)
299+
300+
s3.assert_called_once_with(
301+
"s3",
302+
**{
303+
"aws_access_key_id": event.data.artifact_credentials.access_key_id,
304+
"aws_secret_access_key": event.data.artifact_credentials.secret_access_key,
305+
"aws_session_token": event.data.artifact_credentials.session_token,
306+
},
307+
)
308+
309+
265310
def test_code_pipeline_put_output_artifact_not_found():
266311
raw_event = load_event("codePipelineEventData.json")
267312
parsed_event = CodePipelineJobEvent(raw_event)

0 commit comments

Comments
 (0)