コード例 #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
        )
コード例 #2
0
async def test_assert_valid_prover_x_no_connection_id(
    mock_agent_controller: AcaPyClient,
):
    pres_exchange = PresentationExchange(
        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",
    )

    prover = mock(Verifier)

    when(prover).get_proof_record(
        controller=mock_agent_controller, proof_id=pres_exchange.proof_id
    ).thenReturn(get(pres_exchange))

    with pytest.raises(
        CloudApiException, match="No connection id associated with proof request."
    ):
        assert await assert_valid_prover(
            aries_controller=mock_agent_controller,
            presentation=AcceptProofRequest(
                proof_id=pres_exchange.proof_id, presentation_spec=indy_pres_spec
            ),
            prover=prover,
        )
コード例 #3
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,
            )
コード例 #4
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,
            )
コード例 #5
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,
        )
コード例 #6
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,
        )
コード例 #7
0
    PresentProofProtocolVersion, )
from app.tests.verifier.test_verifier_utils import (
    indy_proof_request,
    indy_pres_spec,
)
from app.tests.util.mock import get
from shared_models import PresentationExchange

from app.facades.trust_registry import Actor

presentation_exchange_record_1 = PresentationExchange(
    connection_id="abcde",
    created_at="2021-11-22 11:37:45.179595Z",
    updated_at="2021-11-22 11:37:45.179595Z",
    proof_id="abcde",
    protocol_version=PresentProofProtocolVersion.v1.value,
    presentation={},
    role="prover",
    state="presentation-sent",
    verified=False,
)

presentation_exchange_record_2 = PresentationExchange(
    connection_id="abcde",
    created_at="2021-11-22 11:37:45.179595Z",
    updated_at="2021-11-22 11:37:45.179595Z",
    proof_id="abcde",
    protocol_version=PresentProofProtocolVersion.v2.value,
    presentation={},
    role="prover",
    state="presentation-sent",