Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

fix: Clean providers list when oauth config is disabled #13

Merged
merged 5 commits into from
Feb 5, 2024
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
5 changes: 3 additions & 2 deletions src/argilla_server/apis/v1/handlers/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@

@router.get("/providers", response_model=Providers)
def list_providers(_request: Request) -> Providers:
items = [Provider(name=provider_name) for provider_name in settings.oauth.providers]
if not settings.oauth.enabled:
return Providers(items=[])

return Providers(items=items)
return Providers(items=[Provider(name=provider_name) for provider_name in settings.oauth.providers])


@router.get("/providers/{provider}/authentication")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def __init__(
self.enabled = enabled
self.allow_http_redirect = allow_http_redirect
self.allowed_workspaces = allowed_workspaces or []

self._providers = providers or []

if self.allow_http_redirect:
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/api/v1/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ async def test_list_providers_with_oauth_disabled(
assert response.status_code == 200
assert response.json() == {"items": []}

async def test_list_provider_with_oauth_disabled_from_settings(
self, async_client: AsyncClient, owner_auth_header: dict, default_oauth_settings: OAuth2Settings
):
default_oauth_settings.enabled = False
with mock.patch("argilla_server.security.settings.Settings.oauth", new_callable=lambda: default_oauth_settings):
response = await async_client.get("/api/v1/oauth2/providers", headers=owner_auth_header)
assert response.status_code == 200
assert response.json() == {"items": []}

async def test_list_providers(
self, async_client: AsyncClient, owner_auth_header: dict, default_oauth_settings: OAuth2Settings
):
Expand Down Expand Up @@ -103,6 +112,19 @@ async def test_provider_authentication_with_oauth_disabled(
)
assert response.status_code == 404

async def test_provider_authentication_with_oauth_disabled_and_provider_defined(
self,
async_client: AsyncClient,
owner_auth_header: dict,
default_oauth_settings: OAuth2Settings,
):
default_oauth_settings.enabled = False
with mock.patch("argilla_server.security.settings.Settings.oauth", new_callable=lambda: default_oauth_settings):
response = await async_client.get(
"/api/v1/oauth2/providers/huggingface/authentication", headers=owner_auth_header
)
assert response.status_code == 404

async def test_provider_authentication_with_invalid_provider(
self, async_client: AsyncClient, owner_auth_header: dict, default_oauth_settings: OAuth2Settings
):
Expand Down
Loading