Skip to content

Commit b32cb8c

Browse files
author
Oliver Friesen
committed
Issue: 246 test
1 parent cc3866b commit b32cb8c

File tree

2 files changed

+363
-0
lines changed

2 files changed

+363
-0
lines changed

tests/functional/validator/conftest.py

Lines changed: 355 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,81 @@ def eventbridge_event():
244244
"detail": {"message": "hello hello", "username": "blah blah"},
245245
}
246246

247+
@pytest.fixture
248+
def eventbridge_s3_HeadObject_event():
249+
return {
250+
"account": "123456789012",
251+
"detail": {
252+
"additionalEventData": {
253+
"AuthenticationMethod": "AuthHeader",
254+
"CipherSuite": "ECDHE-RSA-AES128-GCM-SHA256",
255+
"SignatureVersion": "SigV4",
256+
"bytesTransferredIn": 0,
257+
"bytesTransferredOut": 0,
258+
"x-amz-id-2": "ejUr9Nd/4IO1juF/a6GOcu+PKrVX6dOH6jDjQOeCJvtARUqzxrhHGrhEt04cqYtAZVqcSEXYqo0="
259+
},
260+
"awsRegion": "us-west-1",
261+
"eventCategory": "Data",
262+
"eventID": "be4fdb30-9508-4984-b071-7692221899ae",
263+
"eventName": "HeadObject",
264+
"eventSource": "s3.amazonaws.com",
265+
"eventTime": "2020-12-22T10:05:29Z",
266+
"eventType": "AwsApiCall",
267+
"eventVersion": "1.07",
268+
"managementEvent": False,
269+
"readOnly": True,
270+
"recipientAccountId": "123456789012",
271+
"requestID": "A123B1C123D1E123",
272+
"requestParameters": {
273+
"Host": "lambda-artifacts-deafc19498e3f2df.s3.us-west-1.amazonaws.com",
274+
"bucketName": "lambda-artifacts-deafc19498e3f2df",
275+
"key": "path1/path2/path3/file.zip"
276+
},
277+
"resources": [
278+
{
279+
"ARN": "arn:aws:s3:::lambda-artifacts-deafc19498e3f2df/path1/path2/path3/file.zip",
280+
"type": "AWS::S3::Object"
281+
},
282+
{
283+
"ARN": "arn:aws:s3:::lambda-artifacts-deafc19498e3f2df",
284+
"accountId": "123456789012",
285+
"type": "AWS::S3::Bucket"
286+
}
287+
],
288+
"responseElements": None,
289+
"sourceIPAddress": "AWS Internal",
290+
"userAgent": "AWS Internal",
291+
"userIdentity": {
292+
"accessKeyId": "ABCDEFGHIJKLMNOPQR12",
293+
"accountId": "123456789012",
294+
"arn": "arn:aws:sts::123456789012:assumed-role/role-name1/1234567890123",
295+
"invokedBy": "AWS Internal",
296+
"principalId": "ABCDEFGHIJKLMN1OPQRST:1234567890123",
297+
"sessionContext": {
298+
"attributes": {
299+
"creationDate": "2020-12-09T09:58:24Z",
300+
"mfaAuthenticated": "false"
301+
},
302+
"sessionIssuer": {
303+
"accountId": "123456789012",
304+
"arn": "arn:aws:iam::123456789012:role/role-name1",
305+
"principalId": "ABCDEFGHIJKLMN1OPQRST",
306+
"type": "Role",
307+
"userName": "role-name1"
308+
}
309+
},
310+
"type": "AssumedRole"
311+
},
312+
"vpcEndpointId": "vpce-a123cdef"
313+
},
314+
"detail-type": "AWS API Call via CloudTrail",
315+
"id": "e0bad426-0a70-4424-b53a-eb902ebf5786",
316+
"region": "us-west-1",
317+
"resources": [],
318+
"source": "aws.s3",
319+
"time": "2020-12-22T10:05:29Z",
320+
"version": "0"
321+
}
247322

248323
@pytest.fixture
249324
def sqs_event():
@@ -356,3 +431,283 @@ def cloudwatch_logs_schema():
356431
],
357432
},
358433
}
434+
435+
@pytest.fixture
436+
def eventbridge_schema_registry_aws_s3_AWSAPICallViaCloudTrail_v2():
437+
return {
438+
"$schema": "http://json-schema.org/draft-04/schema#",
439+
"definitions": {
440+
"AWSAPICallViaCloudTrail": {
441+
"properties": {
442+
"additionalEventData": {
443+
"$ref": "#/definitions/AdditionalEventData"
444+
},
445+
"awsRegion": {
446+
"type": "string"
447+
},
448+
"errorCode": {
449+
"type": "string"
450+
},
451+
"errorMessage": {
452+
"type": "string"
453+
},
454+
"eventID": {
455+
"type": "string"
456+
},
457+
"eventName": {
458+
"type": "string"
459+
},
460+
"eventSource": {
461+
"type": "string"
462+
},
463+
"eventTime": {
464+
"format": "date-time",
465+
"type": "string"
466+
},
467+
"eventType": {
468+
"type": "string"
469+
},
470+
"eventVersion": {
471+
"type": "string"
472+
},
473+
"recipientAccountId": {
474+
"type": "string"
475+
},
476+
"requestID": {
477+
"type": "string"
478+
},
479+
"requestParameters": {
480+
"$ref": "#/definitions/RequestParameters"
481+
},
482+
"resources": {
483+
"items": {
484+
"type": "object"
485+
},
486+
"type": "array"
487+
},
488+
"responseElements": {
489+
"type": [
490+
"object",
491+
"null"
492+
]
493+
},
494+
"sourceIPAddress": {
495+
"type": "string"
496+
},
497+
"userAgent": {
498+
"type": "string"
499+
},
500+
"userIdentity": {
501+
"$ref": "#/definitions/UserIdentity"
502+
},
503+
"vpcEndpointId": {
504+
"type": "string"
505+
},
506+
"x-amazon-open-api-schema-readOnly": {
507+
"type": "boolean"
508+
}
509+
},
510+
"required": [
511+
"eventID",
512+
"awsRegion",
513+
"eventVersion",
514+
"responseElements",
515+
"sourceIPAddress",
516+
"eventSource",
517+
"requestParameters",
518+
"resources",
519+
"userAgent",
520+
"readOnly",
521+
"userIdentity",
522+
"eventType",
523+
"additionalEventData",
524+
"vpcEndpointId",
525+
"requestID",
526+
"eventTime",
527+
"eventName",
528+
"recipientAccountId"
529+
],
530+
"type": "object"
531+
},
532+
"AdditionalEventData": {
533+
"properties": {
534+
"objectRetentionInfo": {
535+
"$ref": "#/definitions/ObjectRetentionInfo"
536+
},
537+
"x-amz-id-2": {
538+
"type": "string"
539+
}
540+
},
541+
"required": [
542+
"x-amz-id-2"
543+
],
544+
"type": "object"
545+
},
546+
"Attributes": {
547+
"properties": {
548+
"creationDate": {
549+
"format": "date-time",
550+
"type": "string"
551+
},
552+
"mfaAuthenticated": {
553+
"type": "string"
554+
}
555+
},
556+
"required": [
557+
"mfaAuthenticated",
558+
"creationDate"
559+
],
560+
"type": "object"
561+
},
562+
"LegalHoldInfo": {
563+
"properties": {
564+
"isUnderLegalHold": {
565+
"type": "boolean"
566+
},
567+
"lastModifiedTime": {
568+
"format": "int64",
569+
"type": "integer"
570+
}
571+
},
572+
"type": "object"
573+
},
574+
"ObjectRetentionInfo": {
575+
"properties": {
576+
"legalHoldInfo": {
577+
"$ref": "#/definitions/LegalHoldInfo"
578+
},
579+
"retentionInfo": {
580+
"$ref": "#/definitions/RetentionInfo"
581+
}
582+
},
583+
"type": "object"
584+
},
585+
"RequestParameters": {
586+
"properties": {
587+
"bucketName": {
588+
"type": "string"
589+
},
590+
"key": {
591+
"type": "string"
592+
},
593+
"legal-hold": {
594+
"type": "string"
595+
},
596+
"retention": {
597+
"type": "string"
598+
}
599+
},
600+
"required": [
601+
"bucketName",
602+
"key"
603+
],
604+
"type": "object"
605+
},
606+
"RetentionInfo": {
607+
"properties": {
608+
"lastModifiedTime": {
609+
"format": "int64",
610+
"type": "integer"
611+
},
612+
"retainUntilMode": {
613+
"type": "string"
614+
},
615+
"retainUntilTime": {
616+
"format": "int64",
617+
"type": "integer"
618+
}
619+
},
620+
"type": "object"
621+
},
622+
"SessionContext": {
623+
"properties": {
624+
"attributes": {
625+
"$ref": "#/definitions/Attributes"
626+
}
627+
},
628+
"required": [
629+
"attributes"
630+
],
631+
"type": "object"
632+
},
633+
"UserIdentity": {
634+
"properties": {
635+
"accessKeyId": {
636+
"type": "string"
637+
},
638+
"accountId": {
639+
"type": "string"
640+
},
641+
"arn": {
642+
"type": "string"
643+
},
644+
"principalId": {
645+
"type": "string"
646+
},
647+
"sessionContext": {
648+
"$ref": "#/definitions/SessionContext"
649+
},
650+
"type": {
651+
"type": "string"
652+
}
653+
},
654+
"required": [
655+
"accessKeyId",
656+
"sessionContext",
657+
"accountId",
658+
"principalId",
659+
"type",
660+
"arn"
661+
],
662+
"type": "object"
663+
}
664+
},
665+
"properties": {
666+
"account": {
667+
"type": "string"
668+
},
669+
"detail": {
670+
"$ref": "#/definitions/AWSAPICallViaCloudTrail"
671+
},
672+
"detail-type": {
673+
"type": "string"
674+
},
675+
"id": {
676+
"type": "string"
677+
},
678+
"region": {
679+
"type": "string"
680+
},
681+
"resources": {
682+
"items": {
683+
"type": "string"
684+
},
685+
"type": "array"
686+
},
687+
"source": {
688+
"type": "string"
689+
},
690+
"time": {
691+
"format": "date-time",
692+
"type": "string"
693+
},
694+
"version": {
695+
"type": "string"
696+
}
697+
},
698+
"required": [
699+
"detail-type",
700+
"resources",
701+
"id",
702+
"source",
703+
"time",
704+
"detail",
705+
"region",
706+
"version",
707+
"account"
708+
],
709+
"title": "AWSAPICallViaCloudTrail",
710+
"type": "object",
711+
"x-amazon-events-detail-type": "AWS API Call via CloudTrail",
712+
"x-amazon-events-source": "aws.s3"
713+
}

tests/functional/validator/test_validator.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ def test_validate_invalid_schema_format(raw_event):
3737
validate(event=raw_event, schema="schema.json")
3838

3939

40+
def test_validate_accept_schema_customn_format(
41+
eventbridge_schema_registry_aws_s3_AWSAPICallViaCloudTrail_v2,
42+
eventbridge_s3_HeadObject_event):
43+
validate(event=eventbridge_s3_HeadObject_event,
44+
schema=eventbridge_schema_registry_aws_s3_AWSAPICallViaCloudTrail_v2,
45+
formats={'int64': lambda v: True})
46+
47+
4048
def test_validate_invalid_envelope_expression(schema, wrapped_event):
4149
with pytest.raises(exceptions.InvalidEnvelopeExpressionError):
4250
validate(event=wrapped_event, schema=schema, envelope=True)

0 commit comments

Comments
 (0)