Skip to content

Commit

Permalink
Merge pull request #418 from rohe/claim_boolean
Browse files Browse the repository at this point in the history
Made phone_number_verified be boolean.
  • Loading branch information
lwm authored Aug 31, 2017
2 parents 6b56e7d + 5258930 commit f220947
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ The format is based on the [KeepAChangeLog] project.
- [#405]: Fix generation of endpoint urls
- [#411]: Empty lists not indexable
- [#413]: Fix error when wrong response_mode requested
- [#418]: Made phone_number_claim be boolean and fixed a bug when importing JSON (non-boolean where boolean expected)

[#418]: https://github.com/OpenIDC/pyoidc/pull/418
[#411]: https://github.com/OpenIDC/pyoidc/issues/411
[#405]: https://github.com/OpenIDC/pyoidc/issues/405
[#413]: https://github.com/OpenIDC/pyoidc/issues/413
Expand Down
3 changes: 3 additions & 0 deletions src/oic/oauth2/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ def _add_value(self, skey, vtyp, key, val, _deser, null_allowed):
skey))
else:
return
elif vtyp is bool:
raise ValueError(
'"{}", wrong type of value for "{}"'.format(val, skey))

if isinstance(val, six.string_types):
self._dict[skey] = val
Expand Down
2 changes: 1 addition & 1 deletion src/oic/oic/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ class OpenIDSchema(Message):
"zoneinfo": SINGLE_OPTIONAL_STRING,
"locale": SINGLE_OPTIONAL_STRING,
"phone_number": SINGLE_OPTIONAL_STRING,
"phone_number_verified": SINGLE_OPTIONAL_STRING,
"phone_number_verified": SINGLE_OPTIONAL_BOOLEAN,
"address": OPTIONAL_ADDRESS,
"updated_at": SINGLE_OPTIONAL_INT,
"_claim_names": OPTIONAL_MESSAGE,
Expand Down
38 changes: 34 additions & 4 deletions tests/test_oic_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,31 @@ def test_openidschema_from_json(json_param):
OpenIDSchema().from_json(json_param)


@pytest.mark.parametrize("json_param", [
'{"email_verified":false, "email":"foo@example.com", "sub":"abc"}',
'{"email_verified":true, "email":"foo@example.com", "sub":"abc"}',
'{"phone_number_verified":false, "phone_number":"+1 555 200000", '
'"sub":"abc"}',
'{"phone_number_verified":true, "phone_number":"+1 555 20000", '
'"sub":"abc"}',
])
def test_claim_booleans(json_param):
assert OpenIDSchema().from_json(json_param)


@pytest.mark.parametrize("json_param", [
'{"email_verified":"Not", "email":"foo@example.com", "sub":"abc"}',
'{"email_verified":"Sure", "email":"foo@example.com", "sub":"abc"}',
'{"phone_number_verified":"Not", "phone_number":"+1 555 200000", '
'"sub":"abc"}',
'{"phone_number_verified":"Sure", "phone_number":"+1 555 20000", '
'"sub":"abc"}',
])
def test_claim_not_booleans(json_param):
with pytest.raises(ValueError):
OpenIDSchema().from_json(json_param)


def test_claims_deser():
_dic = {
"userinfo": {
Expand Down Expand Up @@ -350,16 +375,21 @@ def test_registration_request(self):
"default_max_age": 10, "response_types": ["code"]}
assert js_obj == expected_js_obj

flattened_list_dict = {k: v[0] if isinstance(v, list) else v for k, v in expected_js_obj.items()}
assert query_string_compare(req.to_urlencoded(), urlencode(flattened_list_dict))
flattened_list_dict = {k: v[0] if isinstance(v, list) else v for k, v in
expected_js_obj.items()}
assert query_string_compare(req.to_urlencoded(),
urlencode(flattened_list_dict))

@pytest.mark.parametrize("enc_param", [
"request_object_encryption_enc",
"id_token_encrypted_response_enc",
"userinfo_encrypted_response_enc",
])
def test_registration_request_with_coupled_encryption_params(self, enc_param):
registration_params = {"redirect_uris": ["https://example.com/authz_cb"], enc_param: "RS25asdasd6"}
def test_registration_request_with_coupled_encryption_params(self,
enc_param):
registration_params = {
"redirect_uris": ["https://example.com/authz_cb"],
enc_param: "RS25asdasd6"}
registration_req = RegistrationRequest(**registration_params)
with pytest.raises(AssertionError):
registration_req.verify()
Expand Down

0 comments on commit f220947

Please sign in to comment.