-
Notifications
You must be signed in to change notification settings - Fork 46
Implement list_auth_providers #826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -767,6 +767,67 @@ def test_create_connection_lazy_refresh_token_store(requests_mock): | |
| ) | ||
|
|
||
|
|
||
| def test_list_auth_providers(requests_mock, api_version): | ||
| requests_mock.get(API_URL, json=build_capabilities(api_version=api_version)) | ||
| requests_mock.get( | ||
| API_URL + "credentials/oidc", | ||
| json={ | ||
| "providers": [ | ||
| {"id": "p1", "issuer": "https://openeo.example", "title": "openEO", "scopes": ["openid"]}, | ||
| {"id": "p2", "issuer": "https://other.example", "title": "Other", "scopes": ["openid"]}, | ||
| ] | ||
| }, | ||
| ) | ||
|
|
||
| conn = Connection(API_URL) | ||
| providers = conn.list_auth_providers() | ||
| assert len(providers) == 3 | ||
|
|
||
| p1 = next(filter(lambda x: x["id"] == "p1", providers), None) | ||
| assert isinstance(p1, dict) | ||
| assert p1["type"] == "oidc" | ||
| assert p1["issuer"] == "https://openeo.example" | ||
| assert p1["title"] == "openEO" | ||
|
|
||
| p2 = next(filter(lambda x: x["id"] == "p2", providers), None) | ||
| assert isinstance(p2, dict) | ||
| assert p2["type"] == "oidc" | ||
| assert p2["issuer"] == "https://other.example" | ||
| assert p2["title"] == "Other" | ||
|
|
||
| basic = next(filter(lambda x: x["id"] == "/credentials/basic", providers), None) | ||
| assert isinstance(basic, dict) | ||
| assert basic["type"] == "basic" | ||
| assert basic["issuer"] == API_URL + "credentials/basic" | ||
| assert basic["title"] == "Internal" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of using separate asserts, one for each fields, I prefer a single assert that checks the response as a whole, which is perfectly doable here, e.g. assert providers == [
{
"type": "oidc",
"issuer": ...
"title": ...
},
{
...
]The advantage of this is that you can easily see and understand the expected output.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure whether this might lead to problems when the (stub) API (for whatever reason) would change the order of the array?! |
||
|
|
||
|
|
||
| def test_list_auth_providers_empty(requests_mock, api_version): | ||
| requests_mock.get( | ||
| API_URL, | ||
| json=build_capabilities(api_version=api_version, basic_auth=False, oidc_auth=False), | ||
| ) | ||
|
|
||
| conn = Connection(API_URL) | ||
| providers = conn.list_auth_providers() | ||
| assert len(providers) == 0 | ||
|
|
||
|
|
||
| def test_list_auth_providers_invalid(requests_mock, api_version, caplog): | ||
| requests_mock.get(API_URL, json=build_capabilities(api_version=api_version, basic_auth=False)) | ||
| error_message = "Maintenance ongoing" | ||
| requests_mock.get( | ||
| API_URL + "credentials/oidc", | ||
| status_code=500, | ||
| json={"code": "Internal", "message": error_message}, | ||
| ) | ||
|
|
||
| conn = Connection(API_URL) | ||
| providers = conn.list_auth_providers() | ||
| assert len(providers) == 0 | ||
| assert f"Unable to load the OpenID Connect provider list: {error_message}" in caplog.messages | ||
|
|
||
|
|
||
| def test_authenticate_basic_no_support(requests_mock, api_version): | ||
| requests_mock.get(API_URL, json={"api_version": api_version, "endpoints": []}) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.