Skip to content

Commit 07e4dd3

Browse files
committed
fix(ITs): config-gov ITs fixed
1 parent d2795b4 commit 07e4dd3

File tree

2 files changed

+62
-53
lines changed

2 files changed

+62
-53
lines changed

build/testScript.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ if [[ $TRAVIS_BRANCH == "main" && $TRAVIS_PULL_REQUEST == "false" ]]; then
66
curl https://us-south.functions.appdomain.cloud/api/v1/web/e6b54af6-ab44-4149-a8e4-e906dcc58136/default/secadvstg-location-shift.json
77
echo "${FINDINGS_ENV}" | base64 -d >> findings_v1.env
88
echo "${NOTIFICATIONS_ENV}" | base64 -d >> notifications_v1.env
9-
# echo "${CONFIGURATION_GOVERNANCE_ENV}" | base64 -d >> configuration_governance_v1.env
9+
echo "${CONFIGURATION_GOVERNANCE_ENV}" | base64 -d >> configuration_governance_v1.env
1010
pytest test/integration
1111
fi

test/integration/test_configuration_governance_v1.py

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@
2626
config_file = 'configuration_governance_v1.env'
2727

2828
# Variables to hold link values
29+
account_id = os.getenv("ACCOUNT_ID")
30+
rule_label = os.getenv("RULE_LABEL") or "sdk-it"
31+
resource_group_id = os.getenv("RESOURCE_GROUP_ID")
32+
2933
rule_attachment_id_link = None
3034
rule_id_link = None
3135

36+
rule_etag = None
37+
rule_attachment_etag = None
38+
3239
class TestConfigurationGovernanceV1():
3340
"""
3441
Integration Test Class for ConfigurationGovernanceV1
@@ -56,26 +63,18 @@ def setup_class(cls):
5663
@needscredentials
5764
def test_create_rules(self):
5865

59-
# Construct a dict representation of a TargetResourceAdditionalTargetAttributesItem model
60-
target_resource_additional_target_attributes_item_model = {
61-
'name': 'resource_id',
62-
'value': '81f3db5e-f9db-4c46-9de3-a4a76e66adbf',
63-
'operator': 'string_equals',
64-
}
65-
6666
# Construct a dict representation of a TargetResource model
6767
target_resource_model = {
68-
'service_name': 'iam-groups',
69-
'resource_kind': 'service',
70-
'additional_target_attributes': [target_resource_additional_target_attributes_item_model],
68+
'service_name': 'cloud-object-storage',
69+
'resource_kind': 'bucket',
7170
}
7271

7372
# Construct a dict representation of a RuleRequiredConfigSingleProperty model
7473
rule_required_config_model = {
7574
'description': 'Public access check',
76-
'property': 'public_access_enabled',
77-
'operator': 'is_true',
78-
'value': 'testString',
75+
'property': 'location',
76+
'operator': 'string_equals',
77+
'value': 'us-south',
7978
}
8079

8180
# Construct a dict representation of a EnforcementAction model
@@ -85,20 +84,20 @@ def test_create_rules(self):
8584

8685
# Construct a dict representation of a RuleRequest model
8786
rule_request_model = {
88-
'account_id': '531fc3e28bfc43c5a2cea07786d93f5c',
87+
'account_id': account_id,
8988
'name': 'Disable public access',
9089
'description': 'Ensure that public access to account resources is disabled.',
9190
'rule_type': 'user_defined',
92-
'target': {'service_name':'iam-groups','resource_kind':'service'},
93-
'required_config': {'description':'Public access check','and':[{'property':'public_access_enabled','operator':'is_false'}]},
91+
'target': target_resource_model,
92+
'required_config': rule_required_config_model,
9493
'enforcement_actions': [enforcement_action_model],
95-
'labels': ['Access', 'IAM'],
94+
'labels': [rule_label],
9695
}
9796

9897
# Construct a dict representation of a CreateRuleRequest model
9998
create_rule_request_model = {
10099
'request_id': '3cebc877-58e7-44a5-a292-32114fa73558',
101-
'rule': {'account_id':'531fc3e28bfc43c5a2cea07786d93f5c','name':'Disable public access','description':'Ensure that public access to account resources is disabled.','labels':['Access','IAM'],'target':{'service_name':'iam-groups','resource_kind':'service'},'required_config':{'description':'Public access check','and':[{'property':'public_access_enabled','operator':'is_false'}]},'enforcement_actions':[{'action':'disallow'},{'action':'audit_log'}]},
100+
'rule': rule_request_model,
102101
}
103102

104103
create_rules_response = self.configuration_governance_service.create_rules(
@@ -119,16 +118,22 @@ def test_create_rule_attachments(self):
119118

120119
# Construct a dict representation of a RuleScope model
121120
rule_scope_model = {
122-
'note': 'My enterprise',
123-
'scope_id': '282cf433ac91493ba860480d92519990',
124-
'scope_type': 'enterprise',
121+
'note': 'My account',
122+
'scope_id': account_id,
123+
'scope_type': 'account',
124+
}
125+
126+
rule_excluded_scope_model = {
127+
'note': 'My account resource group',
128+
'scope_id': resource_group_id,
129+
'scope_type': 'account.resource_group',
125130
}
126131

127132
# Construct a dict representation of a RuleAttachmentRequest model
128133
rule_attachment_request_model = {
129-
'account_id': '531fc3e28bfc43c5a2cea07786d93f5c',
130-
'included_scope': {'note':'My enterprise','scope_id':'282cf433ac91493ba860480d92519990','scope_type':'enterprise'},
131-
'excluded_scopes': [rule_scope_model],
134+
'account_id': account_id,
135+
'included_scope': rule_scope_model,
136+
'excluded_scopes': [rule_excluded_scope_model],
132137
}
133138

134139
create_rule_attachments_response = self.configuration_governance_service.create_rule_attachments(
@@ -149,10 +154,10 @@ def test_create_rule_attachments(self):
149154
def test_list_rules(self):
150155

151156
list_rules_response = self.configuration_governance_service.list_rules(
152-
account_id='531fc3e28bfc43c5a2cea07786d93f5c',
157+
account_id=account_id,
153158
transaction_id='testString',
154159
attached=True,
155-
labels='SOC2,ITCS300',
160+
labels=[rule_label],
156161
scopes='scope_id',
157162
limit=1000,
158163
offset=38
@@ -174,47 +179,42 @@ def test_get_rule(self):
174179
rule = get_rule_response.get_result()
175180
assert rule is not None
176181

182+
global rule_etag
183+
rule_etag = get_rule_response.headers['etag']
184+
177185
@needscredentials
178186
def test_update_rule(self):
179187

180-
# Construct a dict representation of a TargetResourceAdditionalTargetAttributesItem model
181-
target_resource_additional_target_attributes_item_model = {
182-
'name': 'testString',
183-
'value': 'testString',
184-
'operator': 'string_equals',
185-
}
186-
187188
# Construct a dict representation of a TargetResource model
188189
target_resource_model = {
189-
'service_name': 'iam-groups',
190-
'resource_kind': 'service',
191-
'additional_target_attributes': [target_resource_additional_target_attributes_item_model],
190+
'service_name': 'cloud-object-storage',
191+
'resource_kind': 'bucket',
192192
}
193193

194194
# Construct a dict representation of a RuleRequiredConfigSingleProperty model
195195
rule_required_config_model = {
196196
'description': 'testString',
197-
'property': 'public_access_enabled',
198-
'operator': 'is_false',
199-
'value': 'testString',
197+
'property': 'location',
198+
'operator': 'string_equals',
199+
'value': 'us-south',
200200
}
201201

202202
# Construct a dict representation of a EnforcementAction model
203203
enforcement_action_model = {
204-
'action': 'audit_log',
204+
'action': 'disallow',
205205
}
206206

207207
update_rule_response = self.configuration_governance_service.update_rule(
208208
rule_id=rule_id_link,
209-
if_match='testString',
209+
if_match=rule_etag,
210210
name='Disable public access',
211211
description='Ensure that public access to account resources is disabled.',
212-
target={'service_name':'iam-groups','resource_kind':'service','additional_target_attributes':[]},
213-
required_config={'property':'public_access_enabled','operator':'is_false'},
212+
target=target_resource_model,
213+
required_config=rule_required_config_model,
214214
enforcement_actions=[enforcement_action_model],
215-
account_id='531fc3e28bfc43c5a2cea07786d93f5c',
215+
account_id=account_id,
216216
rule_type='user_defined',
217-
labels=['SOC2', 'ITCS300'],
217+
labels=[rule_label],
218218
transaction_id='testString'
219219
)
220220

@@ -249,23 +249,32 @@ def test_get_rule_attachment(self):
249249
rule_attachment = get_rule_attachment_response.get_result()
250250
assert rule_attachment is not None
251251

252+
global rule_attachment_etag
253+
rule_attachment_etag = get_rule_attachment_response.headers['etag']
254+
252255
@needscredentials
253256
def test_update_rule_attachment(self):
254257

255258
# Construct a dict representation of a RuleScope model
256259
rule_scope_model = {
257-
'note': 'My enterprise',
258-
'scope_id': '282cf433ac91493ba860480d92519990',
259-
'scope_type': 'enterprise',
260+
'note': 'My account',
261+
'scope_id': account_id,
262+
'scope_type': 'account',
263+
}
264+
265+
excluded_scope_model = {
266+
'note': 'My account resource group',
267+
'scope_id': resource_group_id,
268+
'scope_type': 'account.resource_group',
260269
}
261270

262271
update_rule_attachment_response = self.configuration_governance_service.update_rule_attachment(
263272
rule_id=rule_id_link,
264273
attachment_id=rule_attachment_id_link,
265-
if_match='testString',
266-
account_id='531fc3e28bfc43c5a2cea07786d93f5c',
267-
included_scope={'note':'My enterprise','scope_id':'282cf433ac91493ba860480d92519990','scope_type':'enterprise'},
268-
excluded_scopes=[rule_scope_model],
274+
if_match=rule_attachment_etag,
275+
account_id=account_id,
276+
included_scope=rule_scope_model,
277+
excluded_scopes=[excluded_scope_model],
269278
transaction_id='testString'
270279
)
271280

0 commit comments

Comments
 (0)