From 1e0cc3c3793d3521f5684bc185303608ba05496f Mon Sep 17 00:00:00 2001 From: sklump Date: Tue, 25 Aug 2020 18:32:28 +0000 Subject: [PATCH] utf-8 encoding to byte strings Signed-off-by: sklump --- .../messaging/jsonld/create_verify_data.py | 2 +- .../messaging/jsonld/tests/test_routes.py | 62 +++++++++++++------ 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/aries_cloudagent/messaging/jsonld/create_verify_data.py b/aries_cloudagent/messaging/jsonld/create_verify_data.py index 69c9aafbc9..28c91a640e 100644 --- a/aries_cloudagent/messaging/jsonld/create_verify_data.py +++ b/aries_cloudagent/messaging/jsonld/create_verify_data.py @@ -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): diff --git a/aries_cloudagent/messaging/jsonld/tests/test_routes.py b/aries_cloudagent/messaging/jsonld/tests/test_routes.py index d78c07f1a6..e0642178f2 100644 --- a/aries_cloudagent/messaging/jsonld/tests/test_routes.py +++ b/aries_cloudagent/messaging/jsonld/tests/test_routes.py @@ -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,7 +28,10 @@ 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", @@ -37,10 +39,15 @@ async def test_verify_credential(self): ], "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", }, },