Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ansys/hps/client/auth/api/auth_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ def __init__(self, client: Client):
@property
def url(self) -> str:
"""API URL."""
return f"{self.client.url}/auth"
return f"{self.client.auth_api_url}".rstrip("/")

@property
def realm_url(self) -> str:
"""Realm URL."""
return f"{self.url}/admin/realms/{self.client.realm}"
return f"{self.client.auth_url}".replace("/auth/realms", "/auth/admin/realms")

def get_users(self, as_objects=True, **query_params) -> list[User]:
"""Get users, filtered according to query parameters.
Expand Down
23 changes: 23 additions & 0 deletions tests/auth/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import logging
import uuid
from unittest.mock import MagicMock

import pytest
from keycloak import KeycloakOpenID
Expand Down Expand Up @@ -184,3 +185,25 @@ def test_impersonate_user(url, keycloak_client):
assert token_info["preferred_username"] == new_user.username

delete_user(keycloak_client, new_user)


def test_auth_api_url(client):
"""Test that the auth_api_url property returns the
correct URL for the default instance of JMS."""
api = AuthApi(client)
auth_api_url = client.auth_api_url.rstrip("/")
assert api.realm_url == f"{auth_api_url}/admin/realms/{client.realm}"
assert api.url == auth_api_url


def test_customized_auth_api_url(client):
"""Test that the auth_api_url property returns the correct URL for custom entries."""
# Mock the client object so we can easily force a specific URL that's not the default
mock_client = MagicMock()
mock_client.auth_url = "https://example.com/dev/hps/auth/realms/myrealm"

# Create an instance of AuthApi with the mocked client
auth_api = AuthApi(client=mock_client)

# Assert the expected transformation
assert auth_api.realm_url == "https://example.com/dev/hps/auth/admin/realms/myrealm"
Loading