示例#1
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,
        )
示例#2
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,
            )
示例#3
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,
            )
async def test_accept_proof_request(mock_agent_controller: AcaPyClient):
    when(mock_agent_controller.present_proof_v1_0).send_presentation(
        ...).thenReturn(get(v10_presentation_exchange_records[0]))

    accepted_proof_request = await VerifierV1.accept_proof_request(
        mock_agent_controller,
        proof_request=AcceptProofRequest(
            proof_id="v1-123",
            presentation_spec=IndyPresSpec(
                requested_attributes={},
                requested_predicates={},
                self_attested_attributes={},
            ),
        ),
    )

    assert isinstance(accepted_proof_request, PresentationExchange)
示例#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
async def test_accept_proof_request_v1(
    issue_credential_to_alice: CredentialExchange,
    alice_member_client: AsyncClient,
    acme_client: AsyncClient,
    acme_and_alice_connection: AcmeAliceConnect,
):
    response = await acme_client.post(
        BASE_PATH + "/send-request",
        json={
            "connection_id": acme_and_alice_connection["acme_connection_id"],
            "protocol_version": "v1",
            "proof_request": indy_proof_request.dict(),
        },
    )
    response.raise_for_status()
    acme_exchange = response.json()
    acme_proof_id = acme_exchange["proof_id"]

    assert check_webhook_state(
        client=alice_member_client,
        filter_map={"state": "request-received"},
        topic="proofs",
        max_duration=120,
    )
    proof_records_alice = await alice_member_client.get(BASE_PATH + "/proofs")
    alice_proof_id = proof_records_alice.json()[0]["proof_id"]

    requested_credentials = await alice_member_client.get(
        f"/generic/verifier/proofs/{alice_proof_id}/credentials")

    referent = requested_credentials.json()[0]["cred_info"]["referent"]
    indy_request_attrs = IndyRequestedCredsRequestedAttr(cred_id=referent,
                                                         revealed=True)
    proof_accept = AcceptProofRequest(
        proof_id=alice_proof_id,
        presentation_spec=IndyPresSpec(
            requested_attributes={"0_speed_uuid": indy_request_attrs},
            requested_predicates={},
            self_attested_attributes={},
        ),
    )

    response = await alice_member_client.post(
        BASE_PATH + "/accept-request",
        json=proof_accept.dict(),
    )
    assert check_webhook_state(
        client=alice_member_client,
        filter_map={
            "state": "done",
            "proof_id": alice_proof_id
        },
        topic="proofs",
        max_duration=120,
    )
    assert check_webhook_state(
        client=acme_client,
        filter_map={
            "state": "done",
            "proof_id": acme_proof_id
        },
        topic="proofs",
        max_duration=120,
    )

    result = response.json()

    pres_exchange_result = PresentationExchange(**result)
    assert isinstance(pres_exchange_result, PresentationExchange)
    assert response.status_code == 200
示例#8
0
async def test_accept_proof_request_v2(
    issue_credential_to_alice: CredentialExchange,
    alice_member_client: AsyncClient,
    acme_client: AsyncClient,
    alice_tenant: Any,
    acme_tenant: Any,
    credential_definition_id: str,
    acme_and_alice_connection: AcmeAliceConnect,
):
    wait_for_event, _ = await start_listener(
        topic="proofs", wallet_id=alice_tenant["tenant_id"])

    response = await acme_client.post(
        BASE_PATH + "/send-request",
        json={
            "connection_id": acme_and_alice_connection["acme_connection_id"],
            "protocol_version": "v2",
            # Custom proof request because v2 doesn't support proof request without restrictions
            # see: https://github.com/hyperledger/aries-cloudagent-python/issues/1755
            "proof_request": {
                "name": "Proof Request",
                "version": "1.0.0",
                "requested_attributes": {
                    "0_speed_uuid": {
                        "name":
                        "speed",
                        "restrictions": [{
                            "cred_def_id":
                            credential_definition_id
                        }],
                    }
                },
                "requested_predicates": {},
            },
        },
    )
    response.raise_for_status()
    acme_exchange = response.json()
    acme_proof_id = acme_exchange["proof_id"]

    payload = await wait_for_event(
        filter_map={
            "state": "request-received",
            "connection_id": acme_and_alice_connection["alice_connection_id"],
        })

    alice_proof_id = payload["proof_id"]

    requested_credentials = await alice_member_client.get(
        f"/generic/verifier/proofs/{alice_proof_id}/credentials")

    referent = requested_credentials.json()[0]["cred_info"]["referent"]
    indy_request_attrs = IndyRequestedCredsRequestedAttr(cred_id=referent,
                                                         revealed=True)
    proof_accept = AcceptProofRequest(
        proof_id=alice_proof_id,
        presentation_spec=IndyPresSpec(
            requested_attributes={"0_speed_uuid": indy_request_attrs},
            requested_predicates={},
            self_attested_attributes={},
        ),
    )

    wait_for_event, _ = await start_listener(
        topic="proofs", wallet_id=acme_tenant["tenant_id"])

    response = await alice_member_client.post(
        BASE_PATH + "/accept-request",
        json=proof_accept.dict(),
    )

    await wait_for_event(filter_map={
        "proof_id": acme_proof_id,
        "state": "done",
        "verified": True
    })

    result = response.json()

    pres_exchange_result = PresentationExchange(**result)
    assert isinstance(pres_exchange_result, PresentationExchange)
    assert response.status_code == 200