@@ -40,6 +40,55 @@ def request(self, host, path, request, verbose=False):
4040 return []
4141
4242
43+ def test_login_token_oidc (requests_session ):
44+ """Login with OIDC client credentials flow."""
45+
46+ hub_url = "https://example.com/myapp/endpoint"
47+ login_url = "https://example.com/myapp/auth/tokenoidclogin/"
48+ token_url = "https://sso.example.com/protocol/openid-connect/token"
49+
50+ conf = PyConfigParser ()
51+ conf .load_from_dict (
52+ {
53+ "HUB_URL" : hub_url ,
54+ "AUTH_METHOD" : "token_oidc" ,
55+ "OIDC_CLIENT_ID" : "test-client" ,
56+ "OIDC_CLIENT_SECRET" : "secret-token" ,
57+ "OIDC_AUTH_SERVER_TOKEN_URL" : token_url ,
58+ "CA_CERT" : "/path/to/ca-bundle.crt"
59+ }
60+ )
61+
62+ transport = FakeTransport ()
63+ proxy = HubProxy (conf , transport = transport )
64+
65+ with mock .patch ("requests.post" ) as mock_post :
66+ mock_post .return_value .json .return_value = {"access_token" : "secret-token" }
67+
68+ # Force a login
69+ proxy ._login (force = True )
70+
71+ mock_post .assert_called_once_with (
72+ "https://sso.example.com/protocol/openid-connect/token" ,
73+ data = {
74+ "grant_type" : "client_credentials" ,
75+ "client_id" : "test-client" ,
76+ "client_secret" : "secret-token" ,
77+ "scope" : "openid"
78+ },
79+ timeout = 30
80+ )
81+
82+ # Cookies should have been shared between session and transport
83+ assert requests_session .return_value .cookies is transport .cookiejar
84+
85+ requests_session .return_value .get .assert_called_once_with (
86+ "https://example.com/myapp/auth/tokenoidclogin/" ,
87+ headers = {"Authorization" : "Bearer secret-token" },
88+ verify = "/path/to/ca-bundle.crt"
89+ )
90+
91+
4392def test_login_gssapi (requests_session ):
4493 """Login with gssapi method obtains session cookie via SPNEGO & krb5login."""
4594
0 commit comments