44
55from cryptojwt .jwk .rsa import import_private_rsa_key_from_file
66from cryptojwt .key_bundle import KeyBundle
7+ from oidcmsg .configure import create_from_config_file
78from oidcmsg .oauth2 import AccessTokenRequest
89from oidcmsg .oauth2 import AccessTokenResponse
910from oidcmsg .oauth2 import AuthorizationRequest
1415from oidcmsg .time_util import utc_time_sans_frac
1516import pytest
1617
18+ from oidcrp .configure import RPConfiguration
1719from oidcrp .exception import OidcServiceError
1820from oidcrp .exception import ParseError
1921from oidcrp .oauth2 import Client
@@ -60,7 +62,7 @@ def test_construct_authorization_request(self):
6062 }
6163
6264 self .client .client_get ("service_context" ).state .create_state ('issuer' , key = 'ABCDE' )
63- msg = self .client .client_get ("service" ,'authorization' ).construct (request_args = req_args )
65+ msg = self .client .client_get ("service" , 'authorization' ).construct (request_args = req_args )
6466 assert isinstance (msg , AuthorizationRequest )
6567 assert msg ['client_id' ] == 'client_1'
6668 assert msg ['redirect_uri' ] == 'https://example.com/auth_cb'
@@ -81,9 +83,9 @@ def test_construct_accesstoken_request(self):
8183 auth_response = AuthorizationResponse (code = 'access_code' )
8284
8385 self .client .client_get ("service_context" ).state .store_item (auth_response ,
84- 'auth_response' , 'ABCDE' )
86+ 'auth_response' , 'ABCDE' )
8587
86- msg = self .client .client_get ("service" ,'accesstoken' ).construct (
88+ msg = self .client .client_get ("service" , 'accesstoken' ).construct (
8789 request_args = req_args , state = 'ABCDE' )
8890
8991 assert isinstance (msg , AccessTokenRequest )
@@ -105,19 +107,19 @@ def test_construct_refresh_token_request(self):
105107 state = 'state'
106108 )
107109
108- _context .state .store_item (auth_request , 'auth_request' ,'ABCDE' )
110+ _context .state .store_item (auth_request , 'auth_request' , 'ABCDE' )
109111
110112 auth_response = AuthorizationResponse (code = 'access_code' )
111113
112- _context .state .store_item (auth_response ,'auth_response' , 'ABCDE' )
114+ _context .state .store_item (auth_response , 'auth_response' , 'ABCDE' )
113115
114116 token_response = AccessTokenResponse (refresh_token = "refresh_with_me" ,
115117 access_token = "access" )
116118
117119 _context .state .store_item (token_response , 'token_response' , 'ABCDE' )
118120
119121 req_args = {}
120- msg = self .client .client_get ("service" ,'refresh_token' ).construct (
122+ msg = self .client .client_get ("service" , 'refresh_token' ).construct (
121123 request_args = req_args , state = 'ABCDE' )
122124 assert isinstance (msg , RefreshAccessTokenRequest )
123125 assert msg .to_dict () == {
@@ -131,7 +133,7 @@ def test_error_response(self):
131133 err = ResponseMessage (error = 'Illegal' )
132134 http_resp = MockResponse (400 , err .to_urlencoded ())
133135 resp = self .client .parse_request_response (
134- self .client .client_get ("service" ,'authorization' ), http_resp )
136+ self .client .client_get ("service" , 'authorization' ), http_resp )
135137
136138 assert resp ['error' ] == 'Illegal'
137139 assert resp ['status_code' ] == 400
@@ -141,7 +143,7 @@ def test_error_response_500(self):
141143 http_resp = MockResponse (500 , err .to_urlencoded ())
142144 with pytest .raises (ParseError ):
143145 self .client .parse_request_response (
144- self .client .client_get ("service" ,'authorization' ), http_resp )
146+ self .client .client_get ("service" , 'authorization' ), http_resp )
145147
146148 def test_error_response_2 (self ):
147149 err = ResponseMessage (error = 'Illegal' )
@@ -151,4 +153,42 @@ def test_error_response_2(self):
151153
152154 with pytest .raises (OidcServiceError ):
153155 self .client .parse_request_response (
154- self .client .client_get ("service" ,'authorization' ), http_resp )
156+ self .client .client_get ("service" , 'authorization' ), http_resp )
157+
158+
159+ class TestClient2 (object ):
160+ @pytest .fixture (autouse = True )
161+ def create_client (self ):
162+ self .redirect_uri = "http://example.com/redirect"
163+ KEYSPEC = [
164+ {"type" : "RSA" , "use" : ["sig" ]},
165+ {"type" : "EC" , "crv" : "P-256" , "use" : ["sig" ]},
166+ ]
167+
168+ conf = {
169+ 'redirect_uris' : ['https://example.com/cli/authz_cb' ],
170+ 'client_id' : 'client_1' ,
171+ 'client_secret' : 'abcdefghijklmnop' ,
172+ 'rp_keys' : {
173+ 'private_path' : 'private/jwks.json' ,
174+ 'key_defs' : KEYSPEC ,
175+ 'public_path' : 'static/jwks.json' ,
176+ # this will create the jwks files if they are absent
177+ 'read_only' : False
178+ }
179+ }
180+ rp_conf = RPConfiguration (conf )
181+ self .client = Client (config = rp_conf )
182+ assert self .client
183+
184+ def test_keyjar (self ):
185+ req_args = {
186+ 'state' : 'ABCDE' ,
187+ 'redirect_uri' : 'https://example.com/auth_cb' ,
188+ 'response_type' : ['code' ]
189+ }
190+
191+ _context = self .client .client_get ("service_context" )
192+ assert len (_context .keyjar ) == 1 # one issuer
193+ assert len (_context .keyjar ["" ]) == 2
194+ assert len (_context .keyjar .get ("sig" )) == 2
0 commit comments