示例#1
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}
示例#2
0
def test_create_asset_claims_with_endorsement(alice_client: Client,
                                              existing_asset: Asset) -> None:
    """Create asset claims and (self-) endorsements on an unique asset all at once."""
    claims = [b"claim-1", b"claim-2"]

    response = alice_client.put(existing_asset,
                                claims=claims,
                                endorse=True,
                                create_claims=True)

    prefix = "/".join((
        "/api/v1/asset-types",
        existing_asset.asset_type_id,
        "assets",
        existing_asset.asset_id,
        "claims",
    ))
    # Affected resources: for each endorsements we also created the claim.
    assert len(
        response.resources) == 2 * len(claims)  # type: ignore[union-attr]
    for c in [hashed_claim(c) for c in claims]:
        assert "/".join(
            (prefix, c)) in response.resources  # type: ignore[union-attr]
        assert ("/".join(
            (prefix, c, "endorsements", alice_client.identity.identity_id))
                in response.resources  # type: ignore[union-attr]
                )
示例#3
0
def test_create_identity_claims(alice_client: Client) -> None:
    """Alice creates claims against herself."""
    claims = [b"alice-claim-3", b"alice-claim-4"]

    response = alice_client.put(alice_client.identity.public_identity,
                                claims=claims)

    prefix = "/".join((
        "/api/v1/identities",
        alice_client.identity.identity_id,
        "claims",
    ))
    assert len(response.resources) == len(claims)  # type: ignore[union-attr]
    for c in [hashed_claim(c) for c in claims]:
        assert "/".join(
            (prefix, c)) in response.resources  # type: ignore[union-attr]
示例#4
0
def test_claims_header(
    client: Client,
    mocked_requests_200: respx.MockTransport,
    entity: Entity,
    endorse: bool,
    create_claims: bool,
) -> None:
    """Request to create claims/endorsements against an entity contains 'x-iov42-claims' header."""
    claims = [b"claim-1"]
    _ = client.put(entity,
                   claims=claims,
                   endorse=endorse,
                   create_claims=create_claims)
    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}
示例#5
0
def test_create_asset_type_claims(alice_client: Client,
                                  existing_asset_type_id: str) -> None:
    """Create asset claims on an asset type."""
    claims = [b"claim-1", b"claim-2"]

    response = alice_client.put(AssetType(existing_asset_type_id),
                                claims=claims)

    prefix = "/".join((
        "/api/v1/asset-types",
        existing_asset_type_id,
        "claims",
    ))
    assert len(response.resources) == len(claims)  # type: ignore[union-attr]
    for c in [hashed_claim(c) for c in claims]:
        assert "/".join(
            (prefix, c)) in response.resources  # type: ignore[union-attr]
示例#6
0
def test_create_identity_claim_content(public_identity: PublicIdentity) -> None:
    """Request content to create claims against an identity."""
    request_id = "123456"
    claims = [b"claim-1", b"claim-2"]

    content = json.loads(
        public_identity.put_request_content(request_id=request_id, claims=claims)
    )

    hashed_claims = content.pop("claims")
    assert content == {
        "_type": "CreateIdentityClaimsRequest",
        "subjectId": public_identity.identity_id,
        "requestId": request_id,
    }
    assert len(hashed_claims) == len(claims)
    for hc in [hashed_claim(c) for c in claims]:
        assert hc in hashed_claims
示例#7
0
def test_create_asset_type_claims_content() -> None:
    """Request content to create claims on an asset type."""
    request_id = "123456"
    claims = [b"claim-1", b"claim-2"]
    asset_type = AssetType("123456")

    content = json.loads(
        asset_type.put_request_content(request_id=request_id, claims=claims))

    hashed_claims = content.pop("claims")
    assert content == {
        "_type": "CreateAssetTypeClaimsRequest",
        "subjectId": asset_type.asset_type_id,
        "requestId": request_id,
    }
    assert len(hashed_claims) == len(claims)
    for hc in [hashed_claim(c) for c in claims]:
        assert hc in hashed_claims
示例#8
0
def test_hased_claim() -> None:
    """Hash of a claim."""
    assert "RIREN5QE4J55V0aOmXdmRWOoSV_EIUtf0o_tdF4hInM" == hashed_claim(
        b"claim-1")