Skip to content

Commit

Permalink
to_dict method handles empty list case
Browse files Browse the repository at this point in the history
add test changes requested upstream

update changelog to include requested link
  • Loading branch information
andrewkrug authored and lwm committed Aug 23, 2017
1 parent ba67abd commit 25a6fb8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on the [KeepAChangeLog] project.

### Fixed
- [#405]: Fix generation of endpoint urls
- [#411]: Empty lists not indexable

[#405]: https://github.com/OpenIDC/pyoidc/issues/405

Expand Down Expand Up @@ -40,6 +41,7 @@ The format is based on the [KeepAChangeLog] project.
- [#349]: Changed crypto algorithm used by `oic.utils.sdb.Crypt` for token encryption to Fernet. Old stored tokens are incompatible.
- [#363]: Fixed IV reuse for CookieDealer class. Replaced the encrypt-then-mac construction with a proper AEAD (AES-SIV).

[#411]: https://github.com/OpenIDC/pyoidc/issues/411
[#317]: https://github.com/OpenIDC/pyoidc/pull/317
[#313]: https://github.com/OpenIDC/pyoidc/issues/313
[#387]: https://github.com/OpenIDC/pyoidc/pull/387
Expand Down
2 changes: 1 addition & 1 deletion src/oic/oauth2/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def to_dict(self, lev=0):

if isinstance(val, Message):
_res[key] = val.to_dict(lev + 1)
elif isinstance(val, list) and isinstance(val[0], Message):
elif isinstance(val, list) and isinstance(next(iter(val or []), None), Message):
_res[key] = [v.to_dict(lev) for v in val]
else:
_res[key] = val
Expand Down
17 changes: 16 additions & 1 deletion tests/test_oauth2_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class DummyMessage(Message):
"opt_int": SINGLE_OPTIONAL_INT,
"opt_str_list": OPTIONAL_LIST_OF_STRINGS,
"req_str_list": REQUIRED_LIST_OF_STRINGS,
"opt_json": SINGLE_OPTIONAL_JSON}
"opt_json": SINGLE_OPTIONAL_JSON
}


class TestMessage(object):
Expand Down Expand Up @@ -651,6 +652,20 @@ def test_to_jwe(keytype, alg, enc):
assert msg1 == msg


def test_to_dict_with_message_obj():
content = Message(a={'a': {'foo': {'bar': [{'bat': []}]}}})
_dict = content.to_dict(lev=0)
content_fixture = {'a': {'a': {'foo': {'bar': [{'bat': []}]}}}}
assert _dict == content_fixture


def test_to_dict_with_raw_types():
msg = Message(c_default=[])
content_fixture = {'c_default': []}
_dict = msg.to_dict(lev=1)
assert _dict == content_fixture


def test_get_verify_keys_no_kid_multiple_keys():
msg = Message()
header = {'alg': 'RS256'}
Expand Down

0 comments on commit 25a6fb8

Please sign in to comment.