Various changes to organizations endpoint (#3175)
* Raise DuplicatePolicyException when a policy with the same name exists * Implement update_policy * Implement delete_policy
This commit is contained in:
parent
1eda31cb76
commit
cdc4385e2a
5 changed files with 139 additions and 8 deletions
|
|
@ -420,18 +420,56 @@ def test_attach_policy():
|
|||
account_id = client.create_account(AccountName=mockname, Email=mockemail)[
|
||||
"CreateAccountStatus"
|
||||
]["AccountId"]
|
||||
|
||||
|
||||
@mock_organizations
|
||||
def test_delete_policy():
|
||||
client = boto3.client("organizations", region_name="us-east-1")
|
||||
org = client.create_organization(FeatureSet="ALL")["Organization"]
|
||||
base_policies = client.list_policies(Filter="SERVICE_CONTROL_POLICY")["Policies"]
|
||||
base_policies.should.have.length_of(1)
|
||||
policy_id = client.create_policy(
|
||||
Content=json.dumps(policy_doc01),
|
||||
Description="A dummy service control policy",
|
||||
Name="MockServiceControlPolicy",
|
||||
Type="SERVICE_CONTROL_POLICY",
|
||||
)["Policy"]["PolicySummary"]["Id"]
|
||||
response = client.attach_policy(PolicyId=policy_id, TargetId=root_id)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
response = client.attach_policy(PolicyId=policy_id, TargetId=ou_id)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
response = client.attach_policy(PolicyId=policy_id, TargetId=account_id)
|
||||
new_policies = client.list_policies(Filter="SERVICE_CONTROL_POLICY")["Policies"]
|
||||
new_policies.should.have.length_of(2)
|
||||
response = client.delete_policy(PolicyId=policy_id)
|
||||
response["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)
|
||||
new_policies = client.list_policies(Filter="SERVICE_CONTROL_POLICY")["Policies"]
|
||||
new_policies.should.equal(base_policies)
|
||||
new_policies.should.have.length_of(1)
|
||||
|
||||
|
||||
@mock_organizations
|
||||
def test_delete_policy_exception():
|
||||
client = boto3.client("organizations", region_name="us-east-1")
|
||||
org = client.create_organization(FeatureSet="ALL")["Organization"]
|
||||
non_existent_policy_id = utils.make_random_service_control_policy_id()
|
||||
with assert_raises(ClientError) as e:
|
||||
response = client.delete_policy(PolicyId=non_existent_policy_id)
|
||||
ex = e.exception
|
||||
ex.operation_name.should.equal("DeletePolicy")
|
||||
ex.response["Error"]["Code"].should.equal("400")
|
||||
ex.response["Error"]["Message"].should.contain("PolicyNotFoundException")
|
||||
|
||||
# Attempt to delete an attached policy
|
||||
policy_id = client.create_policy(
|
||||
Content=json.dumps(policy_doc01),
|
||||
Description="A dummy service control policy",
|
||||
Name="MockServiceControlPolicy",
|
||||
Type="SERVICE_CONTROL_POLICY",
|
||||
)["Policy"]["PolicySummary"]["Id"]
|
||||
root_id = client.list_roots()["Roots"][0]["Id"]
|
||||
client.attach_policy(PolicyId=policy_id, TargetId=root_id)
|
||||
with assert_raises(ClientError) as e:
|
||||
response = client.delete_policy(PolicyId=policy_id)
|
||||
ex = e.exception
|
||||
ex.operation_name.should.equal("DeletePolicy")
|
||||
ex.response["Error"]["Code"].should.equal("400")
|
||||
ex.response["Error"]["Message"].should.contain("PolicyInUseException")
|
||||
|
||||
|
||||
@mock_organizations
|
||||
|
|
@ -479,6 +517,44 @@ def test_attach_policy_exception():
|
|||
ex.response["Error"]["Message"].should.contain("InvalidInputException")
|
||||
|
||||
|
||||
@mock_organizations
|
||||
def test_update_policy():
|
||||
client = boto3.client("organizations", region_name="us-east-1")
|
||||
org = client.create_organization(FeatureSet="ALL")["Organization"]
|
||||
|
||||
policy_dict = dict(
|
||||
Content=json.dumps(policy_doc01),
|
||||
Description="A dummy service control policy",
|
||||
Name="MockServiceControlPolicy",
|
||||
Type="SERVICE_CONTROL_POLICY",
|
||||
)
|
||||
policy_id = client.create_policy(**policy_dict)["Policy"]["PolicySummary"]["Id"]
|
||||
|
||||
for key in ("Description", "Name"):
|
||||
response = client.update_policy(**{"PolicyId": policy_id, key: "foobar"})
|
||||
policy = client.describe_policy(PolicyId=policy_id)
|
||||
policy["Policy"]["PolicySummary"][key].should.equal("foobar")
|
||||
validate_service_control_policy(org, response["Policy"])
|
||||
|
||||
response = client.update_policy(PolicyId=policy_id, Content="foobar")
|
||||
policy = client.describe_policy(PolicyId=policy_id)
|
||||
policy["Policy"]["Content"].should.equal("foobar")
|
||||
validate_service_control_policy(org, response["Policy"])
|
||||
|
||||
|
||||
@mock_organizations
|
||||
def test_update_policy_exception():
|
||||
client = boto3.client("organizations", region_name="us-east-1")
|
||||
org = client.create_organization(FeatureSet="ALL")["Organization"]
|
||||
non_existent_policy_id = utils.make_random_service_control_policy_id()
|
||||
with assert_raises(ClientError) as e:
|
||||
response = client.update_policy(PolicyId=non_existent_policy_id)
|
||||
ex = e.exception
|
||||
ex.operation_name.should.equal("UpdatePolicy")
|
||||
ex.response["Error"]["Code"].should.equal("400")
|
||||
ex.response["Error"]["Message"].should.contain("PolicyNotFoundException")
|
||||
|
||||
|
||||
@mock_organizations
|
||||
def test_list_polices():
|
||||
client = boto3.client("organizations", region_name="us-east-1")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue