-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_handler.py
28 lines (22 loc) · 2.16 KB
/
test_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import unittest
import handler
class HandlerTests(unittest.TestCase):
def test_handler(self):
with self.assertRaises(SystemExit): # Check that will exit if error code is incorrect
handler.lambda_handler({"detail": {"errorCode": "random"}}, {})
def test_form_mfa_device_arn(self):
self.assertEqual(handler.form_mfa_arn("123456789012", "testUser", "/"),
"arn:aws:iam::123456789012:mfa/testUser")
self.assertEqual(handler.form_mfa_arn("123456789012", "testUser", "/somepath/"),
"arn:aws:iam::123456789012:mfa/somepath/testUser")
self.assertNotEqual(handler.form_mfa_arn("123456789012", "testUser", "/somepath/"),
"arn:aws:iam::123456789012:mfa/testUser")
test_event = {'version': '0', 'id': '1234', 'detail-type': 'AWS API Call via CloudTrail',
'source': 'aws.iam', 'account': '123456789012', 'time': '2019-11-24T07:38:30Z', 'region': 'us-east-1', 'resources': [],
'detail': {'eventVersion': '1.05', 'userIdentity': {'type': 'IAMUser', 'principalId': 'SCRUBBED',
'arn': 'arn:aws:iam::123456789012:user/testUser',
'accountId': '123456789012', 'accessKeyId': 'SCRUBBED',
'userName': 'testUser', 'sessionContext':
{'attributes': {'mfaAuthenticated': 'true', 'creationDate': '2019-11-24T07:27:15Z'}}, 'invokedBy': 'signin.amazonaws.com'},'eventTime': '2019-11-24T07:38:30Z', 'eventSource': 'iam.amazonaws.com', 'eventName': 'CreateVirtualMFADevice', 'awsRegion': 'us-east-1', 'sourceIPAddress': '1.1.1.1', 'userAgent': 'signin.amazonaws.com', 'errorCode': 'EntityAlreadyExistsException', 'errorMessage': 'MFADevice entity at the same path and name already exists.', 'requestParameters': {'virtualMFADeviceName': 'test', 'path': '/'}, 'responseElements': None, 'requestID': 'SCRUBBED', 'eventID': 'SCRUBBED', 'eventType': 'AwsApiCall'}}
if __name__ == '__main__':
unittest.main()