Example #1
0
async def test_get_connection_record(mock_agent_controller: AcaPyClient):
    pres_exchange = PresentationExchange(
        connection_id="3fa85f64-5717-4562-b3fc-2c963f66afa6",
        created_at="2021-09-15 13:49:47Z",
        proof_id="v1-abcd",
        presentation=None,
        presentation_request=indy_proof_request,
        role="prover",
        state="proposal-sent",
        protocol_version="v1",
        updated_at=None,
        verified="false",
    )
    conn_record = ConnRecord(connection_id=pres_exchange.connection_id)
    with when(mock_agent_controller.connection).get_connection(...).thenReturn(
        get(conn_record)
    ), when(Verifier).get_proof_record(...).thenReturn(get(pres_exchange)), patch(
        "app.generic.verifier.verifier_utils.get_connection_record",
        return_value=conn_record,
    ):
        assert (
            await get_connection_record(
                aries_controller=mock_agent_controller,
                connection_id=conn_record.connection_id,
            )
            == conn_record
        )
Example #2
0
async def test_assert_valid_verifier_x_no_public_did_no_invitation_key(
    mock_agent_controller: AcaPyClient,
):
    conn = ConnRecord(
        connection_id="a-connection-id",
    )

    when(mock_agent_controller.connection).get_connection(
        conn_id="a-connection-id"
    ).thenReturn(get(conn))

    # valid
    with patch(
        "app.generic.verifier.verifier_utils.assert_public_did",
        side_effect=Exception("Error"),
    ), patch("app.generic.verifier.verifier_utils.get_actor", return_value=actor):
        with pytest.raises(CloudApiException, match="Connection has no invitation key"):
            await assert_valid_verifier(
                aries_controller=mock_agent_controller,
                proof_request=SendProofRequest(
                    protocol_version=PresentProofProtocolVersion.v1,
                    connection_id="a-connection-id",
                    proof_request=indy_proof_request,
                ),
            )
Example #3
0
async def test_onboard_issuer_no_public_did(
    mock_agent_controller: AcaPyClient,
):
    endorser_controller = get_mock_agent_controller()

    when(acapy_wallet).get_public_did(controller=mock_agent_controller).thenRaise(
        CloudApiException(detail="Error")
    )
    when(acapy_wallet).create_did(mock_agent_controller).thenReturn(
        get(
            Did(
                did="WgWxqztrNooG92RXvxSTWv",
                verkey="WgWxqztrNooG92RXvxSTWvWgWxqztrNooG92RXvxSTWv",
            )
        )
    )

    when(acapy_ledger).register_nym_on_ledger(...).thenReturn(get())

    when(acapy_ledger).accept_taa_if_required(...).thenReturn(get())
    when(acapy_wallet).set_public_did(...).thenReturn(get())

    when(acapy_wallet).get_public_did(controller=endorser_controller).thenReturn(
        get(Did(did="EndorserController", verkey="EndorserVerkey"))
    )

    when(endorser_controller.out_of_band).create_invitation(...).thenReturn(
        get(InvitationRecord(invitation=InvitationMessage()))
    )
    when(mock_agent_controller.out_of_band).receive_invitation(...).thenReturn(
        get(ConnRecord())
    )

    when(mock_agent_controller.endorse_transaction).set_endorser_role(...).thenReturn(
        get()
    )
    when(mock_agent_controller.endorse_transaction).set_endorser_info(...).thenReturn(
        get()
    )

    # Mock event listener
    when(onboarding).start_listener(...).thenReturn(get(mock_start_listener))
    onboard_result = await onboarding.onboard_issuer(
        name="issuer_name",
        endorser_controller=endorser_controller,
        issuer_controller=mock_agent_controller,
        issuer_wallet_id="issuer_wallet_id",
    )

    assert_that(onboard_result).has_did("did:sov:WgWxqztrNooG92RXvxSTWv")
    verify(acapy_wallet).create_did(mock_agent_controller)
    verify(acapy_ledger).register_nym_on_ledger(
        endorser_controller,
        did="WgWxqztrNooG92RXvxSTWv",
        verkey="WgWxqztrNooG92RXvxSTWvWgWxqztrNooG92RXvxSTWv",
        alias="issuer_name",
    )
    verify(acapy_ledger).accept_taa_if_required(mock_agent_controller)
    verify(acapy_wallet).set_public_did(mock_agent_controller, "WgWxqztrNooG92RXvxSTWv")
Example #4
0
async def test_onboard_issuer_public_did_exists(
    mock_agent_controller: AcaPyClient,
):
    when(acapy_wallet).get_public_did(controller=mock_agent_controller).thenReturn(
        get(
            Did(
                did="WgWxqztrNooG92RXvxSTWv",
                verkey="WgWxqztrNooG92RXvxSTWvWgWxqztrNooG92RXvxSTWv",
            )
        )
    )

    endorser_controller = get_mock_agent_controller()

    when(endorser_controller.out_of_band).create_invitation(...).thenReturn(
        get(InvitationRecord(invitation=InvitationMessage()))
    )
    when(mock_agent_controller.out_of_band).receive_invitation(...).thenReturn(
        get(ConnRecord())
    )

    when(acapy_wallet).get_public_did(controller=endorser_controller).thenReturn(
        get(Did(did="EndorserController", verkey="EndorserVerkey"))
    )

    when(mock_agent_controller.endorse_transaction).set_endorser_role(...).thenReturn(
        get()
    )
    when(mock_agent_controller.endorse_transaction).set_endorser_info(...).thenReturn(
        get()
    )

    # Mock event listener
    when(onboarding).start_listener(...).thenReturn(get(mock_start_listener))
    onboard_result = await onboarding.onboard_issuer(
        name="issuer_name",
        endorser_controller=endorser_controller,
        issuer_controller=mock_agent_controller,
        issuer_wallet_id="issuer_wallet_id",
    )

    assert_that(onboard_result).has_did("did:sov:WgWxqztrNooG92RXvxSTWv")
    verify(acapy_wallet, times=0).create_did(...)
    verify(endorser_controller.out_of_band).create_invitation(
        auto_accept=True,
        body=InvitationCreateRequest(
            handshake_protocols=["https://didcomm.org/didexchange/1.0"],
            use_public_did=True,
        ),
    )
    verify(mock_agent_controller.out_of_band).receive_invitation(
        auto_accept=True,
        use_existing_connection=True,
        body=InvitationMessage(),
        alias="endorser",
    )
Example #5
0
async def test_assert_valid_prover_x_invalid_schemas(
    mock_agent_controller: AcaPyClient,
):
    pres_exchange = PresentationExchange(
        connection_id="3fa85f64-5717-4562-b3fc-2c963f66afa6",
        created_at="2021-09-15 13:49:47Z",
        proof_id="v1-abcd",
        presentation=None,
        presentation_request=indy_proof_request,
        role="prover",
        state="proposal-sent",
        protocol_version="v1",
        updated_at=None,
        verified="false",
    )
    conn_record = ConnRecord(
        connection_id=pres_exchange.connection_id, their_public_did="xxx"
    )

    prover = mock(Verifier)

    when(prover).get_proof_record(
        controller=mock_agent_controller, proof_id=pres_exchange.proof_id
    ).thenReturn(get(pres_exchange))
    when(mock_agent_controller.connection).get_connection(
        conn_id=pres_exchange.connection_id
    ).thenReturn(get(conn_record))

    with patch(
        "app.generic.verifier.verifier_utils.get_actor", return_value=actor
    ), patch(
        "app.generic.verifier.verifier_utils.get_schema_ids",
        return_value=["did:schema:456"],
    ), patch(
        "app.generic.verifier.verifier_utils.get_trust_registry_schemas",
        return_value=["did:schema:123"],
    ):
        with pytest.raises(
            CloudApiException,
            match="Presentation is using schemas not registered in trust registry",
        ):
            await assert_valid_prover(
                aries_controller=mock_agent_controller,
                presentation=AcceptProofRequest(
                    proof_id=pres_exchange.proof_id, presentation_spec=indy_pres_spec
                ),
                prover=prover,
            )
Example #6
0
async def test_assert_valid_prover_x_actor_invalid_role(
    mock_agent_controller: AcaPyClient,
):
    actor = Actor(
        id="abcde",
        name="Flint",
        roles=["issuer"],
        did="did:sov:abcde",
        didcomm_invitation=None,
    )

    pres_exchange = PresentationExchange(
        connection_id="3fa85f64-5717-4562-b3fc-2c963f66afa6",
        created_at="2021-09-15 13:49:47Z",
        proof_id="v1-abcd",
        presentation=None,
        presentation_request=indy_proof_request,
        role="prover",
        state="proposal-sent",
        protocol_version="v1",
        updated_at=None,
        verified="false",
    )
    conn_record = ConnRecord(
        connection_id=pres_exchange.connection_id, their_public_did="xxx"
    )

    prover = mock(Verifier)

    when(prover).get_proof_record(
        controller=mock_agent_controller, proof_id=pres_exchange.proof_id
    ).thenReturn(get(pres_exchange))
    when(mock_agent_controller.connection).get_connection(
        conn_id=pres_exchange.connection_id
    ).thenReturn(get(conn_record))

    # valid
    with patch("app.generic.verifier.verifier_utils.get_actor", return_value=actor):
        with pytest.raises(
            CloudApiException, match="Actor is missing required role 'verifier'"
        ):
            await assert_valid_prover(
                aries_controller=mock_agent_controller,
                presentation=AcceptProofRequest(
                    proof_id=pres_exchange.proof_id, presentation_spec=indy_pres_spec
                ),
                prover=prover,
            )
Example #7
0
async def test_assert_valid_verifier_x_not_verifier(
    mock_agent_controller: AcaPyClient,
):
    actor = Actor(
        id="abcde",
        name="Flint",
        roles=["issuer"],
        did="did:sov:abcde",
        didcomm_invitation=None,
    )

    conn = ConnRecord(
        connection_id="a-connection-id",
        invitation_key="H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV",
    )

    when(mock_agent_controller.connection).get_connection(
        conn_id="a-connection-id"
    ).thenReturn(get(conn))

    # valid
    with patch(
        "app.generic.verifier.verifier_utils.assert_public_did",
        side_effect=Exception("Error"),
    ), patch("app.generic.verifier.verifier_utils.get_actor", return_value=actor):
        with pytest.raises(
            CloudApiException,
            match="Flint is not a valid verifier in the trust registry.",
        ):
            await assert_valid_verifier(
                aries_controller=mock_agent_controller,
                proof_request=SendProofRequest(
                    protocol_version=PresentProofProtocolVersion.v1,
                    connection_id="a-connection-id",
                    proof_request=indy_proof_request,
                ),
            )
Example #8
0
async def test_assert_valid_verifier_invitation_key(mock_agent_controller: AcaPyClient):
    conn = ConnRecord(
        connection_id="a-connection-id",
        invitation_key="H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV",
    )

    when(mock_agent_controller.connection).get_connection(
        conn_id="a-connection-id"
    ).thenReturn(get(conn))

    # valid
    with patch(
        "app.generic.verifier.verifier_utils.assert_public_did",
        side_effect=Exception("Error"),
    ), patch("app.generic.verifier.verifier_utils.get_actor", return_value=actor):

        await assert_valid_verifier(
            aries_controller=mock_agent_controller,
            proof_request=SendProofRequest(
                protocol_version=PresentProofProtocolVersion.v1,
                connection_id="a-connection-id",
                proof_request=indy_proof_request,
            ),
        )
Example #9
0
async def test_assert_valid_prover_x_no_public_did_no_invitation_key(
    mock_agent_controller: AcaPyClient,
):
    pres_exchange = PresentationExchange(
        connection_id="3fa85f64-5717-4562-b3fc-2c963f66afa6",
        created_at="2021-09-15 13:49:47Z",
        proof_id="v1-abcd",
        presentation=None,
        presentation_request=indy_proof_request,
        role="prover",
        state="proposal-sent",
        protocol_version="v1",
        updated_at=None,
        verified="false",
    )
    conn_record = ConnRecord(connection_id=pres_exchange.connection_id)

    prover = mock(Verifier)

    when(prover).get_proof_record(
        controller=mock_agent_controller, proof_id=pres_exchange.proof_id
    ).thenReturn(get(pres_exchange))
    when(mock_agent_controller.connection).get_connection(
        conn_id=pres_exchange.connection_id
    ).thenReturn(get(conn_record))

    with pytest.raises(
        CloudApiException, match="Could not determine did of the verifier"
    ):
        await assert_valid_prover(
            aries_controller=mock_agent_controller,
            presentation=AcceptProofRequest(
                proof_id=pres_exchange.proof_id, presentation_spec=indy_pres_spec
            ),
            prover=prover,
        )
Example #10
0
async def test_assert_valid_prover_public_did(mock_agent_controller: AcaPyClient):

    pres_exchange = PresentationExchange(
        connection_id="3fa85f64-5717-4562-b3fc-2c963f66afa6",
        created_at="2021-09-15 13:49:47Z",
        proof_id="v1-abcd",
        presentation=None,
        presentation_request=indy_proof_request,
        role="prover",
        state="proposal-sent",
        protocol_version="v1",
        updated_at=None,
        verified="false",
    )
    conn_record = ConnRecord(
        connection_id=pres_exchange.connection_id, their_public_did="did:sov:123"
    )

    presentation = IndyPresSpec(
        self_attested_attributes={},
        requested_attributes={
            "group_name": IndyRequestedCredsRequestedAttr(
                revealed=False, cred_id="first-unrevealed-cred-id"
            ),
            "another_group_name": IndyRequestedCredsRequestedAttr(
                revealed=True, cred_id="first-revealed-cred-id"
            ),
        },
        requested_predicates={
            "pred_group_name": IndyRequestedCredsRequestedPred(
                cred_id="first-revealed-pred-cred-id"
            )
        },
    )

    prover = mock(Verifier)

    when(prover).get_proof_record(
        controller=mock_agent_controller, proof_id=pres_exchange.proof_id
    ).thenReturn(get(pres_exchange))
    when(mock_agent_controller.connection).get_connection(
        conn_id=pres_exchange.connection_id
    ).thenReturn(get(conn_record))

    with patch(
        "app.generic.verifier.verifier_utils.get_actor", return_value=actor
    ), patch(
        "app.generic.verifier.verifier_utils.get_schema_ids",
        return_value=["did:schema:123"],
    ), patch(
        "app.generic.verifier.verifier_utils.get_trust_registry_schemas",
        return_value=["did:schema:123"],
    ):
        # Should not throw
        await assert_valid_prover(
            aries_controller=mock_agent_controller,
            presentation=AcceptProofRequest(
                proof_id=pres_exchange.proof_id, presentation_spec=presentation
            ),
            prover=prover,
        )
Example #11
0
def to_connections_model(item: RedisItem) -> Connection:
    conn_record = ConnRecord(**item["payload"])
    conn_record = conn_record_to_connection(connection_record=conn_record)

    return conn_record
    protocol_version=PresentProofProtocolVersion.v2.value,
    presentation={},
    role="prover",
    state="presentation-sent",
    verified=False,
)

actor = Actor(
    id="abcde",
    name="Flint",
    roles=["verifier"],
    did="did:sov:2cpBmR3FqGKWi5EyUbpRY8",
    didcomm_invitation=None,
)
conn_record = ConnRecord(
    connection_id="abcde",
    invitation_key="H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV",
)


@pytest.mark.asyncio
async def test_send_proof_request_v1(mock_agent_controller: AcaPyClient):
    # V1
    when(VerifierV1).send_proof_request(...).thenReturn(
        get(presentation_exchange_record_1))

    when(mock_agent_controller.connection).get_connection(
        conn_id="abcde").thenReturn(get(conn_record))

    when(verifier_utils).get_actor(
        did="did:key:z6MkvVT4kkAmhTb9srDHScsL1q7pVKt9cpUJUah2pKuYh4As"
    ).thenReturn(get(actor))