Search in sources :

Example 1 with ClaimToken

use of org.eclipse.dataspaceconnector.spi.iam.ClaimToken in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ContractOfferServiceImplTest method shouldNotGetContractOfferIfPolicyIsNotFound.

@Test
void shouldNotGetContractOfferIfPolicyIsNotFound() {
    var contractDefinition = ContractDefinition.Builder.newInstance().id("1").accessPolicyId("access").contractPolicyId("contract").selectorExpression(AssetSelectorExpression.SELECT_ALL).build();
    when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap()));
    when(contractDefinitionService.definitionsFor(isA(ParticipantAgent.class))).thenReturn(Stream.of(contractDefinition));
    when(assetIndex.queryAssets(isA(AssetSelectorExpression.class))).thenReturn(Stream.of(Asset.Builder.newInstance().build()));
    when(policyStore.findById(any())).thenReturn(null);
    var query = ContractOfferQuery.builder().claimToken(ClaimToken.Builder.newInstance().build()).build();
    var result = contractOfferService.queryContractOffers(query);
    assertThat(result).hasSize(0);
}
Also used : ClaimToken(org.eclipse.dataspaceconnector.spi.iam.ClaimToken) ParticipantAgent(org.eclipse.dataspaceconnector.spi.agent.ParticipantAgent) AssetSelectorExpression(org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression) Test(org.junit.jupiter.api.Test)

Example 2 with ClaimToken

use of org.eclipse.dataspaceconnector.spi.iam.ClaimToken in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ContractValidationServiceImplTest method verifyPolicyNotFound.

@Test
void verifyPolicyNotFound() {
    var originalPolicy = Policy.Builder.newInstance().build();
    var asset = Asset.Builder.newInstance().id("1").build();
    var contractDefinition = ContractDefinition.Builder.newInstance().id("1").accessPolicyId("access").contractPolicyId("contract").selectorExpression(AssetSelectorExpression.SELECT_ALL).build();
    when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap()));
    when(definitionService.definitionFor(isA(ParticipantAgent.class), eq("1"))).thenReturn(contractDefinition);
    when(policyStore.findById(any())).thenReturn(null);
    when(assetIndex.queryAssets(isA(QuerySpec.class))).thenReturn(Stream.of(asset));
    var claimToken = ClaimToken.Builder.newInstance().build();
    var offer = ContractOffer.Builder.newInstance().id("1:2").asset(asset).policy(originalPolicy).provider(URI.create("provider")).consumer(URI.create("consumer")).build();
    var result = validationService.validate(claimToken, offer);
    assertThat(result.failed()).isTrue();
}
Also used : ClaimToken(org.eclipse.dataspaceconnector.spi.iam.ClaimToken) QuerySpec(org.eclipse.dataspaceconnector.spi.query.QuerySpec) ParticipantAgent(org.eclipse.dataspaceconnector.spi.agent.ParticipantAgent) Test(org.junit.jupiter.api.Test)

Example 3 with ClaimToken

use of org.eclipse.dataspaceconnector.spi.iam.ClaimToken in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ContractValidationServiceImplTest method verifyContractOfferValidation.

@Test
void verifyContractOfferValidation() {
    var originalPolicy = Policy.Builder.newInstance().build();
    var newPolicy = Policy.Builder.newInstance().build();
    var asset = Asset.Builder.newInstance().id("1").build();
    var contractDefinition = ContractDefinition.Builder.newInstance().id("1").accessPolicyId("access").contractPolicyId("contract").selectorExpression(AssetSelectorExpression.SELECT_ALL).build();
    when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap()));
    when(definitionService.definitionFor(isA(ParticipantAgent.class), eq("1"))).thenReturn(contractDefinition);
    when(policyStore.findById("access")).thenReturn(Policy.Builder.newInstance().build());
    when(policyStore.findById("contract")).thenReturn(newPolicy);
    when(assetIndex.queryAssets(isA(QuerySpec.class))).thenReturn(Stream.of(asset));
    var claimToken = ClaimToken.Builder.newInstance().build();
    var offer = ContractOffer.Builder.newInstance().id("1:2").asset(asset).policy(originalPolicy).provider(URI.create("provider")).consumer(URI.create("consumer")).build();
    var result = validationService.validate(claimToken, offer);
    assertThat(result.getContent()).isNotNull();
    // verify the returned policy is the sanitized one
    assertThat(result.getContent().getPolicy()).isNotSameAs(originalPolicy);
    verify(agentService).createFor(isA(ClaimToken.class));
    verify(definitionService).definitionFor(isA(ParticipantAgent.class), eq("1"));
    verify(assetIndex).queryAssets(isA(QuerySpec.class));
}
Also used : ClaimToken(org.eclipse.dataspaceconnector.spi.iam.ClaimToken) QuerySpec(org.eclipse.dataspaceconnector.spi.query.QuerySpec) ParticipantAgent(org.eclipse.dataspaceconnector.spi.agent.ParticipantAgent) Test(org.junit.jupiter.api.Test)

Example 4 with ClaimToken

use of org.eclipse.dataspaceconnector.spi.iam.ClaimToken in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ContractValidationServiceImplTest method validateAgreementDate.

private boolean validateAgreementDate(long signingDate, long startDate, long endDate) {
    when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap()));
    var claimToken = ClaimToken.Builder.newInstance().build();
    var agreement = ContractAgreement.Builder.newInstance().id("1").providerAgentId("provider").consumerAgentId("consumer").policyId("policy").assetId(UUID.randomUUID().toString()).contractSigningDate(signingDate).contractStartDate(startDate).contractEndDate(endDate).id("1:2").build();
    return validationService.validate(claimToken, agreement);
}
Also used : ClaimToken(org.eclipse.dataspaceconnector.spi.iam.ClaimToken) ParticipantAgent(org.eclipse.dataspaceconnector.spi.agent.ParticipantAgent)

Example 5 with ClaimToken

use of org.eclipse.dataspaceconnector.spi.iam.ClaimToken in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ContractValidationServiceImplTest method verifyContractAgreementValidation.

@Test
void verifyContractAgreementValidation() {
    var newPolicy = Policy.Builder.newInstance().build();
    var contractDefinition = ContractDefinition.Builder.newInstance().id("1").accessPolicyId("access").contractPolicyId("contract").selectorExpression(AssetSelectorExpression.SELECT_ALL).build();
    when(agentService.createFor(isA(ClaimToken.class))).thenReturn(new ParticipantAgent(emptyMap(), emptyMap()));
    when(definitionService.definitionFor(isA(ParticipantAgent.class), eq("1"))).thenReturn(contractDefinition);
    when(policyStore.findById("access")).thenReturn(Policy.Builder.newInstance().build());
    when(policyStore.findById("contract")).thenReturn(newPolicy);
    var claimToken = ClaimToken.Builder.newInstance().build();
    var agreement = ContractAgreement.Builder.newInstance().id("1").providerAgentId("provider").consumerAgentId("consumer").policyId("policy").assetId(UUID.randomUUID().toString()).contractStartDate(Instant.now().getEpochSecond()).contractEndDate(Instant.now().plus(1, ChronoUnit.DAYS).getEpochSecond()).contractSigningDate(Instant.now().getEpochSecond()).id("1:2").build();
    assertThat(validationService.validate(claimToken, agreement)).isTrue();
    verify(agentService).createFor(isA(ClaimToken.class));
    verify(definitionService).definitionFor(isA(ParticipantAgent.class), eq("1"));
}
Also used : ClaimToken(org.eclipse.dataspaceconnector.spi.iam.ClaimToken) ParticipantAgent(org.eclipse.dataspaceconnector.spi.agent.ParticipantAgent) Test(org.junit.jupiter.api.Test)

Aggregations

ClaimToken (org.eclipse.dataspaceconnector.spi.iam.ClaimToken)10 ParticipantAgent (org.eclipse.dataspaceconnector.spi.agent.ParticipantAgent)6 Test (org.junit.jupiter.api.Test)6 AssetSelectorExpression (org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression)3 JOSEException (com.nimbusds.jose.JOSEException)2 JWSHeader (com.nimbusds.jose.JWSHeader)2 JWSVerifier (com.nimbusds.jose.JWSVerifier)2 DefaultJWSVerifierFactory (com.nimbusds.jose.crypto.factories.DefaultJWSVerifierFactory)2 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)2 SignedJWT (com.nimbusds.jwt.SignedJWT)2 ParseException (java.text.ParseException)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 PublicKeyResolver (org.eclipse.dataspaceconnector.spi.iam.PublicKeyResolver)2 TokenRepresentation (org.eclipse.dataspaceconnector.spi.iam.TokenRepresentation)2 QuerySpec (org.eclipse.dataspaceconnector.spi.query.QuerySpec)2 Result (org.eclipse.dataspaceconnector.spi.result.Result)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1