Skip to content

Commit 648637a

Browse files
committed
create code_verifier tests
1 parent eaad344 commit 648637a

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

tests/pyop/test_provider.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
from oic import rndstr
1313
from oic.oauth2.message import MissingRequiredValue, MissingRequiredAttribute
1414
from oic.oic import PREFERENCE2PROVIDER
15-
from oic.oic.message import IdToken, AuthorizationRequest, ClaimsRequest, Claims, EndSessionRequest, EndSessionResponse
15+
from oic.oic.message import IdToken, ClaimsRequest, Claims, EndSessionRequest, EndSessionResponse
1616

17+
from pyop.message import AuthorizationRequest
1718
from pyop.access_token import BearerTokenError
1819
from pyop.authz_state import AuthorizationState
1920
from pyop.client_authentication import InvalidClientAuthentication
@@ -319,6 +320,19 @@ def test_code_exchange_request(self):
319320
self.authn_request_args)
320321

321322
@patch('time.time', MOCK_TIME)
323+
def test_pkce_code_exchange_request(self):
324+
self.authorization_code_exchange_request_args['code'] = self.create_authz_code(
325+
{
326+
"code_challenge": "_1f8tFjAtu6D1Df-GOyDPoMjCJdEvaSWsnqR6SLpzsw",
327+
"code_challenge_method": "S256"
328+
}
329+
)
330+
self.authorization_code_exchange_request_args['code_verifier'] = "SoOEDN-mZKNhw7Mc52VXxyiqTvFB3mod36MwPru253c"
331+
response = self.provider._do_code_exchange(self.authorization_code_exchange_request_args, None)
332+
assert response['access_token'] in self.provider.authz_state.access_tokens
333+
assert_id_token_base_claims(response['id_token'], self.provider.signing_key, self.provider,
334+
self.authn_request_args)
335+
@patch('time.time', MOCK_TIME)
322336
def test_code_exchange_request_with_claims_requested_in_id_token(self):
323337
claims_req = {'claims': ClaimsRequest(id_token=Claims(email=None))}
324338
self.authorization_code_exchange_request_args['code'] = self.create_authz_code(extra_auth_req_params=claims_req)
@@ -374,6 +388,12 @@ def test_handle_token_request_reject_missing_grant_type(self):
374388
with pytest.raises(InvalidTokenRequest):
375389
self.provider.handle_token_request(urlencode(self.authorization_code_exchange_request_args))
376390

391+
def test_handle_token_request_reject_invalid_code_verifier(self):
392+
del self.authorization_code_exchange_request_args['grant_type']
393+
self.authorization_code_exchange_request_args['code'] = self.create_authz_code()
394+
with pytest.raises(InvalidTokenRequest):
395+
self.provider.handle_token_request(urlencode(self.authorization_code_exchange_request_args))
396+
377397
def test_refresh_request(self):
378398
self.provider.authz_state = AuthorizationState(HashBasedSubjectIdentifierFactory('salt'),
379399
refresh_token_lifetime=600)

0 commit comments

Comments
 (0)