1+ import json
12from urllib .parse import parse_qs
23from urllib .parse import urlparse
34
4- import json
55import pytest
66from cryptojwt .exception import HeaderError
7-
87from cryptojwt .jwk .hmac import SYMKey
98from cryptojwt .jwk .rsa import new_rsa_key
109from cryptojwt .jws .exception import NoSuitableSigningKeys
11-
1210from cryptojwt .key_bundle import KeyBundle
13- from cryptojwt .key_jar import build_keyjar
1411from cryptojwt .key_jar import KeyJar
12+ from cryptojwt .key_jar import build_keyjar
1513
1614from oidcmsg .exception import DecodeError
1715from oidcmsg .exception import MessageException
1816from oidcmsg .exception import OidcMsgError
19- from oidcmsg .exception import WrongEncryptionAlgorithm
20-
21- from oidcmsg .message import json_deserializer , msg_ser
22- from oidcmsg .message import json_serializer
2317from oidcmsg .message import OPTIONAL_LIST_OF_MESSAGES
2418from oidcmsg .message import OPTIONAL_LIST_OF_STRINGS
2519from oidcmsg .message import OPTIONAL_MESSAGE
2822from oidcmsg .message import SINGLE_OPTIONAL_JSON
2923from oidcmsg .message import SINGLE_OPTIONAL_STRING
3024from oidcmsg .message import SINGLE_REQUIRED_STRING
25+ from oidcmsg .message import json_deserializer
26+ from oidcmsg .message import json_serializer
27+ from oidcmsg .message import msg_ser
3128from oidcmsg .message import sp_sep_list_deserializer
32-
3329from oidcmsg .oauth2 import Message
3430
3531__author__ = 'Roland Hedberg'
4137 {"type" : "RSA" , "use" : ["enc" ]},
4238 {"type" : "EC" , "crv" : "P-256" , "use" : ["sig" ]},
4339 {"type" : "EC" , "crv" : "P-256" , "use" : ["enc" ]},
44- ]
40+ ]
4541
4642keym = [
4743 {"type" : "RSA" , "use" : ["sig" ]},
4844 {"type" : "RSA" , "use" : ["sig" ]},
4945 {"type" : "RSA" , "use" : ["sig" ]},
50- ]
46+ ]
5147
5248KEYJAR = build_keyjar (keys )
5349
5450IKEYJAR = build_keyjar (keys )
55- IKEYJAR .issuer_keys [ 'issuer' ] = IKEYJAR .issuer_keys [ '' ]
56- del IKEYJAR . issuer_keys ['' ]
51+ IKEYJAR .import_jwks ( IKEYJAR .export_jwks ( private = True ), 'issuer' )
52+ del IKEYJAR ['' ]
5753
5854KEYJARS = {}
5955for iss in ['A' , 'B' , 'C' ]:
6056 _kj = build_keyjar (keym )
61- _kj .issuer_keys [ iss ] = _kj .issuer_keys [ '' ]
62- del _kj . issuer_keys ['' ]
57+ _kj .import_jwks ( _kj .export_jwks ( private = True ), iss )
58+ del _kj ['' ]
6359 KEYJARS [iss ] = _kj
6460
6561
@@ -121,7 +117,7 @@ class DummyMessage(Message):
121117 "opt_str_list" : OPTIONAL_LIST_OF_STRINGS ,
122118 "req_str_list" : REQUIRED_LIST_OF_STRINGS ,
123119 "opt_json" : SINGLE_OPTIONAL_JSON
124- }
120+ }
125121
126122
127123class TestMessage (object ):
@@ -296,7 +292,7 @@ def test_int_instead_of_string(self):
296292@pytest .mark .parametrize ("keytype,alg" , [
297293 ('RSA' , 'RS256' ),
298294 ('EC' , 'ES256' )
299- ])
295+ ])
300296def test_to_jwt (keytype , alg ):
301297 msg = Message (a = 'foo' , b = 'bar' , c = 'tjoho' )
302298 _jwt = msg .to_jwt (KEYJAR .get_signing_key (keytype , '' ), alg )
@@ -307,7 +303,7 @@ def test_to_jwt(keytype, alg):
307303@pytest .mark .parametrize ("keytype,alg,enc" , [
308304 ('RSA' , 'RSA1_5' , 'A128CBC-HS256' ),
309305 ('EC' , 'ECDH-ES' , 'A128GCM' ),
310- ])
306+ ])
311307def test_to_jwe (keytype , alg , enc ):
312308 msg = Message (a = 'foo' , b = 'bar' , c = 'tjoho' )
313309 _jwe = msg .to_jwe (KEYJAR .get_encrypt_key (keytype , '' ), alg = alg , enc = enc )
@@ -334,7 +330,7 @@ class MsgMessage(Message):
334330 c_param = {
335331 "msg" : OPTIONAL_MESSAGE ,
336332 "opt_str" : SINGLE_OPTIONAL_STRING ,
337- }
333+ }
338334
339335 _dict = {
340336 "req_str" : "Fair" , "req_str_list" : ["spike" , "lee" ],
@@ -359,7 +355,7 @@ class MsgMessage(Message):
359355 c_param = {
360356 "msgs" : OPTIONAL_LIST_OF_MESSAGES ,
361357 "opt_str" : SINGLE_OPTIONAL_STRING ,
362- }
358+ }
363359
364360 _dict = {
365361 "req_str" : "Fair" , "req_str_list" : ["spike" , "lee" ],
@@ -385,7 +381,7 @@ class MsgMessage(Message):
385381 c_param = {
386382 "msgs" : OPTIONAL_LIST_OF_MESSAGES ,
387383 "opt_str" : SINGLE_OPTIONAL_STRING ,
388- }
384+ }
389385
390386 _dict = {
391387 "req_str" : "Fair" , "req_str_list" : ["spike" , "lee" ],
@@ -409,7 +405,7 @@ class MsgMessage(Message):
409405 c_param = {
410406 "msgs" : OPTIONAL_LIST_OF_MESSAGES ,
411407 "opt_str" : SINGLE_OPTIONAL_STRING ,
412- }
408+ }
413409
414410 _dict = {
415411 "req_str" : "Fair" , "req_str_list" : ["spike" , "lee" ],
@@ -446,7 +442,7 @@ def test_json_type_error():
446442@pytest .mark .parametrize ("keytype,alg,enc" , [
447443 ('RSA' , 'RSA1_5' , 'A128CBC-HS256' ),
448444 ('EC' , 'ECDH-ES' , 'A128GCM' ),
449- ])
445+ ])
450446def test_to_jwe (keytype , alg , enc ):
451447 msg = Message (a = 'foo' , b = 'bar' , c = 'tjoho' )
452448 _jwe = msg .to_jwe (KEYJAR .get_encrypt_key (keytype , '' ), alg = alg ,
@@ -469,8 +465,7 @@ def test_no_suitable_keys():
469465 keytype = 'RSA'
470466 alg = 'RS256'
471467 msg = Message (a = 'foo' , b = 'bar' , c = 'tjoho' )
472- _jwt = msg .to_jwt (NEW_KEYJAR .get_signing_key (keytype , '' , kid = NEW_KID ),
473- alg )
468+ _jwt = msg .to_jwt (NEW_KEYJAR .get_signing_key (keytype , '' , kid = NEW_KID ), alg )
474469 with pytest .raises (NoSuitableSigningKeys ):
475470 Message ().from_jwt (_jwt , KEYJAR )
476471
@@ -495,9 +490,9 @@ def test_weed():
495490def test_msg_ser ():
496491 assert msg_ser ('a.b.c' , 'dict' ) == 'a.b.c'
497492 with pytest .raises (MessageException ):
498- msg_ser ([1 ,2 ], 'dict' )
493+ msg_ser ([1 , 2 ], 'dict' )
499494 with pytest .raises (OidcMsgError ):
500- msg_ser ([1 ,2 ], 'list' )
495+ msg_ser ([1 , 2 ], 'list' )
501496
502497
503498def test_error_description ():
0 commit comments