diff --git a/tests/conftest.py b/tests/conftest.py index 39bd584..e0d93ea 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -35,7 +35,17 @@ class KeycloakTestEnv(object): username: str = os.environ["KEYCLOAK_ADMIN"], password: str = os.environ["KEYCLOAK_ADMIN_PASSWORD"], ): - """Init method.""" + """Init method. + + :param host: Hostname + :type host: str + :param port: Port + :type port: str + :param username: Admin username + :type username: str + :param password: Admin password + :type password: str + """ self.KEYCLOAK_HOST = host self.KEYCLOAK_PORT = port self.KEYCLOAK_ADMIN = username @@ -43,54 +53,96 @@ class KeycloakTestEnv(object): @property def KEYCLOAK_HOST(self): - """Hostname getter.""" + """Hostname getter. + + :returns: Keycloak host + :rtype: str + """ return self._KEYCLOAK_HOST @KEYCLOAK_HOST.setter def KEYCLOAK_HOST(self, value: str): - """Hostname setter.""" + """Hostname setter. + + :param value: Keycloak host + :type value: str + """ self._KEYCLOAK_HOST = value @property def KEYCLOAK_PORT(self): - """Port getter.""" + """Port getter. + + :returns: Keycloak port + :rtype: str + """ return self._KEYCLOAK_PORT @KEYCLOAK_PORT.setter def KEYCLOAK_PORT(self, value: str): - """Port setter.""" + """Port setter. + + :param value: Keycloak port + :type value: str + """ self._KEYCLOAK_PORT = value @property def KEYCLOAK_ADMIN(self): - """Admin username getter.""" + """Admin username getter. + + :returns: Admin username + :rtype: str + """ return self._KEYCLOAK_ADMIN @KEYCLOAK_ADMIN.setter def KEYCLOAK_ADMIN(self, value: str): - """Admin username setter.""" + """Admin username setter. + + :param value: Admin username + :type value: str + """ self._KEYCLOAK_ADMIN = value @property def KEYCLOAK_ADMIN_PASSWORD(self): - """Admin password getter.""" + """Admin password getter. + + :returns: Admin password + :rtype: str + """ return self._KEYCLOAK_ADMIN_PASSWORD @KEYCLOAK_ADMIN_PASSWORD.setter def KEYCLOAK_ADMIN_PASSWORD(self, value: str): - """Admin password setter.""" + """Admin password setter. + + :param value: Admin password + :type value: str + """ self._KEYCLOAK_ADMIN_PASSWORD = value @pytest.fixture def env(): - """Fixture for getting the test environment configuration object.""" + """Fixture for getting the test environment configuration object. + + :returns: Keycloak test environment object + :rtype: KeycloakTestEnv + """ return KeycloakTestEnv() @pytest.fixture def admin(env: KeycloakTestEnv): - """Fixture for initialized KeycloakAdmin class.""" + """Fixture for initialized KeycloakAdmin class. + + :param env: Keycloak test environment + :type env: KeycloakTestEnv + :returns: Keycloak admin + :rtype: KeycloakAdmin + """ return KeycloakAdmin( server_url=f"http://{env.KEYCLOAK_HOST}:{env.KEYCLOAK_PORT}", username=env.KEYCLOAK_ADMIN, @@ -100,7 +152,17 @@ def admin(env: KeycloakTestEnv): @pytest.fixture def oid(env: KeycloakTestEnv, realm: str, admin: KeycloakAdmin): - """Fixture for initialized KeycloakOpenID class.""" + """Fixture for initialized KeycloakOpenID class. + + :param env: Keycloak test environment + :type env: KeycloakTestEnv + :param realm: Keycloak realm + :type realm: str + :param admin: Keycloak admin + :type admin: KeycloakAdmin + :yields: Keycloak OpenID client + :rtype: KeycloakOpenID + """ # Set the realm admin.realm_name = realm # Create client @@ -126,7 +188,17 @@ def oid(env: KeycloakTestEnv, realm: str, admin: KeycloakAdmin): @pytest.fixture def oid_with_credentials(env: KeycloakTestEnv, realm: str, admin: KeycloakAdmin): - """Fixture for an initialized KeycloakOpenID class and a random user credentials.""" + """Fixture for an initialized KeycloakOpenID class and a random user credentials. + + :param env: Keycloak test environment + :type env: KeycloakTestEnv + :param realm: Keycloak realm + :type realm: str + :param admin: Keycloak admin + :type admin: KeycloakAdmin + :yields: Keycloak OpenID client with user credentials + :rtype: Tuple[KeycloakOpenID, str, str] + """ # Set the realm admin.realm_name = realm # Create client @@ -173,7 +245,17 @@ def oid_with_credentials(env: KeycloakTestEnv, realm: str, admin: KeycloakAdmin) @pytest.fixture def oid_with_credentials_authz(env: KeycloakTestEnv, realm: str, admin: KeycloakAdmin): - """Fixture for an initialized KeycloakOpenID class and a random user credentials.""" + """Fixture for an initialized KeycloakOpenID class and a random user credentials. + + :param env: Keycloak test environment + :type env: KeycloakTestEnv + :param realm: Keycloak realm + :type realm: str + :param admin: Keycloak admin + :type admin: KeycloakAdmin + :yields: Keycloak OpenID client configured as an authorization server with client credentials + :rtype: Tuple[KeycloakOpenID, str, str] + """ # Set the realm admin.realm_name = realm # Create client @@ -229,7 +311,13 @@ def oid_with_credentials_authz(env: KeycloakTestEnv, realm: str, admin: Keycloak @pytest.fixture def realm(admin: KeycloakAdmin) -> str: - """Fixture for a new random realm.""" + """Fixture for a new random realm. + + :param admin: Keycloak admin + :type admin: KeycloakAdmin + :yields: Keycloak realm + :rtype: str + """ realm_name = str(uuid.uuid4()) admin.create_realm(payload={"realm": realm_name, "enabled": True}) yield realm_name @@ -238,7 +326,15 @@ def realm(admin: KeycloakAdmin) -> str: @pytest.fixture def user(admin: KeycloakAdmin, realm: str) -> str: - """Fixture for a new random user.""" + """Fixture for a new random user. + + :param admin: Keycloak admin + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + :yields: Keycloak user + :rtype: str + """ admin.realm_name = realm username = str(uuid.uuid4()) user_id = admin.create_user(payload={"username": username, "email": f"{username}@test.test"}) @@ -248,7 +344,15 @@ def user(admin: KeycloakAdmin, realm: str) -> str: @pytest.fixture def group(admin: KeycloakAdmin, realm: str) -> str: - """Fixture for a new random group.""" + """Fixture for a new random group. + + :param admin: Keycloak admin + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + :yields: Keycloak group + :rtype: str + """ admin.realm_name = realm group_name = str(uuid.uuid4()) group_id = admin.create_group(payload={"name": group_name}) @@ -258,7 +362,15 @@ def group(admin: KeycloakAdmin, realm: str) -> str: @pytest.fixture def client(admin: KeycloakAdmin, realm: str) -> str: - """Fixture for a new random client.""" + """Fixture for a new random client. + + :param admin: Keycloak admin + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + :yields: Keycloak client id + :rtype: str + """ admin.realm_name = realm client = str(uuid.uuid4()) client_id = admin.create_client(payload={"name": client, "clientId": client}) @@ -268,7 +380,17 @@ def client(admin: KeycloakAdmin, realm: str) -> str: @pytest.fixture def client_role(admin: KeycloakAdmin, realm: str, client: str) -> str: - """Fixture for a new random client role.""" + """Fixture for a new random client role. + + :param admin: Keycloak admin + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + :param client: Keycloak client + :type client: str + :yields: Keycloak client role + :rtype: str + """ admin.realm_name = realm role = str(uuid.uuid4()) admin.create_client_role(client, {"name": role, "composite": False}) @@ -278,7 +400,19 @@ def client_role(admin: KeycloakAdmin, realm: str, client: str) -> str: @pytest.fixture def composite_client_role(admin: KeycloakAdmin, realm: str, client: str, client_role: str) -> str: - """Fixture for a new random composite client role.""" + """Fixture for a new random composite client role. + + :param admin: Keycloak admin + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + :param client: Keycloak client + :type client: str + :param client_role: Keycloak client role + :type client_role: str + :yields: Composite client role + :rtype: str + """ admin.realm_name = realm role = str(uuid.uuid4()) admin.create_client_role(client, {"name": role, "composite": True}) @@ -290,7 +424,11 @@ def composite_client_role(admin: KeycloakAdmin, realm: str, client: str, client_ @pytest.fixture def selfsigned_cert(): - """Generate self signed certificate for a hostname, and optional IP addresses.""" + """Generate self signed certificate for a hostname, and optional IP addresses. + + :returns: Selfsigned certificate + :rtype: Tuple[str, str] + """ hostname = "testcert" ip_addresses = None key = None diff --git a/tests/test_keycloak_admin.py b/tests/test_keycloak_admin.py index b55e1c7..f2865f9 100644 --- a/tests/test_keycloak_admin.py +++ b/tests/test_keycloak_admin.py @@ -22,7 +22,11 @@ def test_keycloak_version(): def test_keycloak_admin_bad_init(env): - """Test keycloak admin bad init.""" + """Test keycloak admin bad init. + + :param env: Environment fixture + :type env: KeycloakTestEnv + """ with pytest.raises(TypeError) as err: KeycloakAdmin( server_url=f"http://{env.KEYCLOAK_HOST}:{env.KEYCLOAK_PORT}", @@ -43,7 +47,11 @@ def test_keycloak_admin_bad_init(env): def test_keycloak_admin_init(env): - """Test keycloak admin init.""" + """Test keycloak admin init. + + :param env: Environment fixture + :type env: KeycloakTestEnv + """ admin = KeycloakAdmin( server_url=f"http://{env.KEYCLOAK_HOST}:{env.KEYCLOAK_PORT}", username=env.KEYCLOAK_ADMIN, @@ -118,7 +126,11 @@ def test_keycloak_admin_init(env): def test_realms(admin: KeycloakAdmin): - """Test realms.""" + """Test realms. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + """ # Get realms realms = admin.get_realms() assert len(realms) == 1, realms @@ -183,7 +195,13 @@ def test_realms(admin: KeycloakAdmin): def test_import_export_realms(admin: KeycloakAdmin, realm: str): - """Test import and export of realms.""" + """Test import and export of realms. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm realm_export = admin.export_realm(export_clients=True, export_groups_and_role=True) @@ -201,7 +219,13 @@ def test_import_export_realms(admin: KeycloakAdmin, realm: str): def test_users(admin: KeycloakAdmin, realm: str): - """Test users.""" + """Test users. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm # Check no users present @@ -293,7 +317,13 @@ def test_users(admin: KeycloakAdmin, realm: str): def test_users_pagination(admin: KeycloakAdmin, realm: str): - """Test user pagination.""" + """Test user pagination. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm for ind in range(admin.PAGE_SIZE + 50): @@ -311,7 +341,13 @@ def test_users_pagination(admin: KeycloakAdmin, realm: str): def test_idps(admin: KeycloakAdmin, realm: str): - """Test IDPs.""" + """Test IDPs. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm # Create IDP @@ -383,7 +419,13 @@ def test_idps(admin: KeycloakAdmin, realm: str): def test_user_credentials(admin: KeycloakAdmin, user: str): - """Test user credentials.""" + """Test user credentials. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param user: Keycloak user + :type user: str + """ res = admin.set_user_password(user_id=user, password="booya", temporary=True) assert res == dict(), res @@ -411,7 +453,13 @@ def test_user_credentials(admin: KeycloakAdmin, user: str): def test_social_logins(admin: KeycloakAdmin, user: str): - """Test social logins.""" + """Test social logins. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param user: Keycloak user + :type user: str + """ res = admin.add_user_social_login( user_id=user, provider_id="gitlab", provider_userid="test", provider_username="test" ) @@ -451,7 +499,11 @@ def test_social_logins(admin: KeycloakAdmin, user: str): def test_server_info(admin: KeycloakAdmin): - """Test server info.""" + """Test server info. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + """ info = admin.get_server_info() assert set(info.keys()) == { "systemInfo", @@ -471,7 +523,13 @@ def test_server_info(admin: KeycloakAdmin): def test_groups(admin: KeycloakAdmin, user: str): - """Test groups.""" + """Test groups. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param user: Keycloak user + :type user: str + """ # Test get groups groups = admin.get_groups() assert len(groups) == 0 @@ -615,7 +673,13 @@ def test_groups(admin: KeycloakAdmin, user: str): def test_clients(admin: KeycloakAdmin, realm: str): - """Test clients.""" + """Test clients. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm # Test get clients @@ -875,7 +939,13 @@ def test_clients(admin: KeycloakAdmin, realm: str): def test_realm_roles(admin: KeycloakAdmin, realm: str): - """Test realm roles.""" + """Test realm roles. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm # Test get realm roles @@ -1031,7 +1101,13 @@ def test_realm_roles(admin: KeycloakAdmin, realm: str): def test_client_roles(admin: KeycloakAdmin, client: str): - """Test client roles.""" + """Test client roles. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param client: Keycloak client + :type client: str + """ # Test get client roles res = admin.get_client_roles(client_id=client) assert len(res) == 0 @@ -1194,7 +1270,14 @@ def test_client_roles(admin: KeycloakAdmin, client: str): def test_enable_token_exchange(admin: KeycloakAdmin, realm: str): - """Test enable token exchange.""" + """Test enable token exchange. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + :raises AssertionError: In case of bad configuration + """ # Test enabling token exchange between two confidential clients admin.realm_name = realm @@ -1283,7 +1366,13 @@ def test_enable_token_exchange(admin: KeycloakAdmin, realm: str): def test_email(admin: KeycloakAdmin, user: str): - """Test email.""" + """Test email. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param user: Keycloak user + :type user: str + """ # Emails will fail as we don't have SMTP test setup with pytest.raises(KeycloakPutError) as err: admin.send_update_account(user_id=user, payload=dict()) @@ -1296,7 +1385,11 @@ def test_email(admin: KeycloakAdmin, user: str): def test_get_sessions(admin: KeycloakAdmin): - """Test get sessions.""" + """Test get sessions. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + """ sessions = admin.get_sessions(user_id=admin.get_user_id(username=admin.username)) assert len(sessions) >= 1 with pytest.raises(KeycloakGetError) as err: @@ -1305,7 +1398,13 @@ def test_get_sessions(admin: KeycloakAdmin): def test_get_client_installation_provider(admin: KeycloakAdmin, client: str): - """Test get client installation provider.""" + """Test get client installation provider. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param client: Keycloak client + :type client: str + """ with pytest.raises(KeycloakGetError) as err: admin.get_client_installation_provider(client_id=client, provider_id="bad") assert err.match('404: b\'{"error":"Unknown Provider"}\'') @@ -1324,7 +1423,13 @@ def test_get_client_installation_provider(admin: KeycloakAdmin, client: str): def test_auth_flows(admin: KeycloakAdmin, realm: str): - """Test auth flows.""" + """Test auth flows. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm res = admin.get_authentication_flows() @@ -1471,7 +1576,13 @@ def test_auth_flows(admin: KeycloakAdmin, realm: str): def test_authentication_configs(admin: KeycloakAdmin, realm: str): - """Test authentication configs.""" + """Test authentication configs. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm # Test list of auth providers @@ -1503,7 +1614,13 @@ def test_authentication_configs(admin: KeycloakAdmin, realm: str): def test_sync_users(admin: KeycloakAdmin, realm: str): - """Test sync users.""" + """Test sync users. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm # Only testing the error message @@ -1513,7 +1630,13 @@ def test_sync_users(admin: KeycloakAdmin, realm: str): def test_client_scopes(admin: KeycloakAdmin, realm: str): - """Test client scopes.""" + """Test client scopes. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm # Test get client scopes @@ -1651,7 +1774,13 @@ def test_client_scopes(admin: KeycloakAdmin, realm: str): def test_components(admin: KeycloakAdmin, realm: str): - """Test components.""" + """Test components. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm # Test get components @@ -1702,7 +1831,13 @@ def test_components(admin: KeycloakAdmin, realm: str): def test_keys(admin: KeycloakAdmin, realm: str): - """Test keys.""" + """Test keys. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm assert set(admin.get_keys()["active"].keys()) == {"AES", "HS256", "RS256", "RSA-OAEP"} assert {k["algorithm"] for k in admin.get_keys()["keys"]} == { @@ -1714,7 +1849,13 @@ def test_keys(admin: KeycloakAdmin, realm: str): def test_events(admin: KeycloakAdmin, realm: str): - """Test events.""" + """Test events. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm events = admin.get_events() @@ -1734,7 +1875,13 @@ def test_events(admin: KeycloakAdmin, realm: str): def test_auto_refresh(admin: KeycloakAdmin, realm: str): - """Test auto refresh token.""" + """Test auto refresh token. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ # Test get refresh admin.auto_refresh_token = list() admin.connection = ConnectionManager( @@ -1818,7 +1965,13 @@ def test_auto_refresh(admin: KeycloakAdmin, realm: str): def test_get_required_actions(admin: KeycloakAdmin, realm: str): - """Test required actions.""" + """Test required actions. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm ractions = admin.get_required_actions() assert isinstance(ractions, list) @@ -1836,7 +1989,13 @@ def test_get_required_actions(admin: KeycloakAdmin, realm: str): def test_get_required_action_by_alias(admin: KeycloakAdmin, realm: str): - """Test get required action by alias.""" + """Test get required action by alias. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm ractions = admin.get_required_actions() ra = admin.get_required_action_by_alias("UPDATE_PASSWORD") @@ -1846,7 +2005,13 @@ def test_get_required_action_by_alias(admin: KeycloakAdmin, realm: str): def test_update_required_action(admin: KeycloakAdmin, realm: str): - """Test update required action.""" + """Test update required action. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + """ admin.realm_name = realm ra = admin.get_required_action_by_alias("UPDATE_PASSWORD") old = copy.deepcopy(ra) @@ -1860,7 +2025,19 @@ def test_update_required_action(admin: KeycloakAdmin, realm: str): def test_get_composite_client_roles_of_group( admin: KeycloakAdmin, realm: str, client: str, group: str, composite_client_role: str ): - """Test get composite client roles of group.""" + """Test get composite client roles of group. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + :param client: Keycloak client + :type client: str + :param group: Keycloak group + :type group: str + :param composite_client_role: Composite client role + :type composite_client_role: str + """ admin.realm_name = realm role = admin.get_client_role(client, composite_client_role) admin.assign_group_client_roles(group_id=group, client_id=client, roles=[role]) @@ -1871,7 +2048,19 @@ def test_get_composite_client_roles_of_group( def test_get_role_client_level_children( admin: KeycloakAdmin, realm: str, client: str, composite_client_role: str, client_role: str ): - """Test get children of composite client role.""" + """Test get children of composite client role. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + :param client: Keycloak client + :type client: str + :param composite_client_role: Composite client role + :type composite_client_role: str + :param client_role: Client role + :type client_role: str + """ admin.realm_name = realm child = admin.get_client_role(client, client_role) parent = admin.get_client_role(client, composite_client_role) @@ -1880,7 +2069,17 @@ def test_get_role_client_level_children( def test_upload_certificate(admin: KeycloakAdmin, realm: str, client: str, selfsigned_cert: tuple): - """Test upload certificate.""" + """Test upload certificate. + + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + :param realm: Keycloak realm + :type realm: str + :param client: Keycloak client + :type client: str + :param selfsigned_cert: Selfsigned certificates + :type selfsigned_cert: tuple + """ admin.realm_name = realm cert, _ = selfsigned_cert cert = cert.decode("utf-8").strip() diff --git a/tests/test_keycloak_openid.py b/tests/test_keycloak_openid.py index 6bee648..5a6a2ed 100644 --- a/tests/test_keycloak_openid.py +++ b/tests/test_keycloak_openid.py @@ -22,7 +22,11 @@ from keycloak.keycloak_openid import KeycloakOpenID def test_keycloak_openid_init(env): - """Test KeycloakOpenId's init method.""" + """Test KeycloakOpenId's init method. + + :param env: Environment fixture + :type env: KeycloakTestEnv + """ oid = KeycloakOpenID( server_url=f"http://{env.KEYCLOAK_HOST}:{env.KEYCLOAK_PORT}", realm_name="master", @@ -37,7 +41,11 @@ def test_keycloak_openid_init(env): def test_well_known(oid: KeycloakOpenID): - """Test the well_known method.""" + """Test the well_known method. + + :param oid: Keycloak OpenID client + :type oid: KeycloakOpenID + """ res = oid.well_known() assert res is not None assert res != dict() @@ -100,7 +108,13 @@ def test_well_known(oid: KeycloakOpenID): def test_auth_url(env, oid: KeycloakOpenID): - """Test the auth_url method.""" + """Test the auth_url method. + + :param env: Environment fixture + :type env: KeycloakTestEnv + :param oid: Keycloak OpenID client + :type oid: KeycloakOpenID + """ res = oid.auth_url(redirect_uri="http://test.test/*") assert ( res @@ -111,7 +125,11 @@ def test_auth_url(env, oid: KeycloakOpenID): def test_token(oid_with_credentials: Tuple[KeycloakOpenID, str, str]): - """Test the token method.""" + """Test the token method. + + :param oid_with_credentials: Keycloak OpenID client with pre-configured user credentials + :type oid_with_credentials: Tuple[KeycloakOpenID, str, str] + """ oid, username, password = oid_with_credentials token = oid.token(username=username, password=password) assert token == { @@ -155,7 +173,13 @@ def test_token(oid_with_credentials: Tuple[KeycloakOpenID, str, str]): def test_exchange_token( oid_with_credentials: Tuple[KeycloakOpenID, str, str], admin: KeycloakAdmin ): - """Test the exchange token method.""" + """Test the exchange token method. + + :param oid_with_credentials: Keycloak OpenID client with pre-configured user credentials + :type oid_with_credentials: Tuple[KeycloakOpenID, str, str] + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + """ # Verify existing user oid, username, password = oid_with_credentials @@ -197,7 +221,11 @@ def test_exchange_token( def test_logout(oid_with_credentials): - """Test logout.""" + """Test logout. + + :param oid_with_credentials: Keycloak OpenID client with pre-configured user credentials + :type oid_with_credentials: Tuple[KeycloakOpenID, str, str] + """ oid, username, password = oid_with_credentials token = oid.token(username=username, password=password) @@ -209,19 +237,34 @@ def test_logout(oid_with_credentials): def test_certs(oid: KeycloakOpenID): - """Test certificates.""" + """Test certificates. + + :param oid: Keycloak OpenID client + :type oid: KeycloakOpenID + """ assert len(oid.certs()["keys"]) == 2 def test_public_key(oid: KeycloakOpenID): - """Test public key.""" + """Test public key. + + :param oid: Keycloak OpenID client + :type oid: KeycloakOpenID + """ assert oid.public_key() is not None def test_entitlement( oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str], admin: KeycloakAdmin ): - """Test entitlement.""" + """Test entitlement. + + :param oid_with_credentials_authz: Keycloak OpenID client configured as an authorization + server with client credentials + :type oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str] + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + """ oid, username, password = oid_with_credentials_authz token = oid.token(username=username, password=password) resource_server_id = admin.get_client_authz_resources( @@ -233,7 +276,11 @@ def test_entitlement( def test_introspect(oid_with_credentials: Tuple[KeycloakOpenID, str, str]): - """Test introspect.""" + """Test introspect. + + :param oid_with_credentials: Keycloak OpenID client with pre-configured user credentials + :type oid_with_credentials: Tuple[KeycloakOpenID, str, str] + """ oid, username, password = oid_with_credentials token = oid.token(username=username, password=password) @@ -247,7 +294,11 @@ def test_introspect(oid_with_credentials: Tuple[KeycloakOpenID, str, str]): def test_decode_token(oid_with_credentials: Tuple[KeycloakOpenID, str, str]): - """Test decode token.""" + """Test decode token. + + :param oid_with_credentials: Keycloak OpenID client with pre-configured user credentials + :type oid_with_credentials: Tuple[KeycloakOpenID, str, str] + """ oid, username, password = oid_with_credentials token = oid.token(username=username, password=password) @@ -262,7 +313,12 @@ def test_decode_token(oid_with_credentials: Tuple[KeycloakOpenID, str, str]): def test_load_authorization_config(oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str]): - """Test load authorization config.""" + """Test load authorization config. + + :param oid_with_credentials_authz: Keycloak OpenID client configured as an authorization + server with client credentials + :type oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str] + """ oid, username, password = oid_with_credentials_authz oid.load_authorization_config(path="tests/data/authz_settings.json") @@ -277,7 +333,12 @@ def test_load_authorization_config(oid_with_credentials_authz: Tuple[KeycloakOpe def test_get_policies(oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str]): - """Test get policies.""" + """Test get policies. + + :param oid_with_credentials_authz: Keycloak OpenID client configured as an authorization + server with client credentials + :type oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str] + """ oid, username, password = oid_with_credentials_authz token = oid.token(username=username, password=password) @@ -310,7 +371,12 @@ def test_get_policies(oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str def test_get_permissions(oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str]): - """Test get policies.""" + """Test get policies. + + :param oid_with_credentials_authz: Keycloak OpenID client configured as an authorization + server with client credentials + :type oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str] + """ oid, username, password = oid_with_credentials_authz token = oid.token(username=username, password=password) @@ -354,7 +420,12 @@ def test_get_permissions(oid_with_credentials_authz: Tuple[KeycloakOpenID, str, def test_uma_permissions(oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str]): - """Test UMA permissions.""" + """Test UMA permissions. + + :param oid_with_credentials_authz: Keycloak OpenID client configured as an authorization + server with client credentials + :type oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str] + """ oid, username, password = oid_with_credentials_authz token = oid.token(username=username, password=password) @@ -365,7 +436,14 @@ def test_uma_permissions(oid_with_credentials_authz: Tuple[KeycloakOpenID, str, def test_has_uma_access( oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str], admin: KeycloakAdmin ): - """Test has UMA access.""" + """Test has UMA access. + + :param oid_with_credentials_authz: Keycloak OpenID client configured as an authorization + server with client credentials + :type oid_with_credentials_authz: Tuple[KeycloakOpenID, str, str] + :param admin: Keycloak Admin client + :type admin: KeycloakAdmin + """ oid, username, password = oid_with_credentials_authz token = oid.token(username=username, password=password)