|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
import unittest |
|
3
|
|
|
|
|
4
|
|
|
from awslambdahelper import AWSConfigEvaluation, InsufficientDataEvaluation, NonCompliantEvaluation |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class TestEvaluations(unittest.TestCase): |
|
8
|
|
|
def test_missingtimestamp(self): |
|
9
|
|
|
evaluation = AWSConfigEvaluation( |
|
10
|
|
|
AWSConfigEvaluation.TYPE_NON_COMPLIANT, |
|
11
|
|
|
'debug' |
|
12
|
|
|
).set( |
|
13
|
|
|
OrderingTimestamp=None |
|
14
|
|
|
) |
|
15
|
|
|
payload = evaluation.to_dict() |
|
16
|
|
|
self.assertRegexpMatches(payload['OrderingTimestamp'], r"\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d+Z") |
|
17
|
|
|
|
|
18
|
|
|
def test_existingtimestamp(self): |
|
19
|
|
|
evaluation = AWSConfigEvaluation( |
|
20
|
|
|
AWSConfigEvaluation.TYPE_NON_COMPLIANT, |
|
21
|
|
|
Annotation='debug', |
|
22
|
|
|
OrderingTimestamp='timestamp' |
|
23
|
|
|
) |
|
24
|
|
|
payload = evaluation.to_dict() |
|
25
|
|
|
self.assertEqual(payload['OrderingTimestamp'], 'timestamp') |
|
26
|
|
|
|
|
27
|
|
|
def test_insufficientdataevaluation(self): |
|
28
|
|
|
evaluation = InsufficientDataEvaluation( |
|
29
|
|
|
Annotation='testing-annotation', |
|
30
|
|
|
ResourceId='resource-id', |
|
31
|
|
|
ResourceType='resource-type', |
|
32
|
|
|
OrderingTimestamp='ordering-timestamp' |
|
33
|
|
|
) |
|
34
|
|
|
|
|
35
|
|
|
self.assertDictEqual(evaluation.to_dict(), { |
|
36
|
|
|
'Annotation': 'testing-annotation', |
|
37
|
|
|
'ComplianceResourceId': 'resource-id', |
|
38
|
|
|
'ComplianceResourceType': 'resource-type', |
|
39
|
|
|
'ComplianceType': 'INSUFFICIENT_DATA', |
|
40
|
|
|
'OrderingTimestamp': 'ordering-timestamp' |
|
41
|
|
|
|
|
42
|
|
|
}) |
|
43
|
|
|
|
|
44
|
|
|
def test_non_compliant_evaluation(self): |
|
45
|
|
|
evaluation = NonCompliantEvaluation( |
|
46
|
|
|
Annotation='non-compliantevaluation', |
|
47
|
|
|
).set( |
|
48
|
|
|
OrderingTimestamp='my-timestamp' |
|
49
|
|
|
) |
|
50
|
|
|
|
|
51
|
|
|
self.assertDictEqual(evaluation.to_dict(), { |
|
52
|
|
|
'Annotation': 'non-compliantevaluation', |
|
53
|
|
|
'ComplianceResourceId': None, |
|
54
|
|
|
'ComplianceResourceType': None, |
|
55
|
|
|
'ComplianceType': 'NON_COMPLIANT', |
|
56
|
|
|
'OrderingTimestamp': 'my-timestamp' |
|
57
|
|
|
}) |
|
58
|
|
|
|