-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #349 from bcgov/feat/347-add-backwards-compat-sett…
…ing-for-token-claims Add backwards compatibility setting for token claims
- Loading branch information
Showing
5 changed files
with
82 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,41 @@ | |
"sub_proof_index": 0, | ||
"values": { | ||
"email": { | ||
"raw": "jamiehalebc@gmail.com", | ||
"raw": "test@email.com", | ||
"encoded": "73814602767252868561268261832462872577293109184327908660400248444458427915643", | ||
} | ||
} | ||
} | ||
} | ||
|
||
multiple_valid_requested_attributes = { | ||
"req_attr_0": { | ||
"names": ["email_1", "age_1"], | ||
"restrictions": [ | ||
{ | ||
"schema_name": "verified-email", | ||
"issuer_did": "MTYqmTBoLT7KLP5RNfgK3b", | ||
} | ||
], | ||
}, | ||
} | ||
|
||
multiple_valid_revealed_attr_groups = { | ||
"req_attr_0": { | ||
"sub_proof_index": 0, | ||
"values": { | ||
"email_1": { | ||
"raw": "[email protected]", | ||
"encoded": "73814602767252868561268261832462872577293109184327908660400248444458427915643", | ||
}, | ||
"age_1": { | ||
"raw": "30", | ||
"encoded": "73814602767252868561268261832462872577293109184327908660400248444458427915644", | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_valid_proof_presentation_with_one_attribute_returns_claims(): | ||
|
@@ -66,7 +94,7 @@ async def test_valid_proof_presentation_with_multiple_attributes_returns_claims( | |
"sub_proof_index": 0, | ||
"values": { | ||
"email": { | ||
"raw": "jamiehalebc@gmail.com", | ||
"raw": "test@email.com", | ||
"encoded": "73814602767252868561268261832462872577293109184327908660400248444458427915643", | ||
} | ||
} | ||
|
@@ -87,36 +115,48 @@ async def test_valid_proof_presentation_with_multiple_attributes_returns_claims( | |
|
||
|
||
@pytest.mark.asyncio | ||
async def test_valid_proof_presentation_with_one_attribute_and_multiple_values_returns_claims(): | ||
presentation['presentation_request']['requested_attributes'] = { | ||
"req_attr_0": { | ||
"names": ["email_1", "age_1"], | ||
"restrictions": [ | ||
{ | ||
"schema_name": "verified-email", | ||
"issuer_did": "MTYqmTBoLT7KLP5RNfgK3b", | ||
} | ||
], | ||
}, | ||
} | ||
presentation['presentation']['requested_proof']['revealed_attr_groups'] = { | ||
"req_attr_0": { | ||
"sub_proof_index": 0, | ||
"values": { | ||
"email_1": { | ||
"raw": "[email protected]", | ||
"encoded": "73814602767252868561268261832462872577293109184327908660400248444458427915643", | ||
}, | ||
"age_1": { | ||
"raw": "30", | ||
"encoded": "73814602767252868561268261832462872577293109184327908660400248444458427915644", | ||
} | ||
} | ||
} | ||
} | ||
async def test_include_v1_attributes_false_does_not_add_the_named_attributes(): | ||
presentation['presentation_request']['requested_attributes'] = multiple_valid_requested_attributes | ||
presentation['presentation']['requested_proof']['revealed_attr_groups'] = multiple_valid_revealed_attr_groups | ||
with mock.patch.object(AuthSession, "presentation_exchange", presentation): | ||
ver_config.include_v1_attributes = False | ||
claims = Token.get_claims(auth_session, ver_config) | ||
vc_presented_attributes_obj = eval(claims["vc_presented_attributes"]) | ||
assert claims is not None | ||
assert vc_presented_attributes_obj["email_1"] == '[email protected]' | ||
assert vc_presented_attributes_obj["age_1"] == '30' | ||
assert "email_1" not in claims | ||
assert "age_1" not in claims | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_include_v1_attributes_true_adds_the_named_attributes(): | ||
presentation['presentation_request']['requested_attributes'] = multiple_valid_requested_attributes | ||
presentation['presentation']['requested_proof']['revealed_attr_groups'] = multiple_valid_revealed_attr_groups | ||
with mock.patch.object(AuthSession, "presentation_exchange", presentation): | ||
ver_config.include_v1_attributes = True | ||
claims = Token.get_claims(auth_session, ver_config) | ||
vc_presented_attributes_obj = eval(claims["vc_presented_attributes"]) | ||
assert claims is not None | ||
assert vc_presented_attributes_obj["email_1"] == '[email protected]' | ||
assert vc_presented_attributes_obj["age_1"] == '30' | ||
assert claims["email_1"] == '[email protected]' | ||
assert claims["age_1"] == '30' | ||
|
||
@pytest.mark.asyncio | ||
async def test_include_v1_attributes_none_does_not_add_the_named_attributes(): | ||
presentation['presentation_request']['requested_attributes'] = multiple_valid_requested_attributes | ||
presentation['presentation']['requested_proof']['revealed_attr_groups'] = multiple_valid_revealed_attr_groups | ||
with mock.patch.object(AuthSession, "presentation_exchange", presentation): | ||
ver_config.include_v1_attributes = None | ||
print(ver_config.include_v1_attributes) | ||
claims = Token.get_claims(auth_session, ver_config) | ||
vc_presented_attributes_obj = eval(claims["vc_presented_attributes"]) | ||
assert claims is not None | ||
assert vc_presented_attributes_obj["email_1"] == '[email protected]' | ||
assert vc_presented_attributes_obj["age_1"] == '30' | ||
assert "email_1" not in claims | ||
assert "age_1" not in claims | ||
|
||
|
||
@pytest.mark.asyncio | ||
|
@@ -137,7 +177,7 @@ async def test_revealed_attrs_dont_match_requested_attributes_throws_exception() | |
"sub_proof_index": 0, | ||
"values": { | ||
"email-wrong": { | ||
"raw": "jamiehalebc@gmail.com", | ||
"raw": "test@email.com", | ||
"encoded": "73814602767252868561268261832462872577293109184327908660400248444458427915643", | ||
} | ||
} | ||
|
@@ -155,7 +195,8 @@ async def test_valid_presentation_with_matching_subject_identifier_has_identifie | |
with mock.patch.object(AuthSession, "presentation_exchange", presentation): | ||
claims = Token.get_claims(auth_session, ver_config) | ||
print(claims) | ||
assert claims["sub"] == "[email protected]" | ||
assert claims["sub"] == "[email protected]" | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_valid_presentation_with_non_matching_subject_identifier_and_has_uuid_in_claims_sub(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters