-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SSOAdmin: Default Instance and provisioning of permission sets (#7727)
- Loading branch information
Showing
6 changed files
with
259 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import boto3 | ||
|
||
from moto import mock_aws | ||
from tests import DEFAULT_ACCOUNT_ID | ||
|
||
|
||
@mock_aws | ||
def test_list_instances(): | ||
ssoadmin = boto3.client("sso-admin", "us-east-1") | ||
|
||
# We automatically create an instance on startup | ||
# In AWS, this would involve some manual steps on the dashboard | ||
instances = ssoadmin.list_instances()["Instances"] | ||
assert len(instances) == 1 | ||
|
||
assert instances[0]["CreatedDate"] | ||
assert instances[0]["IdentityStoreId"].startswith("d-") | ||
assert instances[0]["InstanceArn"].startswith("arn:aws:sso:::instance/ssoins-") | ||
assert instances[0]["OwnerAccountId"] == DEFAULT_ACCOUNT_ID | ||
assert instances[0]["Status"] == "ACTIVE" | ||
|
||
assert "Name" not in instances[0] | ||
|
||
|
||
@mock_aws | ||
def test_update_instance(): | ||
ssoadmin = boto3.client("sso-admin", "us-east-1") | ||
|
||
# We automatically create an instance on startup | ||
# In AWS, this would involve some manual steps on the dashboard | ||
initial = ssoadmin.list_instances()["Instances"][0] | ||
|
||
ssoadmin.update_instance(InstanceArn=initial["InstanceArn"], Name="instancename") | ||
|
||
updated = ssoadmin.list_instances()["Instances"][0] | ||
assert updated["Name"] == "instancename" | ||
assert initial["IdentityStoreId"] == updated["IdentityStoreId"] | ||
assert initial["InstanceArn"] == updated["InstanceArn"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import boto3 | ||
|
||
from moto import mock_aws | ||
from tests import DEFAULT_ACCOUNT_ID | ||
|
||
|
||
@mock_aws | ||
def test_provision_permission_set(): | ||
ssoadmin = boto3.client("sso-admin", "us-east-1") | ||
|
||
instance_arn = ssoadmin.list_instances()["Instances"][0]["InstanceArn"] | ||
|
||
p_set_arn = ssoadmin.create_permission_set(InstanceArn=instance_arn, Name="pset1")[ | ||
"PermissionSet" | ||
]["PermissionSetArn"] | ||
|
||
status = ssoadmin.provision_permission_set( | ||
InstanceArn=instance_arn, | ||
PermissionSetArn=p_set_arn, | ||
TargetType="AWS_ACCOUNT", | ||
)["PermissionSetProvisioningStatus"] | ||
|
||
assert status["AccountId"] == DEFAULT_ACCOUNT_ID | ||
assert status["CreatedDate"] | ||
assert status["PermissionSetArn"] == p_set_arn | ||
assert status["Status"] == "SUCCEEDED" | ||
|
||
|
||
@mock_aws | ||
def test_list_permission_sets_provisioned_to_account(): | ||
ssoadmin = boto3.client("sso-admin", "us-east-1") | ||
|
||
instance_arn = ssoadmin.list_instances()["Instances"][0]["InstanceArn"] | ||
|
||
p_set_arn = ssoadmin.create_permission_set(InstanceArn=instance_arn, Name="pset1")[ | ||
"PermissionSet" | ||
]["PermissionSetArn"] | ||
|
||
provisioned = ssoadmin.list_permission_sets_provisioned_to_account( | ||
AccountId=DEFAULT_ACCOUNT_ID, InstanceArn=instance_arn | ||
)["PermissionSets"] | ||
assert len(provisioned) == 0 | ||
|
||
accounts = ssoadmin.list_accounts_for_provisioned_permission_set( | ||
InstanceArn=instance_arn, PermissionSetArn=p_set_arn | ||
)["AccountIds"] | ||
assert accounts == [] | ||
|
||
ssoadmin.provision_permission_set( | ||
InstanceArn=instance_arn, | ||
PermissionSetArn=p_set_arn, | ||
TargetType="AWS_ACCOUNT", | ||
) | ||
|
||
provisioned = ssoadmin.list_permission_sets_provisioned_to_account( | ||
AccountId=DEFAULT_ACCOUNT_ID, InstanceArn=instance_arn | ||
)["PermissionSets"] | ||
assert provisioned == [p_set_arn] | ||
|
||
accounts = ssoadmin.list_accounts_for_provisioned_permission_set( | ||
InstanceArn=instance_arn, PermissionSetArn=p_set_arn | ||
)["AccountIds"] | ||
assert accounts == [DEFAULT_ACCOUNT_ID] |