Skip to content

Commit 7a92e8f

Browse files
committed
add oidc tests for jwt bearer token
1 parent d925094 commit 7a92e8f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/rest/test_connection.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,36 @@ def test_authenticate_oidc_auth_code_pkce_flow_client_from_config(requests_mock,
10611061
assert conn.auth.bearer == 'oidc/oi/' + oidc_mock.state["access_token"]
10621062
assert refresh_token_store.mock_calls == []
10631063

1064+
@pytest.mark.slow
1065+
def test_authenticate_oidc_auth_code_pkce_flow_jwt_bearer(requests_mock, auth_config):
1066+
requests_mock.get(API_URL, json=build_capabilities(api_version="1.3.0"))
1067+
client_id = "myclient"
1068+
issuer = "https://oidc.test"
1069+
requests_mock.get(API_URL + 'credentials/oidc', json={
1070+
"providers": [{"id": "oi", "issuer": issuer, "title": "example", "scopes": ["openid"]}]
1071+
})
1072+
oidc_mock = OidcMock(
1073+
requests_mock=requests_mock,
1074+
expected_grant_type="authorization_code",
1075+
expected_client_id=client_id,
1076+
expected_fields={"scope": "openid"},
1077+
oidc_issuer=issuer,
1078+
scopes_supported=["openid"],
1079+
)
1080+
auth_config.set_oidc_client_config(backend=API_URL, provider_id="oi", client_id=client_id)
1081+
1082+
# With all this set up, kick off the openid connect flow
1083+
refresh_token_store = mock.Mock()
1084+
conn = Connection(API_URL, refresh_token_store=refresh_token_store)
1085+
assert isinstance(conn.auth, NullAuth)
1086+
conn.authenticate_oidc_authorization_code(webbrowser_open=oidc_mock.webbrowser_open)
1087+
capabilities = conn.capabilities()
1088+
assert isinstance(conn.auth, BearerAuth)
1089+
assert capabilities.api_version() == "1.3.0"
1090+
assert capabilities.has_conformance("https://api.openeo.org/*/authentication/jwt") == True
1091+
assert conn.auth.bearer == oidc_mock.state["access_token"]
1092+
# TODO: check issuer ("iss") value in parsed jwt. this will require the example jwt to be formatted accordingly
1093+
assert refresh_token_store.mock_calls == []
10641094

10651095
def test_authenticate_oidc_client_credentials(requests_mock):
10661096
requests_mock.get(API_URL, json={"api_version": "1.0.0"})

0 commit comments

Comments
 (0)