11import json
2+ import os
23
34from idpyoidc .server import OPConfiguration
45from idpyoidc .server import Server
56from idpyoidc .server .client_configure import verify_oidc_client_information
67from idpyoidc .util import load_config_file
7-
88from tests import full_path
99
10+ BASEDIR = os .path .abspath (os .path .dirname (__file__ ))
11+
1012extra = {
1113 "token_usage_rules" : {
1214 "authorization_code" : {
2325 "subject_token_types_supported" : [
2426 "urn:ietf:params:oauth:token-type:access_token" ,
2527 "urn:ietf:params:oauth:token-type:refresh_token" ,
26- "urn:ietf:params:oauth:token-type:id_token"
28+ "urn:ietf:params:oauth:token-type:id_token" ,
2729 ],
2830 "requested_token_types_supported" : [
2931 "urn:ietf:params:oauth:token-type:access_token" ,
3032 "urn:ietf:params:oauth:token-type:refresh_token" ,
31- "urn:ietf:params:oauth:token-type:id_token"
33+ "urn:ietf:params:oauth:token-type:id_token" ,
3234 ],
3335 "policy" : {
3436 "urn:ietf:params:oauth:token-type:access_token" : {
3537 "callable" : "/path/to/callable" ,
36- "kwargs" : {
37- "audience" : ["https://example.com" ],
38- "scopes" : ["openid" ]
39- }
38+ "kwargs" : {"audience" : ["https://example.com" ], "scopes" : ["openid" ]},
4039 },
4140 "urn:ietf:params:oauth:token-type:refresh_token" : {
4241 "callable" : "/path/to/callable" ,
43- "kwargs" : {
44- "resource" : ["https://example.com" ],
45- "scopes" : ["openid" ]
46- }
42+ "kwargs" : {"resource" : ["https://example.com" ], "scopes" : ["openid" ]},
4743 },
48- "" : {
49- "callable" : "/path/to/callable" ,
50- "kwargs" : {
51- "scopes" : ["openid" ]
52- }
53- }
54- }
55- }
44+ "" : {"callable" : "/path/to/callable" , "kwargs" : {"scopes" : ["openid" ]}},
45+ },
46+ },
5647 },
5748 "allowed_scopes" : ["scope" ],
58- "scopes_to_claims" : {
59- "scope_a" : ["claim1" , "claim2" ],
60- "scope_b" : []
61- },
49+ "scopes_to_claims" : {"scope_a" : ["claim1" , "claim2" ], "scope_b" : []},
6250 "add_claims" : {
6351 "always" : {
6452 "userinfo" : ["email" , "phone" ],
7159 "by_scope" : {
7260 "id_token" : False ,
7361 },
74- }
75- }
62+ },
63+ },
7664}
7765
7866
7967def test_op_configure_oidc_clients_simple ():
80- _str = open (full_path ("op_config.json" )).read ()
68+ _str = open (full_path (full_path ( "op_config.json" ) )).read ()
8169 _conf = json .loads (_str )
8270 _conf ["oidc_clients" ] = {
8371 "client1" : {
8472 "client_id" : "client1" ,
8573 "client_secret" : "Namnam" ,
86- "redirect_uris" : [' https://openidconnect.net/callback' , '' ],
87- "response_types" : ["code" ]
74+ "redirect_uris" : [" https://openidconnect.net/callback" , "" ],
75+ "response_types" : ["code" ],
8876 },
8977 "client2" : {
9078 "client_id" : "client2" ,
9179 "client_secret" : "spraket" ,
92- "redirect_uris" : [' https://app1.example.net/foo' , ' https://app2.example.net/bar' ],
93- "response_types" : ["code" ]
80+ "redirect_uris" : [" https://app1.example.net/foo" , " https://app2.example.net/bar" ],
81+ "response_types" : ["code" ],
9482 },
9583 "client3" : {
9684 "client_id" : "client3" ,
97- "client_secret" : ' 2222222222222222222222222222222222222222' ,
98- "redirect_uris" : [' https://127.0.0.1:8090/authz_cb/bobcat' ],
99- "post_logout_redirect_uri" : ' https://openidconnect.net/' ,
100- "response_types" : ["code" ]
101- }
85+ "client_secret" : " 2222222222222222222222222222222222222222" ,
86+ "redirect_uris" : [" https://127.0.0.1:8090/authz_cb/bobcat" ],
87+ "post_logout_redirect_uri" : " https://openidconnect.net/" ,
88+ "response_types" : ["code" ],
89+ },
10290 }
10391
104- op_conf = OPConfiguration (conf = _conf )
92+ op_conf = OPConfiguration (conf = _conf , base_path = BASEDIR )
10593 assert op_conf
10694
10795
10896def test_verify_oidc_client_information_complext ():
109- _conf = load_config_file ("op_config.json" )
110- server = Server (OPConfiguration (conf = _conf ))
97+ _conf = load_config_file (full_path ( "op_config.json" ) )
98+ server = Server (OPConfiguration (conf = _conf , base_path = BASEDIR ))
11199
112100 client_conf = {
113101 "client1" : {
114102 "client_id" : "client1" ,
115103 "client_secret" : "Namnam" ,
116- "redirect_uris" : [' https://openidconnect.net/callback' , '' ],
117- "response_types" : ["code" ]
104+ "redirect_uris" : [" https://openidconnect.net/callback" , "" ],
105+ "response_types" : ["code" ],
118106 }
119107 }
120108
@@ -127,22 +115,22 @@ def test_verify_oidc_client_information_complext():
127115
128116
129117def test_verify_oidc_client_information_2 ():
130- _conf = load_config_file ("op_config.json" )
131- server = Server (OPConfiguration (conf = _conf ))
118+ _conf = load_config_file (full_path ( "op_config.json" ) )
119+ server = Server (OPConfiguration (conf = _conf , base_path = BASEDIR ), cwd = full_path ( "" ))
132120
133121 client_conf = {
134122 "client1" : {
135123 "client_id" : "client1" ,
136124 "client_secret" : "Namnam" ,
137- "redirect_uris" : [' https://openidconnect.net/callback' , '' ],
125+ "redirect_uris" : [" https://openidconnect.net/callback" , "" ],
138126 "response_types" : ["code" ],
139127 "token_usage_rules" : {
140128 "authorization_code" : {
141129 "expires_in" : 600 ,
142130 "supports_minting" : ["access_token" , "refresh_token" ],
143131 },
144132 "refresh_token" : {"supports_minting" : ["access_token" ]},
145- "dummy_token" : {"supports_minting" : ["foobar_token" ]}
133+ "dummy_token" : {"supports_minting" : ["foobar_token" ]},
146134 },
147135 }
148136 }
0 commit comments