-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_out_variables.py
165 lines (136 loc) · 4.22 KB
/
test_out_variables.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import awsenum
import json
import os
dir_path = os.path.dirname(__file__)
api = awsenum.apidef.load_api()
"""
def test_ec2_describe_client_vpn_endpoints_out_variable():
value = extract_variable(
"ec2",
"describe_client_vpn_endpoints",
"ec2_describe_client_vpn_endpoints"
)
assert value == ["cvpn-endpoint-123456789123abcde"]
def test_ec2_describe_vpcs_out_variable():
value = extract_variable(
"ec2",
"describe_vpcs",
"ec2_describe_vpcs",
)
assert value == ["vpc-0e9801d129EXAMPLE", "vpc-06e4ab6c6cEXAMPLE"]
"""
def test_amplifybackend_list_s3_buckets():
_test_out_variable_value(
"amplifybackend",
"list-s3-buckets",
"s3-buckets-names",
)
def test_ec2_describe_instances_out_variable():
_test_out_variable_value(
"ec2",
"describe-instances",
"ec2-instances-ids",
)
def test_ecs_list_clusters_out_variable():
_test_out_variable_value("ecs", "list-clusters", "ecs-clusters-arns")
def test_ecs_list_tasks_out_variable():
_test_out_variable_value(
"ecs",
"list-tasks",
"ecs-cluster-tasks",
version=0
)
def test_ecs_list_services_out_variable():
_test_out_variable_value("ecs", "list-services", "ecs-cluster-services")
def test_iam_get_policy_out_variable():
_test_out_variable_value(
"iam",
"get-policy",
"iam-policy-versions",
variable_file="iam-policy-versions_get-policy"
)
def test_iam_list_attached_role_policies_out_variable():
_test_out_variable_value(
"iam",
"list-attached-role-policies",
"iam-policies-arns",
variable_file="iam-policies-arns_list-attached-role-policies"
)
def test_iam_list_policies_policies_arns_out_variable():
_test_out_variable_value("iam", "list-policies", "iam-policies-arns")
def test_iam_list_policies_policies_versions_out_variable():
_test_out_variable_value(
"iam",
"list-policies",
"iam-policies-versions",
variable_file="iam-policies-versions_list-policies",
)
def test_iam_list_policy_versions_out_variable():
_test_out_variable_value(
"iam",
"list-policy-versions",
"iam-policy-versions"
)
def test_iam_list_role_policies_out_variable():
_test_out_variable_value("iam", "list-role-policies", "iam-role-policies")
def test_iam_list_roles_out_variable():
_test_out_variable_value("iam", "list-roles", "iam-rolenames")
def test_iam_list_users():
_test_out_variable_value("iam", "list-users", "iam-usernames")
def test_lambda_list_functions_out_variable():
_test_out_variable_value(
"lambda",
"list-functions",
"lambda-functions-names"
)
def test_s3_list_buckets():
_test_out_variable_value("s3", "list-buckets", "s3-buckets-names")
def test_secretsmanager_list_secrets_out_variable():
_test_out_variable_value(
"secretsmanager",
"list-secrets",
"secretsmanager-secrets-arns",
)
def _test_out_variable_value(
service,
operation,
varname,
version=0,
response_file=None,
variable_file=None
):
value = extract_variable(
service,
operation,
varname,
version=version,
response_file=response_file
)
assert value == load_variable(varname, variable_file)
def extract_variable(
service,
operation,
varname,
version=0,
response_file=None
):
response_file = response_file or "{}-{}".format(service, operation)
operation_obj = api[service][operation]
varpath = operation_obj["versions"][version]["outvars"][varname]
response = load_response_sample(response_file)
return awsenum.brute.extract_variable_value(
varpath,
response
)
def load_response_sample(name):
filepath = os.path.join(dir_path, "samples/responses/{}.json".format(name))
return load_json(filepath)
def load_variable(varname, filename=None):
filename = filename or varname
filepath = os.path.join(
dir_path, "samples/variables/{}.json".format(filename)
)
return load_json(filepath)[varname]
def load_json(filepath):
with open(filepath) as fi:
return json.load(fi)