Skip to content

Commit

Permalink
make pylama happy
Browse files Browse the repository at this point in the history
  • Loading branch information
rohe committed Jun 22, 2017
1 parent 27c9348 commit 3ec660c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/oic/oauth2/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ def _add_key(self, keyjar, issuer, key, key_type='', kid='',
def get_verify_keys(self, keyjar, key, jso, header, jwt, **kwargs):
"""
Get keys from a keyjar that can be used to verify a signed JWT
:param keyjar: A KeyJar instance
:param keyjar: A KeyJar instance
:param key: List of keys to start with
:param jso: The payload of the JWT, expected to be a dictionary.
:param header: The header of the JWT
Expand Down
33 changes: 21 additions & 12 deletions tests/test_oauth2_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
del IKEYJAR.issuer_keys['']

KEYJARS = {}
for iss in ['A','B','C']:
for iss in ['A', 'B', 'C']:
_kj = build_keyjar(keym)[1]
_kj.issuer_keys[iss] = _kj.issuer_keys['']
del _kj.issuer_keys['']
Expand Down Expand Up @@ -134,19 +134,22 @@ def test_json_serialization(self):
'opt_str_list', 'opt_int'])

def test_from_json(self):
jso = '{"req_str": "Fair", "req_str_list": ["spike", "lee"], "opt_int": [9]}'
jso = '{"req_str": "Fair", "req_str_list": ["spike", "lee"], ' \
'"opt_int": [9]}'
item = DummyMessage().deserialize(jso, "json")

assert _eq(item.keys(), ['req_str', 'req_str_list', 'opt_int'])
assert item["opt_int"] == 9

def test_single_optional(self):
jso = '{"req_str": "Fair", "req_str_list": ["spike", "lee"], "opt_int": [9, 10]}'
jso = '{"req_str": "Fair", "req_str_list": ["spike", "lee"], ' \
'"opt_int": [9, 10]}'
with pytest.raises(TooManyValues):
DummyMessage().deserialize(jso, "json")

def test_extra_param(self):
jso = '{"req_str": "Fair", "req_str_list": ["spike", "lee"], "extra": "out"}'
jso = '{"req_str": "Fair", "req_str_list": ["spike", "lee"], "extra": ' \
'"out"}'
item = DummyMessage().deserialize(jso, "json")

assert _eq(item.keys(), ['req_str', 'req_str_list', 'extra'])
Expand Down Expand Up @@ -284,15 +287,17 @@ def test_urlencoded_invalid_scope(self):
AuthorizationRequest(**args)

def test_urlencoded_deserialize_state(self):
txt = "scope=foo+bar&state=-11&redirect_uri=http%3A%2F%2Ffoobar.example.com%2Foaclient&response_type=code&" \
txt = "scope=foo+bar&state=-11&redirect_uri=http%3A%2F%2Ffoobar" \
".example.com%2Foaclient&response_type=code&" \
"client_id=foobar"

ar = AuthorizationRequest().deserialize(txt, "urlencoded")
assert ar["state"] == "-11"

def test_urlencoded_deserialize_response_type(self):
txt = "scope=openid&state=id-6a3fc96caa7fd5cb1c7d00ed66937134&" \
"redirect_uri=http%3A%2F%2Flocalhost%3A8087authz&response_type=code&client_id=a1b2c3"
"redirect_uri=http%3A%2F%2Flocalhost%3A8087authz&response_type" \
"=code&client_id=a1b2c3"

ar = AuthorizationRequest().deserialize(txt, "urlencoded")
assert ar["scope"] == ["openid"]
Expand Down Expand Up @@ -348,7 +353,8 @@ def test_json_serialize_deserialize(self):
assert ar == ar2

def test_verify(self):
query = 'redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fauthz&response_type=code&client_id=0123456789'
query = 'redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fauthz' \
'&response_type=code&client_id=0123456789'
ar = AuthorizationRequest().deserialize(query, "urlencoded")
assert ar.verify()

Expand Down Expand Up @@ -404,7 +410,8 @@ def test_multiple_scopes_urlencoded(self):
scope=["openid", "foxtrot"])
ue = ar.to_urlencoded()
ue_splits = ue.split('&')
expected_ue_splits = "scope=openid+foxtrot&response_type=code+token&client_id=foobar".split(
expected_ue_splits = "scope=openid+foxtrot&response_type=code+token" \
"&client_id=foobar".split(
'&')
assert _eq(ue_splits, expected_ue_splits)

Expand Down Expand Up @@ -456,7 +463,8 @@ def test_init(self):

def test_extra_params(self):
aer = AuthorizationErrorResponse(error="access_denied",
error_description="brewers has a four game series",
error_description="brewers has a "
"four game series",
foo="bar")
assert aer["error"] == "access_denied"
assert aer["error_description"] == "brewers has a four game series"
Expand All @@ -472,7 +480,8 @@ def test_init(self):

def test_extra_params(self):
ter = TokenErrorResponse(error="access_denied",
error_description="brewers has a four game series",
error_description="brewers has a four game "
"series",
foo="bar")

assert ter["error"] == "access_denied"
Expand Down Expand Up @@ -623,7 +632,7 @@ def test_missing_required(self):
err.to_urlencoded()


@pytest.mark.parametrize("keytype,alg",[
@pytest.mark.parametrize("keytype,alg", [
('RSA', 'RS256'),
('EC', 'ES256')
])
Expand All @@ -634,7 +643,7 @@ def test_to_jwt(keytype, alg):
assert msg1 == msg


@pytest.mark.parametrize("keytype,alg,enc",[
@pytest.mark.parametrize("keytype,alg,enc", [
('RSA', 'RSA1_5', 'A128CBC-HS256'),
('EC', 'ECDH-ES', 'A128GCM'),
])
Expand Down

0 comments on commit 3ec660c

Please sign in to comment.