async def test_activate_user(self, fs):
        # Instantiate Mock Client
        test_client = MockOktaClient(fs)

        # Create Password
        password = models.PasswordCredential({"value": "Password150kta"})
        # Create User Credentials
        user_creds = models.UserCredentials({"password": password})

        # Create User Profile and CreateUser Request
        user_profile = models.UserProfile()
        user_profile.first_name = "John"
        user_profile.last_name = "Doe-Activate"
        user_profile.email = "*****@*****.**"
        user_profile.login = "******"

        create_user_req = models.CreateUserRequest({
            "credentials": user_creds,
            "profile": user_profile
        })

        try:
            # Create query parameters and Create User
            query_params_create = {"activate": "False"}
            user, resp, err = await test_client.create_user(
                create_user_req, query_params_create)
            assert err is None

            # Create query parameters and Activate User
            query_params_activate = {"sendEmail": "False"}
            token, resp, err = await test_client.activate_user(
                user.id, query_params_activate)
            assert err is None
            assert token is not None
            # Ensure correct Object is returned
            assert isinstance(token, models.UserActivationToken)

            # Create query parameters and List Users
            query_params_list = {"filter": "status eq \"ACTIVE\""}
            users, resp, err = await test_client.list_users(query_params_list)
            assert err is None
            # Ensure user is in list
            assert next((usr for usr in users if usr.id == user.id),
                        None) is not None

        finally:
            errors = []
            # Deactivate, then delete created user
            try:
                _, err = await test_client.deactivate_or_delete_user(user.id)
                assert err is None
            except Exception as exc:
                errors.append(exc)

            try:
                _, err = await test_client.deactivate_or_delete_user(user.id)
                assert err is None
            except Exception as exc:
                errors.append(exc)
            assert len(errors) == 0
Beispiel #2
0
 async def test_upload_org_logo(self, fs):
     client = MockOktaClient(fs)
     fs.pause()
     logo = open(f'tests/integration/data/logo.png', 'rb')
     _, err = await client.update_org_logo(logo)
     fs.resume()
     assert err is None
Beispiel #3
0
    async def test_create_get_sign_on_policy_with_group_conditions(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create Group
        GROUP_NAME = "Group-Target-Test"
        group_obj = models.Group(
            {"profile": models.GroupProfile({"name": GROUP_NAME})})
        created_group, _, err = await client.create_group(group_obj)
        assert err is None
        assert isinstance(created_group, models.Group)

        # Create Policy & Conditions
        policy_model = models.OktaSignOnPolicy({
            "name":
            f"{TestPoliciesResource.SDK_PREFIX} Test-Sign-On",
            "status":
            "ACTIVE",
            "description":
            "Test policy applies for tests only"
        })

        policy_conditions = models.OktaSignOnPolicyConditions({
            "people":
            models.PolicyPeopleCondition({
                "groups":
                models.GroupCondition({"include": [created_group.id]})
            })
        })

        policy_model.conditions = policy_conditions

        created_policy, _, err = await client.create_policy(policy_model)
        assert err is None
        assert isinstance(created_policy, models.OktaSignOnPolicy)
        assert created_policy.name == policy_model.name
        assert created_policy.description == policy_model.description
        assert created_policy.status == "ACTIVE"
        assert created_policy.type == models.PolicyType.OKTA_SIGN_ON
        assert len(created_policy.conditions.people.groups.include) == 1
        assert created_group.id in \
            created_policy.conditions.people.groups.include

        # Retrieve
        retrieved_policy, _, err = await client.get_policy(created_policy.id)
        assert err is None
        assert retrieved_policy.id == created_policy.id
        assert retrieved_policy.name == created_policy.name
        assert retrieved_policy.description == created_policy.description
        assert retrieved_policy.status == created_policy.status
        assert retrieved_policy.type == created_policy.type
        assert len(retrieved_policy.conditions.people.groups.include) == 1
        assert created_group.id in \
            retrieved_policy.conditions.people.groups.include

        # Delete Policy + Group
        _, err = await client.delete_policy(created_policy.id)
        assert err is None
        _, err = await client.delete_group(created_group.id)
        assert err is None
Beispiel #4
0
    async def test_create_password_policy(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create Policy
        policy_model = models.PasswordPolicy({
            "name":
            f"{TestPoliciesResource.SDK_PREFIX} Test-Password",
            "status":
            "ACTIVE",
            "description":
            "Test policy applies for tests only"
        })

        created_policy, _, err = await client.create_policy(policy_model)
        assert err is None
        assert isinstance(created_policy, models.PasswordPolicy)
        assert created_policy.name == policy_model.name
        assert created_policy.description == policy_model.description
        assert created_policy.status == "ACTIVE"
        assert created_policy.type == models.PolicyType.PASSWORD

        # Retrieve
        retrieved_policy, _, err = await client.get_policy(created_policy.id)
        assert err is None
        assert retrieved_policy.id == created_policy.id
        assert retrieved_policy.name == created_policy.name
        assert retrieved_policy.description == created_policy.description
        assert retrieved_policy.status == created_policy.status
        assert retrieved_policy.type == created_policy.type

        # Delete
        _, err = await client.delete_policy(created_policy.id)
        assert err is None
    async def test_list_groups(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create Group Object
        GROUP_NAME = "Group-Target-Test"
        group_profile = models.GroupProfile({
            "name": GROUP_NAME
        })
        group_obj = models.Group({
            "profile": group_profile
        })

        try:
            # Create Group
            group, _, err = await client.create_group(group_obj)
            assert err is None
            assert isinstance(group, models.Group)

            groups_list, resp, err = await client.list_groups()
            assert err is None
            assert not resp.has_next()
            assert next((grp for grp in groups_list if grp.id == group.id))

        finally:
            # Delete created group
            _, err = await client.delete_group(group.id)
            assert err is None
    async def test_search_group(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create Group Object
        GROUP_NAME = "Group-Target-Test"
        group_profile = models.GroupProfile({
            "name": GROUP_NAME
        })
        group_obj = models.Group({
            "profile": group_profile
        })

        try:
            # Create Group
            group, _, err = await client.create_group(group_obj)
            assert err is None
            assert isinstance(group, models.Group)

            query_params_query = {"q": GROUP_NAME}
            groups_list, _, err = await client.list_groups(query_params_query)
            assert err is None
            assert groups_list
            assert len(groups_list) == 1
            assert next((grp for grp in groups_list if grp.id == group.id))

        finally:
            # Delete created group
            _, err = await client.delete_group(group.id)
            assert err is None
    async def test_update_group(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create Group Object
        GROUP_NAME = "Group-Target-Test"
        group_profile = models.GroupProfile({"name": GROUP_NAME})
        group_obj = models.Group({"profile": group_profile})

        # Create Group
        group, _, err = await client.create_group(group_obj)
        assert err is None
        assert isinstance(group, models.Group)

        # Create Updated Group Object
        # Create Group Object
        NEW_GROUP_NAME = "Group-Target-Test NEW"
        new_group_profile = models.GroupProfile({"name": NEW_GROUP_NAME})
        new_group_obj = models.Group({"profile": new_group_profile})

        _, _, err = await client.update_group(group.id, new_group_obj)
        assert err is None

        # Verify update worked
        found_group, _, err = await client.get_group(group.id)
        assert err is None
        assert found_group.id == group.id
        assert found_group.profile.name == NEW_GROUP_NAME

        # Delete created group
        _, err = await client.delete_group(group.id)
        assert err is None
Beispiel #8
0
    async def test_update_custom_attribute(self, fs):
        client = MockOktaClient(fs)

        # make random custom attribute name, because it takes some time for cleanup
        random.seed(2021)
        custom_attribute_name = ''.join([ascii_lowercase[random.randint(0, 25)] for i in range(20)])
        definition = copy.deepcopy(ADD_CUSTOM_ATTRIBUTE_DEFINITION)
        definition['custom']['properties'][custom_attribute_name] = CUSTOM_ATTRIBUTE_PROPERTIES

        try:
            resp, _, err = await client.update_group_schema({'definitions': definition})
            assert err is None
            assert custom_attribute_name in resp.definitions.custom.properties
            assert resp.definitions.custom.properties[custom_attribute_name]['title'] == 'Test Custom Attribute'

            # update custom attribute
            resp.definitions.custom.properties[custom_attribute_name]['title'] = 'New Title'
            resp, _, err = await client.update_group_schema(resp)
            assert err is None
            assert resp.definitions.custom.properties[custom_attribute_name]['title'] == 'New Title'

        finally:
            definition = copy.deepcopy(REMOVE_CUSTOM_ATTRIBUTE_DEFINITION)
            definition['custom']['properties'][custom_attribute_name] = None
            resp, _, err = await client.update_group_schema({'definitions': definition}, keep_empty_params=True)
            assert err is None
            assert custom_attribute_name not in resp.definitions.custom.properties
    async def test_create_get_group(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create Group Object
        GROUP_NAME = "Group-Target-Test"
        group_profile = models.GroupProfile({"name": GROUP_NAME})
        group_obj = models.Group({"profile": group_profile})

        # Create Group
        group, _, err = await client.create_group(group_obj)
        assert err is None
        assert isinstance(group, models.Group)

        # Get group using ID
        found_group, _, err = await client.get_group(group.id)
        assert err is None
        assert found_group.id == group.id

        # Delete created group
        _, err = await client.delete_group(group.id)
        assert err is None

        # Ensure group cannot be found again
        found_group, resp, err = await client.get_group(group.id)
        assert err is not None
        assert resp.get_status() == HTTPStatus.NOT_FOUND
        assert found_group is None
Beispiel #10
0
    async def test_list_origins(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create Trusted Origin
        TO_NAME = f"{TestTrustedOriginsResource.SDK_PREFIX}_test_TO"
        TO_ORIGIN = "http://example.com"
        trusted_origin_model = models.TrustedOrigin({
            "name":
            TO_NAME,
            "origin":
            TO_ORIGIN,
            "scopes": [
                models.Scope({"type": models.ScopeType.CORS}),
                models.Scope({"type": models.ScopeType.REDIRECT}),
            ]
        })

        created_trusted_origin, _, err = await \
            client.create_origin(trusted_origin_model)
        assert err is None
        assert isinstance(created_trusted_origin, models.TrustedOrigin)

        # List
        trusted_origins, _, err = await client.list_origins()
        assert err is None
        assert isinstance(trusted_origins, list)
        assert len(trusted_origins) > 0
        assert isinstance(trusted_origins[0], models.TrustedOrigin)
        assert next((to for to in trusted_origins
                     if to.name == created_trusted_origin.name), None) \
            is not None

        # Delete
        _, err = await client.delete_origin(created_trusted_origin.id)
Beispiel #11
0
    async def test_create_get_origin(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create Trusted Origin
        TO_NAME = f"{TestTrustedOriginsResource.SDK_PREFIX}_test_TO"
        TO_ORIGIN = "http://example.com"
        trusted_origin_model = models.TrustedOrigin({
            "name":
            TO_NAME,
            "origin":
            TO_ORIGIN,
            "scopes": [
                models.Scope({"type": models.ScopeType.CORS}),
                models.Scope({"type": models.ScopeType.REDIRECT}),
            ]
        })

        created_trusted_origin, _, err = await \
            client.create_origin(trusted_origin_model)
        assert err is None
        assert isinstance(created_trusted_origin, models.TrustedOrigin)

        # Retrieve
        retrieved_origin, _, err = await \
            client.get_origin(created_trusted_origin.id)
        assert err is None
        assert isinstance(retrieved_origin, models.TrustedOrigin)
        assert retrieved_origin.name == created_trusted_origin.name
        assert len(retrieved_origin.scopes) == 2

        # Delete
        _, err = await client.delete_origin(created_trusted_origin.id)
Beispiel #12
0
 async def test_get_org_contact_types(self, fs):
     client = MockOktaClient(fs)
     org_contact_types, _, err = await client.get_org_contact_types()
     assert err is None
     for item in org_contact_types:
         assert isinstance(item, OrgContactTypeObj)
         assert isinstance(item.contact_type, OrgContactType)
Beispiel #13
0
 async def test_list_brands(self, fs):
     client = MockOktaClient(fs)
     brands, _, err = await client.list_brands()
     assert err is None
     assert len(brands) > 0
     for brand in brands:
         assert isinstance(brand, models.Brand)
Beispiel #14
0
    async def test_list_factors_new_user(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create User
        user_profile = models.UserProfile()
        user_profile.first_name = "John"
        user_profile.last_name = "Doe-List-Factor"
        user_profile.email = "*****@*****.**"
        user_profile.login = "******"

        create_user_req = models.CreateUserRequest({
            "credentials":
            models.UserCredentials({
                "password":
                models.PasswordCredential({"value": "Password150kta"})
            }),
            "profile":
            user_profile
        })

        created_user, _, err = await client.create_user(create_user_req)
        assert err is None
        assert isinstance(created_user, models.User)

        # List factor to validate
        users_factors, _, err = await client.list_factors(created_user.id)
        assert err is None
        assert len(users_factors) == 0

        # Deactivate + delete user
        _, err = await client.deactivate_user(created_user.id)
        assert err is None
        _, err = await client.deactivate_or_delete_user(created_user.id)
        assert err is None
    async def test_subscribe_unsubscribe_user(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        users, _, err = await client.list_users()
        assert err is None
        user = users[0]

        notification_type = models.NotificationType('OKTA_ISSUE')
        _, err = await client.subscribe_user_subscription_by_notification_type(
            user.id, notification_type)
        assert err is None

        resp, _, err = await client.get_user_subscription_by_notification_type(
            user.id, notification_type)
        assert resp.notification_type == models.NotificationType('OKTA_ISSUE')
        assert resp.status == models.SubscriptionStatus('SUBSCRIBED')

        _, err = await client.unsubscribe_user_subscription_by_notification_type(
            user.id, notification_type)
        assert err is None

        resp, _, err = await client.get_user_subscription_by_notification_type(
            user.id, notification_type)
        assert resp.notification_type == models.NotificationType('OKTA_ISSUE')
        assert resp.status == models.SubscriptionStatus('UNSUBSCRIBED')
Beispiel #16
0
    async def test_get_user_type(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create object
        TEST_DESC = F"{TestUserTypesResource.SDK_PREFIX} description"
        TEST_DISPLAY_NAME = F"{TestUserTypesResource.SDK_PREFIX} display name"
        TEST_NAME = F"{TestUserTypesResource.SDK_PREFIX}_akIKx"
        # ^ without VCR testing, can generate random TEST_NAME suffixes

        user_type_obj = models.UserType({
            "description": TEST_DESC,
            "displayName": TEST_DISPLAY_NAME,
            "name": TEST_NAME
        })

        try:
            created, _, err = await client.create_user_type(user_type_obj)
            assert err is None
            assert created.id is not None

            # Retrieve
            found, _, err = await client.get_user_type(created.id)
            assert err is None
            assert found.id == created.id
            assert found.description == TEST_DESC
            assert found.display_name == TEST_DISPLAY_NAME
            assert found.name == TEST_NAME

        finally:
            _, err = await client.delete_user_type(created.id)
            assert err is None
 async def test_get_threat_insight_configuration(self, fs):
     client = MockOktaClient(fs)
     resp, _, err = await client.get_current_configuration()
     assert isinstance(resp, ThreatInsightConfiguration)
     assert '_links' in resp.as_dict().keys()
     assert 'action' in resp.as_dict().keys()
     assert 'excludeZones' in resp.as_dict().keys()
    async def test_subscribe_unsubscribe_role_by_notification_type(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)
        notification_type = models.NotificationType('OKTA_ISSUE')
        _, err = await client.subscribe_role_subscription_by_notification_type(
            'SUPER_ADMIN', notification_type)
        assert err is None

        resp, _, err = await client.get_role_subscription_by_notification_type(
            'SUPER_ADMIN', notification_type)
        assert isinstance(resp, models.Subscription)
        assert resp.notification_type == models.NotificationType('OKTA_ISSUE')
        assert resp.status == models.SubscriptionStatus('SUBSCRIBED')

        try:
            _, err = await client.unsubscribe_role_subscription_by_notification_type(
                'SUPER_ADMIN', notification_type)
            assert err is None
            resp, _, err = await client.get_role_subscription_by_notification_type(
                'SUPER_ADMIN', notification_type)
            assert isinstance(resp, models.Subscription)
            assert resp.notification_type == models.NotificationType(
                'OKTA_ISSUE')
            assert resp.status == models.SubscriptionStatus('UNSUBSCRIBED')

        finally:
            # restore subscription
            _, err = await client.subscribe_role_subscription_by_notification_type(
                'SUPER_ADMIN', notification_type)
            assert err is None
Beispiel #19
0
    async def test_update_feature_lifecycle(self):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # List
        features, _, err = await client.list_features()
        assert err is None
        assert len(features) > 0
        assert isinstance(features[0], models.Feature)

        first_feature = features[0]

        # Update
        first_feature_id = first_feature.id
        original_status = first_feature.status
        lifecycle = "enable" if original_status == "DISABLED"\
            else "disable"
        status_change, _, err = await \
            client.update_feature_lifecycle(first_feature_id, lifecycle)
        assert err is None
        assert isinstance(status_change, models.Feature)
        assert original_status != status_change.status

        # Revert
        lifecycle = "disable" if original_status == "DISABLED"\
            else "enable"
        updated_status_change, _, err = await \
            client.update_feature_lifecycle(first_feature_id, lifecycle)
        assert err is None
        assert isinstance(updated_status_change, models.Feature)
        assert original_status == updated_status_change.status
    async def test_create_auth_server(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create Auth Server
        TEST_NAME = f"{TestAuthorizationServerResource.SDK_PREFIX}_test_aaPeZ"
        TEST_DESC = "Test Auth Server"
        TEST_AUDS = ["api://default"]
        auth_server_model = models.AuthorizationServer({
            "name": TEST_NAME,
            "description": TEST_DESC,
            "audiences": TEST_AUDS
        })

        created_auth_server, _, err = await \
            client.create_authorization_server(auth_server_model)
        assert err is None
        assert isinstance(created_auth_server, models.AuthorizationServer)
        assert created_auth_server.name == TEST_NAME
        assert created_auth_server.description == TEST_DESC
        assert created_auth_server.audiences == TEST_AUDS
        assert created_auth_server.audiences[0] == TEST_AUDS[0]

        # Clean up
        _, err = await client.deactivate_authorization_server(
            created_auth_server.id)
        assert err is None
        _, err = await client.delete_authorization_server(
            created_auth_server.id)
        assert err is None
Beispiel #21
0
    async def test_update_brand(self, fs):
        client = MockOktaClient(fs)
        custom_privacy_policy_url = 'https://www.someHost.com/privacy-policy'

        brands, _, err = await client.list_brands()
        assert err is None
        brand_id = brands[0].id
        brand, _, err = await client.get_brand(brand_id)
        assert err is None
        assert brand.id == brand_id
        assert brand.custom_privacy_policy_url != custom_privacy_policy_url

        new_brand = copy.deepcopy(brand)
        new_brand.agree_to_custom_privacy_policy = True
        new_brand.custom_privacy_policy_url = 'https://www.someHost.com/privacy-policy'

        try:
            updated_brand, _, err = await client.update_brand(
                brand_id, new_brand)
            assert err is None
            assert isinstance(updated_brand, models.Brand)
            assert brand.id == updated_brand.id
            assert updated_brand.custom_privacy_policy_url == custom_privacy_policy_url
        finally:
            # restore previous brand settings
            _, _, err = await client.update_brand(brand_id, brand)
            assert err is None
    async def test_assign_user_to_role(self, fs):
        # Instantiate Mock Client
        test_client = MockOktaClient(fs)

        # Create Password
        password = models.PasswordCredential({"value": "Password150kta"})
        # Create User Credentials
        user_creds = models.UserCredentials({"password": password})

        # Create User Profile and CreateUser Request
        user_profile = models.UserProfile()
        user_profile.first_name = "John"
        user_profile.last_name = "Doe-Assign-User-Role"
        user_profile.email = "*****@*****.**"
        user_profile.login = "******"

        create_user_req = models.CreateUserRequest({
            "credentials": user_creds,
            "profile": user_profile
        })

        # Create Query Parameters and Create User
        query_params_create = {"activate": "True"}
        user, _, err = await test_client.create_user(create_user_req,
                                                     query_params_create)
        assert err is None

        # Create Assign Role Request with Roletype Enum
        USER_ADMIN = models.RoleType.USER_ADMIN
        assign_role_req = models.AssignRoleRequest({"type": USER_ADMIN})

        # Assign Role to User
        _, _, err = await test_client.assign_role_to_user(
            user.id, assign_role_req)
        assert err is None

        # Get Roles for user and ensure role assigned is found
        roles, _, err = await test_client.list_assigned_roles_for_user(user.id)
        found_role = next((role for role in roles if role.type == USER_ADMIN),
                          None)
        assert found_role is not None

        # Remove assigned role from user
        _, err = await test_client.remove_role_from_user(
            user.id, found_role.id)
        assert err is None

        # Get Roles for user and ensure role assigned is NOT found
        roles, _, err = await test_client.list_assigned_roles_for_user(user.id)
        found_role = next((role for role in roles if role.type == USER_ADMIN),
                          None)
        assert found_role is None

        # Deactivate, then delete created user
        _, err = await test_client.deactivate_or_delete_user(user.id)
        assert err is None

        _, err = await test_client.deactivate_or_delete_user(user.id)
        assert err is None
    async def test_update_policy(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create Policy
        policy_model = models.OktaSignOnPolicy({
            "name":
            f"{TestPoliciesResource.SDK_PREFIX} Test-Sign-On",
            "status":
            "ACTIVE",
            "description":
            "Test policy applies for tests only"
        })

        try:
            created_policy, _, err = await client.create_policy(policy_model)
            assert err is None
            assert isinstance(created_policy, models.OktaSignOnPolicy)
            assert created_policy.name == policy_model.name
            assert created_policy.description == policy_model.description
            assert created_policy.status == "ACTIVE"
            assert created_policy.type == models.PolicyType.OKTA_SIGN_ON

            # Retrieve
            retrieved_policy, _, err = await client.get_policy(
                created_policy.id)
            assert err is None
            assert retrieved_policy.id == created_policy.id
            assert retrieved_policy.name == created_policy.name
            assert retrieved_policy.description == created_policy.description
            assert retrieved_policy.status == created_policy.status
            assert retrieved_policy.type == created_policy.type

            # Update
            NEW_NAME = policy_model.name + "UPDATED"
            NEW_DESC = policy_model.description + "UPDATED"
            created_policy.name = NEW_NAME
            created_policy.description = NEW_DESC
            updated_policy, _, err = await client.update_policy(
                created_policy.id, created_policy)
            assert err is None
            assert updated_policy.id == created_policy.id
            assert updated_policy.name == NEW_NAME
            assert updated_policy.description == NEW_DESC

            # Retrieve
            retrieved_policy, _, err = await client.get_policy(
                created_policy.id)
            assert err is None
            assert retrieved_policy.id == created_policy.id
            assert retrieved_policy.name == NEW_NAME
            assert retrieved_policy.description == NEW_DESC
            assert retrieved_policy.status == created_policy.status
            assert retrieved_policy.type == created_policy.type

        finally:
            # Delete
            _, err = await client.delete_policy(created_policy.id)
            assert err is None
Beispiel #24
0
    async def test_change_user_password(self, fs):
        # Instantiate Mock Client
        test_client = MockOktaClient(fs)

        # Create Password
        password = models.PasswordCredential({"value": "Password150kta"})
        # Create User Credentials
        user_creds = models.UserCredentials({"password": password})

        # Create User Profile and CreateUser Request
        user_profile = models.UserProfile()
        user_profile.first_name = "John"
        user_profile.last_name = "Doe-Change-PW"
        user_profile.email = "*****@*****.**"
        user_profile.login = "******"

        create_user_req = models.CreateUserRequest({
            "credentials": user_creds,
            "profile": user_profile
        })

        # Create Query Parameters and Create User
        query_params_create = {"activate": "True"}
        user, _, err = await test_client.create_user(create_user_req,
                                                     query_params_create)
        assert err is None

        # Give time before changing password
        time.sleep(1)

        # Create new Password
        NEW_PASSWORD = "******"
        new_password = models.PasswordCredential({"value": NEW_PASSWORD})

        change_pw_req = models.ChangePasswordRequest({
            "oldPassword":
            password,
            "newPassword":
            new_password
        })

        # change password and retrieve user after
        _, _, err = await test_client.change_password(user.id, change_pw_req)
        assert err is None

        got_user, resp, err = await test_client.get_user(user.id)
        assert got_user.id == user.id
        assert err is None
        # Verify password in updated user obj, changed after original
        DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
        assert datetime.strptime(got_user.password_changed, DATETIME_FORMAT)\
            > datetime.strptime(user.password_changed, DATETIME_FORMAT)

        # Deactivate, then delete created user
        _, err = await test_client.deactivate_or_delete_user(user.id)
        assert err is None

        _, err = await test_client.deactivate_or_delete_user(user.id)
        assert err is None
    async def test_delete_oauth2_scope(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create Auth Server
        TEST_NAME = f"{TestAuthorizationServerResource.SDK_PREFIX}_test_abDfZ"
        TEST_DESC = "Test Auth Server"
        TEST_AUDS = ["api://default"]
        auth_server_model = models.AuthorizationServer({
            "name": TEST_NAME,
            "description": TEST_DESC,
            "audiences": TEST_AUDS
        })

        created_auth_server, _, err = await \
            client.create_authorization_server(auth_server_model)
        assert err is None
        assert isinstance(created_auth_server, models.AuthorizationServer)
        assert created_auth_server.name == TEST_NAME
        assert created_auth_server.description == TEST_DESC
        assert created_auth_server.audiences == TEST_AUDS
        assert created_auth_server.audiences[0] == TEST_AUDS[0]

        # Create Oauth Scope
        SCOPE_NAME = f"{TestAuthorizationServerResource.SDK_PREFIX}:abDGz"
        scope_obj = models.OAuth2Scope({"name": SCOPE_NAME})

        oauth_scope, _, err = await client.create_o_auth_2_scope(
            created_auth_server.id, scope_obj)
        assert err is None
        assert isinstance(oauth_scope, models.OAuth2Scope)
        assert oauth_scope.name == scope_obj.name

        # Get Oauth Scope
        found_oauth_scope, _, err = await client.get_o_auth_2_scope(
            created_auth_server.id, oauth_scope.id)
        assert err is None
        assert found_oauth_scope.name == oauth_scope.name

        # Delete Oauth Scope
        _, err = await client.delete_o_auth_2_scope(created_auth_server.id,
                                                    oauth_scope.id)
        assert err is None

        # Get Oauth Scope
        found_oauth_scope, resp, err = await client.get_o_auth_2_scope(
            created_auth_server.id, oauth_scope.id)
        assert err is not None
        assert isinstance(err, OktaAPIError)
        assert resp.get_status() == HTTPStatus.NOT_FOUND

        # DeActivate Auth server
        _, err = await client.deactivate_authorization_server(
            created_auth_server.id)
        assert err is None
        # Delete Auth server
        _, err = await client.delete_authorization_server(
            created_auth_server.id)
        assert err is None
    async def test_delete_sms_template(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create SMS Template
        sms_translations = models.SmsTemplateTranslations()
        sms_translations.es = \
            "${org.name}: el código de verificación es ${code}"
        sms_translations.fr = \
            "${org.name}: votre code de vérification est ${code}"
        sms_translations.it = "${org.name}: il codice di verifica è ${code}"

        sms_template_model = models.SmsTemplate({
            "name":
            f"{TestTemplatesResource.SDK_PREFIX}-test-template",
            "type":
            models.SmsTemplateType.SMS_VERIFY_CODE,
            "template":
            "${org.name}: your verification code is ${code}",
            "translations":
            sms_translations
        })

        try:
            created_template, _, err = await client.\
                create_sms_template(sms_template_model)
            assert err is None
            assert isinstance(created_template, models.SmsTemplate)
            assert created_template.name == sms_template_model.name
            assert created_template.type == sms_template_model.type
            assert created_template.template == sms_template_model.template

            # Retrieve
            retrieved_template, _, err = await client.\
                get_sms_template(created_template.id)
            assert err is None
            assert retrieved_template.id == created_template.id
            assert retrieved_template.name == created_template.name
            assert retrieved_template.template == created_template.template
            assert retrieved_template.translations.es == sms_translations.es
            assert retrieved_template.translations.it == sms_translations.it
            assert retrieved_template.translations.fr == sms_translations.fr

            # Delete
            _, err = await client.delete_sms_template(created_template.id)
            assert err is None

            # Retrieve
            retrieved_template, resp, err = await client.\
                get_sms_template(created_template.id)
            assert err is not None
            assert isinstance(err, OktaAPIError)
            assert resp.get_status() == HTTPStatus.NOT_FOUND
            assert retrieved_template is None
        finally:
            try:
                _, err = await client.delete_sms_template(created_template.id)
            except Exception:
                pass
 async def test_list_authenticators(self, fs):
     client = MockOktaClient(fs)
     resp, _, err = await client.list_authenticators()
     assert err is None
     assert len(resp) > 0
     assert all([isinstance(elem, models.Authenticator) for elem in resp])
     assert all(
         [isinstance(elem.type, models.AuthenticatorType) for elem in resp])
 async def test_get_role_subscription_by_notification_type(self, fs):
     # Instantiate Mock Client
     client = MockOktaClient(fs)
     notification_type = models.NotificationType('OKTA_ISSUE')
     resp, _, err = await client.get_role_subscription_by_notification_type(
         'SUPER_ADMIN', notification_type)
     assert isinstance(resp, models.Subscription)
     assert resp.notification_type == models.NotificationType('OKTA_ISSUE')
 async def test_list_network_zones(self, fs):
     client = MockOktaClient(fs)
     resp, _, err = await client.list_network_zones()
     for network_zone in resp:
         assert isinstance(network_zone, NetworkZone)
         assert isinstance(network_zone.type, NetworkZoneType)
         assert isinstance(network_zone.status, NetworkZoneStatus)
         assert isinstance(network_zone.usage, NetworkZoneUsage)
Beispiel #30
0
 async def test_get_org_contact_user(self, fs):
     client = MockOktaClient(fs)
     contact_type = OrgContactType('BILLING')
     org_contact_user, _, err = await client.get_org_contact_user(
         contact_type)
     assert err is None
     assert isinstance(org_contact_user, OrgContactUser)
     assert org_contact_user.user_id is not None