Skip to content

Commit

Permalink
Merge pull request #687 from sklump/json-ld-non-ascii
Browse files Browse the repository at this point in the history
Json ld non ascii
  • Loading branch information
andrewwhitehead authored Aug 28, 2020
2 parents 872886b + b24dee0 commit 1f34063
Showing 2 changed files with 43 additions and 21 deletions.
2 changes: 1 addition & 1 deletion aries_cloudagent/messaging/jsonld/create_verify_data.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ def _canonize(data):


def _sha256(data):
return hashlib.sha256(data.encode("ascii")).hexdigest()
return hashlib.sha256(data.encode("utf-8")).hexdigest()


def _cannonize_signature_options(signatureOptions):
62 changes: 42 additions & 20 deletions aries_cloudagent/messaging/jsonld/tests/test_routes.py
Original file line number Diff line number Diff line change
@@ -4,22 +4,21 @@
from aries_cloudagent.config.injection_context import InjectionContext
from aries_cloudagent.wallet.base import BaseWallet
from aries_cloudagent.wallet.basic import BasicWallet

from ....storage.base import BaseStorage

from .. import routes as test_module


# TODO: Add tests
class TestJSONLDRoutes(AsyncTestCase):
def setUp(self):
async def setUp(self):
self.context = InjectionContext(enforce_typing=False)

self.storage = async_mock.create_autospec(BaseStorage)

self.context.injector.bind_instance(BaseStorage, self.storage)

self.wallet = self.wallet = BasicWallet()
self.did_info = await self.wallet.create_local_did()
self.context.injector.bind_instance(BaseWallet, self.wallet)

self.app = {
"request_context": self.context,
}
@@ -29,18 +28,26 @@ async def test_verify_credential(self):
app=self.app,
json=async_mock.CoroutineMock(
return_value={ # posted json
"verkey": "5yKdnU7ToTjAoRNDzfuzVTfWBH38qyhE1b9xh4v8JaWF", # pulled from the did:key in example
"verkey": (
# pulled from the did:key in example
"5yKdnU7ToTjAoRNDzfuzVTfWBH38qyhE1b9xh4v8JaWF"
),
"doc": {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1",
],
"id": "http://example.gov/credentials/3732",
"type": ["VerifiableCredential", "UniversityDegreeCredential"],
"issuer": "did:key:z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd",
"issuer": (
"did:key:z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd"
),
"issuanceDate": "2020-03-10T04:24:12.164Z",
"credentialSubject": {
"id": "did:key:z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd",
"id": (
"did:key:"
"z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd"
),
"degree": {
"type": "BachelorDegree",
"name": "Bachelor of Science and Arts",
@@ -49,9 +56,19 @@ async def test_verify_credential(self):
"proof": {
"type": "Ed25519Signature2018",
"created": "2020-04-10T21:35:35Z",
"verificationMethod": "did:key:z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd#z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd",
"verificationMethod": (
"did:key:"
"z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc"
"4tXLt9DoHd#z6MkjRagNiMu91DduvCvgEsqLZD"
"VzrJzFrwahc4tXLt9DoHd"
),
"proofPurpose": "assertionMethod",
"jws": "eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..l9d0YHjcFAH2H4dB9xlWFZQLUpixVCWJk0eOt4CXQe1NXKWZwmhmn9OQp6YxX0a2LffegtYESTCJEoGVXLqWAA",
"jws": (
"eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaX"
"QiOlsiYjY0Il19..l9d0YHjcFAH2H4dB9xlWFZQLUp"
"ixVCWJk0eOt4CXQe1NXKWZwmhmn9OQp6YxX0a2Lffe"
"gtYESTCJEoGVXLqWAA"
),
},
},
}
@@ -64,16 +81,11 @@ async def test_verify_credential(self):
mock_response.assert_called_once_with({"valid": True}) # expected response

async def test_sign_credential(self):

wallet: BaseWallet = await self.app["request_context"].inject(BaseWallet)

did_info = await wallet.create_local_did()

mock_request = async_mock.MagicMock(
app=self.app,
json=async_mock.CoroutineMock(
return_value={ # posted json
"verkey": did_info.verkey,
"verkey": self.did_info.verkey,
"doc": {
"credential": {
"@context": [
@@ -85,20 +97,30 @@ async def test_sign_credential(self):
"VerifiableCredential",
"UniversityDegreeCredential",
],
"issuer": "did:key:z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd",
"issuer": (
"did:key:"
"z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd"
),
"issuanceDate": "2020-03-10T04:24:12.164Z",
"credentialSubject": {
"id": "did:key:z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd",
"id": (
"did:key:"
"z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd"
),
"degree": {
"type": "BachelorDegree",
"name": "Bachelor of Science and Arts",
"name": u"Bachelor of Encyclopædic Arts",
},
},
},
"options": {
"type": "Ed25519Signature2018",
"created": "2020-04-10T21:35:35Z",
"verificationMethod": "did:key:z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd#z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd",
"verificationMethod": (
"did:key:"
"z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd#"
"z6MkjRagNiMu91DduvCvgEsqLZDVzrJzFrwahc4tXLt9DoHd"
),
"proofPurpose": "assertionMethod",
},
},

0 comments on commit 1f34063

Please sign in to comment.