-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CredentialSubject): compare credential subject against credentia…
…l schema before issuance
- Loading branch information
1 parent
77d219b
commit 2618b20
Showing
3 changed files
with
74 additions
and
4 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
56 changes: 56 additions & 0 deletions
56
tests/v3_certificate_validation/test_unit_credential_subject.py
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import unittest | ||
|
||
from cert_issuer.models.verifiable_credential import validate_credential_subject | ||
|
||
class UnitValidationV3 (unittest.TestCase): | ||
def test_conforms_to_schema (self): | ||
credential_subject = { | ||
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21", | ||
"name": "John Smith", | ||
"nationality": "Canada", | ||
"DOB": "05/10/1983", | ||
"height": "1.80m", | ||
"residentialAddressStreet": "6 Maple Tree street", | ||
"residentialAddressTown": "Toronto", | ||
"residentialAddressPostCode": "YYZYUL" | ||
} | ||
|
||
# TODO: ideally this would be stubbed to have better control over the test | ||
# TODO: however urlretrieve and consumption is a bit convoluted to mock | ||
credential_schema = { | ||
"id": "https://www.blockcerts.org/samples/3.0/example-id-card-schema.json", | ||
"type": "JsonSchema" | ||
} | ||
|
||
try: | ||
validate_credential_subject(credential_subject, credential_schema) | ||
except: | ||
assert False | ||
return | ||
|
||
assert True | ||
def test_does_not_conform_to_schema (self): | ||
credential_subject = { | ||
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21", | ||
"name": "John Smith", | ||
"DOB": "05/10/1983", | ||
"height": "1.80m", | ||
"residentialAddressStreet": "6 Maple Tree street", | ||
"residentialAddressTown": "Toronto", | ||
"residentialAddressPostCode": "YYZYUL" | ||
} | ||
|
||
# TODO: ideally this would be stubbed to have better control over the test | ||
# TODO: however urlretrieve and consumption is a bit convoluted to mock | ||
credential_schema = { | ||
"id": "https://www.blockcerts.org/samples/3.0/example-id-card-schema.json", | ||
"type": "JsonSchema" | ||
} | ||
|
||
try: | ||
validate_credential_subject(credential_subject, credential_schema) | ||
except: | ||
assert True | ||
return | ||
|
||
assert False |