Ejemplo n.º 1
0
    async def test_request_credential(self):
        mock = async_mock.MagicMock()
        record = ConnectionRecord(state=ConnectionRecord.STATE_ACTIVE)
        context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        storage = BasicStorage()
        context.injector.bind_instance(BaseStorage, storage)
        connection_id = await record.save(context)
        mock.json = async_mock.CoroutineMock(
            return_value={
                "connection_id": connection_id,
                "credential_type": "TYPE_EXAMPLE",
                "credential_values": {
                    "test1": "1"
                },
            })

        mock.app = {
            "request_context": context,
            "outbound_message_router": async_mock.CoroutineMock(),
        }

        with async_mock.patch.object(
                test_module, "CredentialExchangeRecord",
                autospec=True) as mock_conn_rec, async_mock.patch.object(
                    test_module.web, "json_response") as mock_response:

            await test_module.request_credential(mock)
            mock_response.assert_called_once()
    async def test_is_saving_record(self):
        context = RequestContext()
        storage = BasicStorage()

        context.injector.bind_instance(BaseStorage, storage)
        context.connection_ready = True
        context.message = CredentialRequest(
            credential={
                "credential_type": "TEST",
                "credential_values": {
                    "test": "one",
                    "value": "two"
                },
            })

        responder = MockResponder()
        responder.connection_id = "1234"

        handler_inst = CredentialRequestHandler()
        await handler_inst.handle(context, responder)

        assert len(responder.messages) == 0
        assert 1 == len(responder.webhooks)

        id = responder.webhooks[0][1]["credential_exchange_id"]
        exchange = await CredentialExchangeRecord.retrieve_by_id(context, id)
        assert exchange != None
        assert exchange.connection_id == responder.connection_id
        assert exchange.state == CredentialExchangeRecord.STATE_REQUEST_RECEIVED
        assert exchange.credential_request == context.message.credential
    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
Ejemplo n.º 5
0
 async def setUp(self):
     self.context = RequestContext(
         base_context=InjectionContext(enforce_typing=False)
     )
     self.context.connection_ready = True
     self.context.connection_record = ConnectionRecord(connection_id="conn-id")
     self.context.message_receipt = MessageReceipt(sender_verkey=TEST_VERKEY)
     self.context.injector.bind_instance(BaseStorage, BasicStorage())
 async def setUp(self):
     self.context = RequestContext(base_context=InjectionContext(
         enforce_typing=False))
     self.context.message_receipt = MessageReceipt(
         sender_verkey=TEST_VERKEY)
     self.storage = BasicStorage()
     self.context.injector.bind_instance(BaseStorage, self.storage)
     self.manager = RoutingManager(self.context)
     assert self.manager.context
    async def setUp(self):
        self.storage = BasicStorage()

        self.context = RequestContext(
            base_context=InjectionContext(enforce_typing=False)
        )
        self.context.injector.bind_instance(BaseStorage, self.storage)

        self.context.connection_ready = True
        self.context.message = Forward(to="sample-did", msg={"msg": "sample-message"})
    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}""")
Ejemplo n.º 9
0
    def create_default_context(self):
        context = InjectionContext()
        storage = BasicStorage()
        responder = MockResponder()

        context.injector.bind_instance(BaseStorage, storage)

        context.connection_ready = True
        context.connection_record = ConnectionRecord(
            connection_id=self.connection_id)

        return [context, storage, responder]
Ejemplo n.º 10
0
    async def test_discovery_response_handler(self):
        context = RequestContext()
        storage = BasicStorage()
        responder = MockResponder()

        context.injector.bind_instance(BaseStorage, storage)

        context.connection_ready = True
        context.connection_record = ConnectionRecord(connection_id=self.connection_id)

        context.message = DiscoveryResponse(services=[self.service])

        handler = DiscoveryResponseHandler()
        await handler.handle(context, responder)
Ejemplo n.º 11
0
    async def testSaveAndRetrieve(self):
        context = InjectionContext()
        storage = BasicStorage()
        context.injector.bind_instance(BaseStorage, storage)

        record = SchemaExchangeRecord(
            payload=self.payload,
            author=self.author,
        )
        record_id = await record.save(context)
        assert record_id == self.hash_id
        self.assert_record(record)

        query = await SchemaExchangeRecord.retrieve_by_id(
            context, self.hash_id)
        self.assert_record(query)
        assert query == record
Ejemplo n.º 12
0
    async def testSaveAndRetrieve(self):
        context = InjectionContext()
        storage = BasicStorage()
        context.injector.bind_instance(BaseStorage, storage)

        record = SchemaExchangeRequestRecord(
            payload=self.payload,
            state=self.state,
            connection_id=self.connection_id,
            author="other",
        )

        record_id = await record.save(context)
        assert record_id != 0
        assert record.payload == self.payload
        assert record.connection_id == self.connection_id
        assert record.state == self.state

        query = await SchemaExchangeRequestRecord.retrieve_by_id(
            context, record_id)
        assert query == record
    async def setUp(self):
        self.storage = BasicStorage()

        self.context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        self.context.injector.bind_instance(BaseStorage, self.storage)

        self.context.connection_ready = True
        self.context.message = Invitation(
            invitation=ConnectionInvitation(
                label=TEST_LABEL,
                did=TEST_DID,
                recipient_keys=[TEST_VERKEY],
                endpoint=TEST_ENDPOINT,
                routing_keys=[TEST_ROUTE_VERKEY],
                image_url=TEST_IMAGE_URL,
            ),
            message="Hello World",
        )
        self.context.connection_record = async_mock.MagicMock(
            connection_id="dummy")
Ejemplo n.º 14
0
    async def test_discovery_handler(self):
        context = RequestContext()
        storage = BasicStorage()
        responder = MockResponder()

        context.injector.bind_instance(BaseStorage, storage)

        record = ServiceRecord(
            consent_schema=self.consent_schema,
            service_schema=self.service_schema,
            label=self.label,
        )
        service_id = await record.save(context=context)

        context.message = Discovery()

        handler = DiscoveryHandler()
        await handler.handle(context, responder)
        assert len(responder.messages) == 1
        assert isinstance(responder.messages[0][0], DiscoveryResponse)
        assert service_id == responder.messages[0][0].services[0]["service_id"]
def manager() -> RoutingManager:
    ctx = RequestContext()
    ctx.message_delivery = MessageDelivery(sender_verkey=TEST_VERKEY)
    ctx.injector.bind_instance(BaseStorage, BasicStorage())
    return RoutingManager(ctx)
def request_context() -> RequestContext:
    ctx = RequestContext()
    ctx.message_delivery = MessageDelivery(sender_verkey=TEST_VERKEY)
    ctx.injector.bind_instance(BaseStorage, BasicStorage())
    yield ctx
Ejemplo n.º 17
0
    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)
Ejemplo n.º 18
0
    def create_default_context(self):
        context = InjectionContext()
        storage = BasicStorage()
        context.injector.bind_instance(BaseStorage, storage)

        return [context, storage]
def store():
    yield BasicStorage()
Ejemplo n.º 20
0
 def setUp(self):
     self.storage = BasicStorage()
     self.context = InjectionContext(enforce_typing=False)
     self.context.injector.bind_instance(BaseStorage, self.storage)