Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    async def test_list_oauth2_scopes(self, fs):
        # Instantiate Mock Client
        client = MockOktaClient(fs)

        # Create Auth Server
        TEST_NAME = f"{TestAuthorizationServerResource.SDK_PREFIX}_test_abDgZ"
        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

        # List Oauth Scopes
        scopes, _, err = await client.list_o_auth_2_scopes(
            created_auth_server.id)
        assert err is None
        assert len(scopes) > 0
        assert next((scope for scope in scopes if scope.id == oauth_scope.id))

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

        # 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
Ejemplo n.º 3
0
    async def test_update_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}:abDHz"
        scope_obj = models.OAuth2Scope({
            "name": SCOPE_NAME,
            "consent": "REQUIRED",
            "metadataPublish": "ALL_CLIENTS"
        })
        UPDATED_SCOPE_NAME = f"{SCOPE_NAME}updated"
        updated_obj = models.OAuth2Scope({
            "name": UPDATED_SCOPE_NAME,
            "consent": "REQUIRED",
            "metadataPublish": "ALL_CLIENTS"
        })

        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

        # Update scope
        updated_scope, _, err = await client.update_o_auth_2_scope(
            created_auth_server.id, oauth_scope.id, updated_obj)
        assert err is None
        assert updated_scope.name == UPDATED_SCOPE_NAME

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

        # 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