Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 9801cfb

Browse files
committed
Use full_path function.
1 parent ad30ba6 commit 9801cfb

File tree

2 files changed

+48
-36
lines changed

2 files changed

+48
-36
lines changed

tests/test_5_oauth2.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
# pylint: disable=no-self-use,missing-docstring
22

33
import json
4-
from urllib.parse import urlparse, parse_qs
4+
from urllib.parse import parse_qs
5+
from urllib.parse import urlparse
56

67
import pytest
7-
88
from cryptojwt.key_jar import build_keyjar
99

1010
from oidcmsg.exception import MissingRequiredAttribute
1111
from oidcmsg.message import DecodeError
1212
from oidcmsg.message import json_deserializer
1313
from oidcmsg.message import json_serializer
1414
from oidcmsg.message import sp_sep_list_deserializer
15-
16-
from oidcmsg.oauth2 import factory
17-
from oidcmsg.oauth2 import is_error_message
1815
from oidcmsg.oauth2 import AccessTokenRequest
1916
from oidcmsg.oauth2 import AccessTokenResponse
2017
from oidcmsg.oauth2 import AuthorizationErrorResponse
2118
from oidcmsg.oauth2 import AuthorizationRequest
2219
from oidcmsg.oauth2 import AuthorizationResponse
2320
from oidcmsg.oauth2 import CCAccessTokenRequest
24-
from oidcmsg.oauth2 import ResponseMessage
25-
from oidcmsg.oauth2 import RefreshAccessTokenRequest
2621
from oidcmsg.oauth2 import ROPCAccessTokenRequest
22+
from oidcmsg.oauth2 import RefreshAccessTokenRequest
23+
from oidcmsg.oauth2 import ResponseMessage
2724
from oidcmsg.oauth2 import TokenErrorResponse
25+
from oidcmsg.oauth2 import factory
26+
from oidcmsg.oauth2 import is_error_message
2827

2928
__author__ = 'Roland Hedberg'
3029

@@ -117,7 +116,8 @@ def test_urlencoded_with_redirect_uri(self):
117116

118117
ue = ar.to_urlencoded()
119118
assert query_string_compare(ue,
120-
"state=cold&redirect_uri=http%3A%2F%2Ffoobar.example.com%2Foaclient&"
119+
"state=cold&redirect_uri=http%3A%2F%2Ffoobar.example.com"
120+
"%2Foaclient&"
121121
"response_type=code&client_id=foobar")
122122

123123
def test_urlencoded_resp_type_token(self):
@@ -128,7 +128,8 @@ def test_urlencoded_resp_type_token(self):
128128

129129
ue = ar.to_urlencoded()
130130
assert query_string_compare(ue,
131-
"state=xyz&redirect_uri=https%3A%2F%2Fclient.example.com%2Fcb&response_type=token&"
131+
"state=xyz&redirect_uri=https%3A%2F%2Fclient.example.com%2Fcb"
132+
"&response_type=token&"
132133
"client_id=s6BhdRkqt3")
133134

134135
def test_deserialize_urlencoded(self):
@@ -146,7 +147,8 @@ def test_urlencoded_with_scope(self):
146147

147148
ue = ar.to_urlencoded()
148149
assert query_string_compare(ue,
149-
"scope=foo+bar&state=cold&redirect_uri=http%3A%2F%2Ffoobar.example.com%2Foaclient&"
150+
"scope=foo+bar&state=cold&redirect_uri=http%3A%2F%2Ffoobar"
151+
".example.com%2Foaclient&"
150152
"response_type=code&client_id=foobar")
151153

152154
def test_deserialize_urlencoded_multiple_params(self):
@@ -165,9 +167,11 @@ def test_urlencoded_missing_required(self):
165167
ar.verify()
166168

167169
def test_urlencoded_invalid_scope(self):
168-
args = {"response_type": [10], "client_id": "foobar",
169-
"redirect_uri": "http://foobar.example.com/oaclient",
170-
"scope": ["foo", "bar"], "state": "cold"}
170+
args = {
171+
"response_type": [10], "client_id": "foobar",
172+
"redirect_uri": "http://foobar.example.com/oaclient",
173+
"scope": ["foo", "bar"], "state": "cold"
174+
}
171175

172176
with pytest.raises(DecodeError):
173177
AuthorizationRequest(**args)
@@ -245,11 +249,13 @@ def test_verify(self):
245249
assert ar.verify()
246250

247251
def test_load_dict(self):
248-
bib = {"scope": ["openid"],
249-
"state": "id-6da9ca0cc23959f5f33e8becd9b08cae",
250-
"redirect_uri": "http://localhost:8087authz",
251-
"response_type": ["code"],
252-
"client_id": "a1b2c3"}
252+
bib = {
253+
"scope": ["openid"],
254+
"state": "id-6da9ca0cc23959f5f33e8becd9b08cae",
255+
"redirect_uri": "http://localhost:8087authz",
256+
"response_type": ["code"],
257+
"client_id": "a1b2c3"
258+
}
253259

254260
arq = AuthorizationRequest(**bib)
255261

@@ -260,11 +266,13 @@ def test_load_dict(self):
260266
assert arq["client_id"] == bib["client_id"]
261267

262268
def test_json_serizalize_deserialize_multiple_params(self):
263-
argv = {"scope": ["openid"],
264-
"state": "id-b0be8bb64118c3ec5f70093a1174b039",
265-
"redirect_uri": "http://localhost:8087authz",
266-
"response_type": ["code"],
267-
"client_id": "a1b2c3"}
269+
argv = {
270+
"scope": ["openid"],
271+
"state": "id-b0be8bb64118c3ec5f70093a1174b039",
272+
"redirect_uri": "http://localhost:8087authz",
273+
"response_type": ["code"],
274+
"client_id": "a1b2c3"
275+
}
268276

269277
arq = AuthorizationRequest(**argv)
270278
jstr = arq.serialize(method="json")
@@ -416,15 +424,18 @@ def test_to_urlencoded_extended_omit(self):
416424

417425
uec = atr.to_urlencoded()
418426
assert query_string_compare(uec,
419-
"scope=inner+outer&level=3&expires_in=3600&token_type=example&extra=local&"
427+
"scope=inner+outer&level=3&expires_in=3600&token_type=example"
428+
"&extra=local&"
420429
"extra=external&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA&"
421-
"access_token=2YotnFZFEjr1zCsicMWpAA&example_parameter=example_value")
430+
"access_token=2YotnFZFEjr1zCsicMWpAA&example_parameter"
431+
"=example_value")
422432

423433
del atr["extra"]
424434
ouec = atr.to_urlencoded()
425435
assert query_string_compare(ouec,
426436
"access_token=2YotnFZFEjr1zCsicMWpAA&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA&"
427-
"level=3&example_parameter=example_value&token_type=example&expires_in=3600&"
437+
"level=3&example_parameter=example_value&token_type=example"
438+
"&expires_in=3600&"
428439
"scope=inner+outer")
429440
assert len(uec) == (len(ouec) + len("extra=local") +
430441
len("extra=external") + 2)

tests/test_7_session.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,22 @@
4141
{"type": "EC", "crv": "P-256", "use": ["enc"]}
4242
]
4343

44-
_dirname = os.path.dirname(os.path.abspath(__file__))
4544

46-
CLI_KEY = init_key_jar(public_path='{}/pub_client.jwks'.format(_dirname),
47-
private_path='{}/priv_client.jwks'.format(_dirname),
45+
def full_path(local_file):
46+
_dirname = os.path.dirname(os.path.abspath(__file__))
47+
return os.path.join(_dirname, local_file)
48+
49+
50+
CLI_KEY = init_key_jar(public_path=full_path('pub_client.jwks'),
51+
private_path=full_path('priv_client.jwks'),
4852
key_defs=KEYDEF, owner=CLIENT_ID)
4953

50-
ISS_KEY = init_key_jar(public_path='{}/pub_iss.jwks'.format(_dirname),
51-
private_path='{}/priv_iss.jwks'.format(_dirname),
54+
ISS_KEY = init_key_jar(public_path=full_path('pub_iss.jwks'),
55+
private_path=full_path('priv_iss.jwks'),
5256
key_defs=KEYDEF, owner=ISS)
5357

54-
ISS_KEY.import_jwks_as_json(open('{}/pub_client.jwks'.format(_dirname)).read(),
55-
CLIENT_ID)
56-
57-
CLI_KEY.import_jwks_as_json(open('{}/pub_iss.jwks'.format(_dirname)).read(),
58-
ISS)
58+
ISS_KEY.import_jwks_as_json(open(full_path('pub_client.jwks')).read(), CLIENT_ID)
59+
CLI_KEY.import_jwks_as_json(open(full_path('pub_iss.jwks')).read(),ISS)
5960

6061

6162
class TestEndSessionResponse(object):

0 commit comments

Comments
 (0)