4
4
5
5
from cryptojwt .jwk .rsa import import_private_rsa_key_from_file
6
6
from cryptojwt .key_bundle import KeyBundle
7
+ from oidcmsg .configure import create_from_config_file
7
8
from oidcmsg .oauth2 import AccessTokenRequest
8
9
from oidcmsg .oauth2 import AccessTokenResponse
9
10
from oidcmsg .oauth2 import AuthorizationRequest
14
15
from oidcmsg .time_util import utc_time_sans_frac
15
16
import pytest
16
17
18
+ from oidcrp .configure import RPConfiguration
17
19
from oidcrp .exception import OidcServiceError
18
20
from oidcrp .exception import ParseError
19
21
from oidcrp .oauth2 import Client
@@ -60,7 +62,7 @@ def test_construct_authorization_request(self):
60
62
}
61
63
62
64
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 )
64
66
assert isinstance (msg , AuthorizationRequest )
65
67
assert msg ['client_id' ] == 'client_1'
66
68
assert msg ['redirect_uri' ] == 'https://example.com/auth_cb'
@@ -81,9 +83,9 @@ def test_construct_accesstoken_request(self):
81
83
auth_response = AuthorizationResponse (code = 'access_code' )
82
84
83
85
self .client .client_get ("service_context" ).state .store_item (auth_response ,
84
- 'auth_response' , 'ABCDE' )
86
+ 'auth_response' , 'ABCDE' )
85
87
86
- msg = self .client .client_get ("service" ,'accesstoken' ).construct (
88
+ msg = self .client .client_get ("service" , 'accesstoken' ).construct (
87
89
request_args = req_args , state = 'ABCDE' )
88
90
89
91
assert isinstance (msg , AccessTokenRequest )
@@ -105,19 +107,19 @@ def test_construct_refresh_token_request(self):
105
107
state = 'state'
106
108
)
107
109
108
- _context .state .store_item (auth_request , 'auth_request' ,'ABCDE' )
110
+ _context .state .store_item (auth_request , 'auth_request' , 'ABCDE' )
109
111
110
112
auth_response = AuthorizationResponse (code = 'access_code' )
111
113
112
- _context .state .store_item (auth_response ,'auth_response' , 'ABCDE' )
114
+ _context .state .store_item (auth_response , 'auth_response' , 'ABCDE' )
113
115
114
116
token_response = AccessTokenResponse (refresh_token = "refresh_with_me" ,
115
117
access_token = "access" )
116
118
117
119
_context .state .store_item (token_response , 'token_response' , 'ABCDE' )
118
120
119
121
req_args = {}
120
- msg = self .client .client_get ("service" ,'refresh_token' ).construct (
122
+ msg = self .client .client_get ("service" , 'refresh_token' ).construct (
121
123
request_args = req_args , state = 'ABCDE' )
122
124
assert isinstance (msg , RefreshAccessTokenRequest )
123
125
assert msg .to_dict () == {
@@ -131,7 +133,7 @@ def test_error_response(self):
131
133
err = ResponseMessage (error = 'Illegal' )
132
134
http_resp = MockResponse (400 , err .to_urlencoded ())
133
135
resp = self .client .parse_request_response (
134
- self .client .client_get ("service" ,'authorization' ), http_resp )
136
+ self .client .client_get ("service" , 'authorization' ), http_resp )
135
137
136
138
assert resp ['error' ] == 'Illegal'
137
139
assert resp ['status_code' ] == 400
@@ -141,7 +143,7 @@ def test_error_response_500(self):
141
143
http_resp = MockResponse (500 , err .to_urlencoded ())
142
144
with pytest .raises (ParseError ):
143
145
self .client .parse_request_response (
144
- self .client .client_get ("service" ,'authorization' ), http_resp )
146
+ self .client .client_get ("service" , 'authorization' ), http_resp )
145
147
146
148
def test_error_response_2 (self ):
147
149
err = ResponseMessage (error = 'Illegal' )
@@ -151,4 +153,42 @@ def test_error_response_2(self):
151
153
152
154
with pytest .raises (OidcServiceError ):
153
155
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