Exemple #1
0
def test_create_request_with_content(
    client: Client,
    endorser: PrivateIdentity,
    mocked_requests_200: respx.MockTransport,
    entity: Entity,
) -> None:
    """Create endorsement request provided by a 3rd party endorser."""
    claims = [b"claim-1", b"claim-2"]

    # Create endorsement request with authorisation of endorser
    content, authorisation = endorser.endorse(entity, claims)

    # This will also add the subject holders authorisation
    client.put(
        entity,
        claims=claims,
        content=content,
        authorisations=[authorisation],
        # endorse=True # TODO - provide test that this does not have any effect
    )
    http_request, _ = mocked_requests_200["create_entity"].calls[0]

    request_id = json.loads(content.decode())["requestId"]
    assert http_request.url.path.rsplit("/", 1)[1] == request_id

    claims_header = json.loads(
        iov42_decode(http_request.headers["x-iov42-claims"]))
    assert claims_header == {}

    authorisations = json.loads(
        iov42_decode(http_request.headers["x-iov42-authorisations"].encode()))
    expected_identities = [a["identityId"] for a in authorisations]
    assert client.identity.identity_id in expected_identities
    assert endorser.identity_id in expected_identities
Exemple #2
0
def test_create_request_with_content_claims(
    client: Client,
    endorser: PrivateIdentity,
    mocked_requests_200: respx.MockTransport,
    entity: Entity,
) -> None:
    """Create endorsement request provided by a 3rd party endorser."""
    claims = [b"claim-1", b"claim-2"]

    # Create endorsement request with authorisation of endorser
    content, authorisation = endorser.endorse(entity, claims)

    # This will also add the subject holders authorisation
    client.put(
        entity,
        claims=claims,
        content=content,
        authorisations=[authorisation],
        create_claims=True
        # endorse=True # TODO - provide test that this does not have any effect
    )
    http_request, _ = mocked_requests_200["create_entity"].calls[0]

    claims_header = json.loads(
        iov42_decode(http_request.headers["x-iov42-claims"]))
    assert claims_header == {hashed_claim(c): c.decode() for c in claims}
def test_3rd_party_endorsements_on_new_claims(
    alice_client: Client,
    existing_asset: Asset,
    bob: PrivateIdentity,
) -> None:
    """Provide endorsements on someone elses claims which do not exist yet."""
    new_claims = [b"alice-claim-100", b"alice-claims-200"]
    content, authorisation = bob.endorse(existing_asset, new_claims)

    # Content and authorisation has to be handed over from the endorser to the
    # identity owning the asset. The asset owner creates the request to add the
    # claims with endorsements which implicitely adds also the owner's authorisation.
    response = alice_client.put(
        existing_asset,
        claims=new_claims,
        content=content,
        authorisations=[authorisation],
        create_claims=True,
    )

    for r in response.resources:  # type: ignore[union-attr]
        if "endorsements/" in r:
            assert bob.identity_id in r