@@ -80,9 +80,7 @@ def userinfo(self):
80
80
def signing_key (self ):
81
81
return RSAKey (key = RSA .generate (2048 ), alg = "RS256" )
82
82
83
- def assert_expected_attributes (self , actual_attributes ):
84
- user_claims = self .userinfo ()
85
- attr_map = self .internal_attributes ()
83
+ def assert_expected_attributes (self , attr_map , user_claims , actual_attributes ):
86
84
expected_attributes = {}
87
85
for out_attr , in_mapping in attr_map ["attributes" ].items ():
88
86
expected_attributes [out_attr ] = [user_claims [in_mapping ["openid" ][0 ]]]
@@ -97,10 +95,10 @@ def setup_jwks_uri(self, jwks_uri, key):
97
95
status = 200 ,
98
96
content_type = "application/json" )
99
97
100
- def setup_token_endpoint (self , token_endpoint_url , signing_key ):
98
+ def setup_token_endpoint (self , token_endpoint_url , userinfo , signing_key ):
101
99
id_token_claims = {
102
100
"iss" : ISSUER ,
103
- "sub" : self . userinfo () ["sub" ],
101
+ "sub" : userinfo ["sub" ],
104
102
"aud" : CLIENT_ID ,
105
103
"nonce" : NONCE ,
106
104
"exp" : time .time () + 3600 ,
@@ -120,10 +118,10 @@ def setup_token_endpoint(self, token_endpoint_url, signing_key):
120
118
status = 200 ,
121
119
content_type = "application/json" )
122
120
123
- def setup_userinfo_endpoint (self , userinfo_endpoint_url ):
121
+ def setup_userinfo_endpoint (self , userinfo_endpoint_url , userinfo ):
124
122
responses .add (responses .POST ,
125
123
userinfo_endpoint_url ,
126
- body = json .dumps (self . userinfo () ),
124
+ body = json .dumps (userinfo ),
127
125
status = 200 ,
128
126
content_type = "application/json" )
129
127
@@ -153,24 +151,24 @@ def test_register_endpoints(self, backend_config):
153
151
assert re .search (regex , redirect_uri_path )
154
152
assert callback == self .oidc_backend .response_endpoint
155
153
156
- def test_translate_response_to_internal_response (self , userinfo ):
154
+ def test_translate_response_to_internal_response (self , internal_attributes , userinfo ):
157
155
internal_response = self .oidc_backend ._translate_response (userinfo , ISSUER )
158
156
assert internal_response .subject_id == userinfo ["sub" ]
159
- self .assert_expected_attributes (internal_response .attributes )
157
+ self .assert_expected_attributes (internal_attributes , userinfo , internal_response .attributes )
160
158
161
159
@responses .activate
162
- def test_response_endpoint (self , backend_config , signing_key , incoming_authn_response ):
160
+ def test_response_endpoint (self , backend_config , internal_attributes , userinfo , signing_key , incoming_authn_response ):
163
161
self .setup_jwks_uri (backend_config ["provider_metadata" ]["jwks_uri" ], signing_key )
164
- self .setup_token_endpoint (backend_config ["provider_metadata" ]["token_endpoint" ], signing_key )
165
- self .setup_userinfo_endpoint (backend_config ["provider_metadata" ]["userinfo_endpoint" ])
162
+ self .setup_token_endpoint (backend_config ["provider_metadata" ]["token_endpoint" ], userinfo , signing_key )
163
+ self .setup_userinfo_endpoint (backend_config ["provider_metadata" ]["userinfo_endpoint" ], userinfo )
166
164
167
165
self .oidc_backend .response_endpoint (incoming_authn_response )
168
166
assert self .oidc_backend .name not in incoming_authn_response .state
169
167
170
168
args = self .oidc_backend .auth_callback_func .call_args [0 ]
171
169
assert isinstance (args [0 ], Context )
172
170
assert isinstance (args [1 ], InternalData )
173
- self .assert_expected_attributes (args [1 ].attributes )
171
+ self .assert_expected_attributes (internal_attributes , userinfo , args [1 ].attributes )
174
172
175
173
def test_start_auth_redirects_to_provider_authorization_endpoint (self , context , backend_config ):
176
174
auth_response = self .oidc_backend .start_auth (context , None )
@@ -188,8 +186,8 @@ def test_start_auth_redirects_to_provider_authorization_endpoint(self, context,
188
186
assert "nonce" in auth_params
189
187
190
188
@responses .activate
191
- def test_entire_flow (self , context , backend_config ):
192
- self .setup_userinfo_endpoint (backend_config ["provider_metadata" ]["userinfo_endpoint" ])
189
+ def test_entire_flow (self , context , backend_config , internal_attributes , userinfo ):
190
+ self .setup_userinfo_endpoint (backend_config ["provider_metadata" ]["userinfo_endpoint" ], userinfo )
193
191
auth_response = self .oidc_backend .start_auth (context , None )
194
192
auth_params = dict (parse_qsl (urlparse (auth_response .message ).query ))
195
193
@@ -198,7 +196,7 @@ def test_entire_flow(self, context, backend_config):
198
196
self .oidc_backend .response_endpoint (context )
199
197
assert self .oidc_backend .name not in context .state
200
198
args = self .oidc_backend .auth_callback_func .call_args [0 ]
201
- self .assert_expected_attributes (args [1 ].attributes )
199
+ self .assert_expected_attributes (internal_attributes , userinfo , args [1 ].attributes )
202
200
203
201
204
202
class TestCreateClient (object ):
0 commit comments