def setUp(self):
        self.storage = BasicStorage()
        self.cache = BasicCache()
        self.wallet = BasicWallet()
        self.responder = MockResponder()
        self.responder.send = async_mock.CoroutineMock()

        self.context = InjectionContext(enforce_typing=False)
        self.context.injector.bind_instance(BaseStorage, self.storage)
        self.context.injector.bind_instance(BaseWallet, self.wallet)
        self.context.injector.bind_instance(BaseResponder, self.responder)
        self.context.injector.bind_instance(BaseCache, self.cache)
        self.context.injector.bind_instance(BaseLedger, async_mock.MagicMock())
        self.context.update_settings({
            "default_endpoint":
            "http://aries.ca/endpoint",
            "default_label":
            "This guy",
            "additional_endpoints": ["http://aries.ca/another-endpoint"],
            "debug.auto_accept_invites":
            True,
            "debug.auto_accept_requests":
            True,
        })

        self.manager = OutOfBandManager(self.context)
        self.test_conn_rec = ConnectionRecord(
            my_did=self.test_did,
            their_did=self.test_target_did,
            their_role=None,
            state=ConnectionRecord.STATE_ACTIVE,
        )
    async def setUp(self):
        self.context: InjectionContext = InjectionContext()
        storage = BasicStorage()
        self.wallet = BasicWallet()
        await self.wallet.create_public_did()
        public_did = await self.wallet.get_public_did()
        assert public_did != None
        self.holder = PDSHolder(self.wallet, storage, self.context)
        issuer = PDSIssuer(self.wallet)

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

        self.context.settings.set_value(
            "personal_storage_registered_types",
            {"local": "aries_cloudagent.pdstorage_thcf.local.LocalPDS"},
        )

        pds = LocalPDS()
        self.context.injector.bind_instance(BasePDS, pds)
        new_storage = SavedPDS(state=SavedPDS.ACTIVE)
        await new_storage.save(self.context)

        self.credential = await create_test_credential(issuer)
        self.cred_id = await self.holder.store_credential({}, self.credential,
                                                          {})
        requested_credentials["credential_id"] = self.cred_id
    async def test_properties(self, wallet):
        assert wallet.name
        assert wallet.type == "basic"
        assert wallet.handle is None
        none_wallet = BasicWallet()
        assert none_wallet.name is None

        assert "BasicWallet" in str(wallet)
        assert wallet.created
 async def setUp(self):
     self.wallet = BasicWallet()
     self.example_schema = {
         "@context": [
             "https://www.w3.org/2018/credentials/v1",
             "https://www.w3.org/2018/credentials/examples/v1",
         ],
         "type": ["VerifiablePresentation"],
         "verifiableCredential": [{}],
     }
 async def test_make_model(self):
     connection_response = ConnectionResponse(connection=ConnectionDetail(
         did=self.test_did, did_doc=self.make_did_doc()))
     wallet = BasicWallet()
     key_info = await wallet.create_signing_key()
     await connection_response.sign_field("connection", key_info.verkey,
                                          wallet)
     data = connection_response.serialize()
     model_instance = ConnectionResponse.deserialize(data)
     assert type(model_instance) is type(connection_response)
Beispiel #6
0
 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,
     }
    async def test_is_handler_saving_record(self):
        context = RequestContext()
        # wallet is required for issuer to sign stuff cause it holds keys
        wallet = BasicWallet()
        # storage is required to save exchange record and save credential
        storage = BasicStorage(wallet)
        # issuer required to create credential
        issuer = PDSIssuer(wallet)
        # holder requiered to save credential
        holder = PDSHolder(context)

        context.injector.bind_instance(BaseWallet, wallet)
        context.injector.bind_instance(BaseStorage, storage)
        context.injector.bind_instance(BaseIssuer, issuer)
        context.injector.bind_instance(BaseHolder, holder)

        record = CredentialExchangeRecord(
            connection_id=connection_id,
            initiator=CredentialExchangeRecord.INITIATOR_SELF,
            role=CredentialExchangeRecord.ROLE_HOLDER,
            state=CredentialExchangeRecord.STATE_REQUEST_SENT,
            thread_id=thread_id,
            credential_request=credential_request,
        )
        await record.save(context)

        credential = await create_credential(context,
                                             credential_request,
                                             their_public_did="1234-theirdid")
        context.message: CredentialIssue = CredentialIssue(
            credential=credential)
        context.message.assign_thread_id(thread_id)
        context.connection_ready = True

        handler_inst = CredentialIssueHandler()
        responder = MockResponder()
        responder.connection_id = connection_id

        await handler_inst.handle(context, responder)

        credential_id = responder.webhooks[0][1]["credential_id"]
        assert credential_id
        credential = await holder.get_credential(credential_id)
        credential = json.loads(credential)
        assert credential["credentialSubject"]

        for key in credential_request["credential_values"]:
            if (credential["credentialSubject"][key] !=
                    credential_request["credential_values"][key]):
                raise Exception(
                    f"""Requested Credential VALUES differ from Issued Credential,
                    RequestedCredential: {credential_request},
                    IssuedCredential: {credential}""")
 def setUp(self):
     self.storage = BasicStorage()
     self.context = InjectionContext()
     self.context.injector.bind_instance(BaseStorage, self.storage)
     self.context.injector.bind_instance(BaseWallet, BasicWallet())
     self.manager = ConnectionManager(self.context)
     self.test_info = ConnectionRecord(
         my_did=self.test_did,
         their_did=self.test_target_did,
         their_role=None,
         state=ConnectionRecord.STATE_ACTIVE,
     )
async def basic_wallet():
    wallet = BasicWallet()
    await wallet.open()
    yield wallet
    await wallet.close()
async def wallet():
    wallet = BasicWallet({"name": "basic"})
    await wallet.open()
    yield wallet
    await wallet.close()
    async def test_save_retrieve_delete_connection_menu(self):
        self.storage = BasicStorage()
        self.context = InjectionContext()
        self.context.injector.bind_instance(BaseStorage, self.storage)
        self.context.injector.bind_instance(BaseWallet, BasicWallet())

        self.responder = MockResponder()
        self.context.injector.bind_instance(test_module.BaseResponder,
                                            self.responder)

        menu = test_module.Menu(
            title="title",
            description="description",
            errormsg=None,
            options=[
                MenuOption(
                    name=f"name-{i}",
                    title=f"option-title-{i}",
                    description=f"option-description-{i}",
                    disabled=bool(i % 2),
                    form=MenuForm(
                        title=f"form-title-{i}",
                        description=f"form-description-{i}",
                        params=[
                            MenuFormParam(
                                name=f"param-name-{i}-{j}",
                                title=f"param-title-{i}-{j}",
                                default=f"param-default-{i}-{j}",
                                description=f"param-description-{i}-{j}",
                                input_type="int",
                                required=bool((i + j) % 2),
                            ) for j in range(2)
                        ],
                    ),
                ) for i in range(3)
            ],
        )
        connection_id = "connid"

        for i in range(2):  # once to add, once to update
            await test_module.save_connection_menu(menu, connection_id,
                                                   self.context)

            webhooks = self.responder.webhooks
            assert len(webhooks) == 1
            (result, target) = webhooks[0]
            assert result == "actionmenu"
            assert target["connection_id"] == connection_id
            assert target["menu"] == menu.serialize()
            self.responder.webhooks.clear()

        # retrieve connection menu
        assert (await test_module.retrieve_connection_menu(
            connection_id, self.context)).serialize() == menu.serialize()

        # delete connection menu
        await test_module.save_connection_menu(None, connection_id,
                                               self.context)

        webhooks = self.responder.webhooks
        assert len(webhooks) == 1
        (result, target) = webhooks[0]
        assert result == "actionmenu"
        assert target == {"connection_id": connection_id, "menu": None}
        self.responder.webhooks.clear()

        # retrieve no menu
        assert (await test_module.retrieve_connection_menu(
            connection_id, self.context) is None)
    async def setUp(self):
        self.context: InjectionContext = InjectionContext()

        wallet = BasicWallet()

        self.verifier = PDSVerifier(wallet)