Skip to content

Commit e0210e8

Browse files
skip: Merge pull request #186 from epam/add_unit_tests
upd: add unit-test for policies 134, 135
2 parents 6e69030 + 6fd897a commit e0210e8

14 files changed

+756
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"SecurityGroups": [
5+
{
6+
"Description": "Managed by Terraform",
7+
"GroupName": "134_c7n_security_group1_green",
8+
"IpPermissions": [
9+
{
10+
"FromPort": 23,
11+
"IpProtocol": "tcp",
12+
"IpRanges": [
13+
{
14+
"CidrIp": "10.0.0.0/16"
15+
}
16+
],
17+
"Ipv6Ranges": [],
18+
"PrefixListIds": [],
19+
"ToPort": 23,
20+
"UserIdGroupPairs": []
21+
}
22+
],
23+
"OwnerId": "this",
24+
"GroupId": "sg-01f8c94ee4b4f7b7a",
25+
"IpPermissionsEgress": [],
26+
"Tags": [
27+
{
28+
"Key": "Name",
29+
"Value": "134_c7n_security_group1_green"
30+
}
31+
],
32+
"VpcId": "vpc-09fc631a5851c5c87"
33+
},
34+
{
35+
"Description": "Managed by Terraform",
36+
"GroupName": "134_c7n_security_group2_green",
37+
"IpPermissions": [
38+
{
39+
"FromPort": 80,
40+
"IpProtocol": "tcp",
41+
"IpRanges": [
42+
{
43+
"CidrIp": "0.0.0.0/0"
44+
}
45+
],
46+
"Ipv6Ranges": [],
47+
"PrefixListIds": [],
48+
"ToPort": 80,
49+
"UserIdGroupPairs": []
50+
},
51+
{
52+
"FromPort": 110,
53+
"IpProtocol": "tcp",
54+
"IpRanges": [
55+
{
56+
"CidrIp": "10.0.0.0/16"
57+
}
58+
],
59+
"Ipv6Ranges": [],
60+
"PrefixListIds": [],
61+
"ToPort": 110,
62+
"UserIdGroupPairs": []
63+
},
64+
{
65+
"FromPort": 25,
66+
"IpProtocol": "tcp",
67+
"IpRanges": [
68+
{
69+
"CidrIp": "10.0.0.0/16"
70+
}
71+
],
72+
"Ipv6Ranges": [],
73+
"PrefixListIds": [],
74+
"ToPort": 25,
75+
"UserIdGroupPairs": []
76+
}
77+
],
78+
"OwnerId": "this",
79+
"GroupId": "sg-0f4527d318bc483f7",
80+
"IpPermissionsEgress": [
81+
{
82+
"IpProtocol": "-1",
83+
"IpRanges": [
84+
{
85+
"CidrIp": "0.0.0.0/0"
86+
}
87+
],
88+
"Ipv6Ranges": [],
89+
"PrefixListIds": [],
90+
"UserIdGroupPairs": []
91+
}
92+
],
93+
"Tags": [
94+
{
95+
"Key": "Name",
96+
"Value": "134_c7n_security_group2_green"
97+
}
98+
],
99+
"VpcId": "vpc-09fc631a5851c5c87"
100+
}
101+
],
102+
"ResponseMetadata": {}
103+
}
104+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"LoadBalancerDescriptions": [
5+
{
6+
"LoadBalancerName": "c7n-134-elb-green",
7+
"DNSName": "c7n-134-elb-green-474763723.us-east-1.elb.amazonaws.com",
8+
"CanonicalHostedZoneName": "c7n-134-elb-green-474763723.us-east-1.elb.amazonaws.com",
9+
"CanonicalHostedZoneNameID": "Z35SXDOTRQ7X7K",
10+
"ListenerDescriptions": [
11+
{
12+
"Listener": {
13+
"Protocol": "HTTP",
14+
"LoadBalancerPort": 80,
15+
"InstanceProtocol": "HTTP",
16+
"InstancePort": 8000
17+
},
18+
"PolicyNames": []
19+
}
20+
],
21+
"Policies": {
22+
"AppCookieStickinessPolicies": [],
23+
"LBCookieStickinessPolicies": [],
24+
"OtherPolicies": []
25+
},
26+
"BackendServerDescriptions": [],
27+
"AvailabilityZones": [
28+
"us-east-1b",
29+
"us-east-1a"
30+
],
31+
"Subnets": [
32+
"subnet-06677597d7a9876e1",
33+
"subnet-0f6e7c3c32d2293d7"
34+
],
35+
"VPCId": "vpc-09fc631a5851c5c87",
36+
"Instances": [],
37+
"HealthCheck": {
38+
"Target": "TCP:8000",
39+
"Interval": 30,
40+
"Timeout": 5,
41+
"UnhealthyThreshold": 2,
42+
"HealthyThreshold": 10
43+
},
44+
"SourceSecurityGroup": {
45+
"OwnerAlias": "this",
46+
"GroupName": "134_c7n_security_group2_green"
47+
},
48+
"SecurityGroups": [
49+
"sg-0f4527d318bc483f7",
50+
"sg-01f8c94ee4b4f7b7a"
51+
],
52+
"CreatedTime": {
53+
"__class__": "datetime",
54+
"year": 2021,
55+
"month": 8,
56+
"day": 18,
57+
"hour": 6,
58+
"minute": 46,
59+
"second": 26,
60+
"microsecond": 280000
61+
},
62+
"Scheme": "internet-facing"
63+
}
64+
],
65+
"ResponseMetadata": {}
66+
}
67+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"PaginationToken": "",
5+
"ResourceTagMappingList": [
6+
{
7+
"ResourceARN": "arn:aws:elasticloadbalancing:us-east-1:this:loadbalancer/c7n-134-elb-green",
8+
"Tags": [
9+
{
10+
"Key": "Name",
11+
"Value": "134_c7n_elb_green"
12+
}
13+
]
14+
}
15+
],
16+
"ResponseMetadata": {}
17+
}
18+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"SecurityGroups": [
5+
{
6+
"Description": "Managed by Terraform",
7+
"GroupName": "134_c7n_security_group2_red",
8+
"IpPermissions": [
9+
{
10+
"FromPort": 110,
11+
"IpProtocol": "tcp",
12+
"IpRanges": [
13+
{
14+
"CidrIp": "0.0.0.0/0"
15+
}
16+
],
17+
"Ipv6Ranges": [],
18+
"PrefixListIds": [],
19+
"ToPort": 110,
20+
"UserIdGroupPairs": []
21+
},
22+
{
23+
"FromPort": 25,
24+
"IpProtocol": "tcp",
25+
"IpRanges": [
26+
{
27+
"CidrIp": "0.0.0.0/0"
28+
}
29+
],
30+
"Ipv6Ranges": [],
31+
"PrefixListIds": [],
32+
"ToPort": 25,
33+
"UserIdGroupPairs": []
34+
}
35+
],
36+
"OwnerId": "this",
37+
"GroupId": "sg-02200272b553b73a8",
38+
"IpPermissionsEgress": [
39+
{
40+
"IpProtocol": "-1",
41+
"IpRanges": [
42+
{
43+
"CidrIp": "0.0.0.0/0"
44+
}
45+
],
46+
"Ipv6Ranges": [],
47+
"PrefixListIds": [],
48+
"UserIdGroupPairs": []
49+
}
50+
],
51+
"Tags": [
52+
{
53+
"Key": "Name",
54+
"Value": "134_c7n_security_group2_red"
55+
}
56+
],
57+
"VpcId": "vpc-017771bb1580daa30"
58+
},
59+
{
60+
"Description": "Managed by Terraform",
61+
"GroupName": "134_c7n_security_group1_red",
62+
"IpPermissions": [
63+
{
64+
"FromPort": 23,
65+
"IpProtocol": "tcp",
66+
"IpRanges": [
67+
{
68+
"CidrIp": "0.0.0.0/0"
69+
}
70+
],
71+
"Ipv6Ranges": [],
72+
"PrefixListIds": [],
73+
"ToPort": 23,
74+
"UserIdGroupPairs": []
75+
}
76+
],
77+
"OwnerId": "this",
78+
"GroupId": "sg-0e21f260ce2257500",
79+
"IpPermissionsEgress": [],
80+
"Tags": [
81+
{
82+
"Key": "Name",
83+
"Value": "134_c7n_security_group1_red"
84+
}
85+
],
86+
"VpcId": "vpc-017771bb1580daa30"
87+
}
88+
],
89+
"ResponseMetadata": {}
90+
}
91+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"LoadBalancerDescriptions": [
5+
{
6+
"LoadBalancerName": "c7n-134-elb-red",
7+
"DNSName": "c7n-134-elb-red-385543091.us-east-1.elb.amazonaws.com",
8+
"CanonicalHostedZoneName": "c7n-134-elb-red-385543091.us-east-1.elb.amazonaws.com",
9+
"CanonicalHostedZoneNameID": "Z35SXDOTRQ7X7K",
10+
"ListenerDescriptions": [
11+
{
12+
"Listener": {
13+
"Protocol": "HTTP",
14+
"LoadBalancerPort": 80,
15+
"InstanceProtocol": "HTTP",
16+
"InstancePort": 8000
17+
},
18+
"PolicyNames": []
19+
}
20+
],
21+
"Policies": {
22+
"AppCookieStickinessPolicies": [],
23+
"LBCookieStickinessPolicies": [],
24+
"OtherPolicies": []
25+
},
26+
"BackendServerDescriptions": [],
27+
"AvailabilityZones": [
28+
"us-east-1b",
29+
"us-east-1a"
30+
],
31+
"Subnets": [
32+
"subnet-00378d962f7230bf0",
33+
"subnet-015bff185def78c75"
34+
],
35+
"VPCId": "vpc-017771bb1580daa30",
36+
"Instances": [],
37+
"HealthCheck": {
38+
"Target": "TCP:8000",
39+
"Interval": 30,
40+
"Timeout": 5,
41+
"UnhealthyThreshold": 2,
42+
"HealthyThreshold": 10
43+
},
44+
"SourceSecurityGroup": {
45+
"OwnerAlias": "this",
46+
"GroupName": "134_c7n_security_group1_red"
47+
},
48+
"SecurityGroups": [
49+
"sg-0e21f260ce2257500",
50+
"sg-02200272b553b73a8"
51+
],
52+
"CreatedTime": {
53+
"__class__": "datetime",
54+
"year": 2021,
55+
"month": 8,
56+
"day": 17,
57+
"hour": 10,
58+
"minute": 47,
59+
"second": 6,
60+
"microsecond": 460000
61+
},
62+
"Scheme": "internet-facing"
63+
}
64+
],
65+
"ResponseMetadata": {}
66+
}
67+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"status_code": 200,
3+
"data": {
4+
"PaginationToken": "",
5+
"ResourceTagMappingList": [
6+
{
7+
"ResourceARN": "arn:aws:elasticloadbalancing:us-east-1:this:loadbalancer/c7n-134-elb-red",
8+
"Tags": [
9+
{
10+
"Key": "Name",
11+
"Value": "134_c7n_elb_red"
12+
}
13+
]
14+
}
15+
],
16+
"ResponseMetadata": {}
17+
}
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class PolicyTest(object):
2+
3+
def test_resources_with_client(self, base_test, resources, local_session):
4+
base_test.assertEqual(len(resources), 1)
5+
security_group_1 = local_session.client("ec2").describe_security_groups()["SecurityGroups"][0]
6+
security_group_2 = local_session.client("ec2").describe_security_groups()["SecurityGroups"][1]
7+
elb_group = resources[0]['SecurityGroups']
8+
base_test.assertIn(security_group_1['GroupId'], elb_group)
9+
base_test.assertIn(security_group_2['GroupId'], elb_group)
10+
base_test.assertEqual(security_group_1['IpPermissions'][0]['FromPort'], 110)
11+
base_test.assertEqual(security_group_1['IpPermissions'][0]['IpRanges'][0]['CidrIp'], "0.0.0.0/0")
12+
base_test.assertEqual(security_group_1['IpPermissions'][1]['FromPort'], 25)
13+
base_test.assertEqual(security_group_1['IpPermissions'][1]['IpRanges'][0]['CidrIp'], "0.0.0.0/0")
14+
base_test.assertEqual(security_group_2['IpPermissions'][0]['FromPort'], 23)
15+
base_test.assertEqual(security_group_2['IpPermissions'][0]['IpRanges'][0]['CidrIp'], "0.0.0.0/0")

0 commit comments

Comments
 (0)