Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json ld non ascii #687

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aries_cloudagent/messaging/jsonld/create_verify_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
62 changes: 42 additions & 20 deletions aries_cloudagent/messaging/jsonld/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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",
Expand All @@ -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"
),
},
},
}
Expand All @@ -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": [
Expand All @@ -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",
},
},
Expand Down