Search in sources :

Example 6 with AccessPolicy

use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.

the class ResourceServiceTest method updateAccessPolicy_resourceNotFound.

@Test
public void updateAccessPolicy_resourceNotFound() {
    AccessPolicy accessPolicy = new AccessPolicy();
    accessPolicy.setId(POLICY_ID);
    accessPolicy.setResource(RESOURCE_ID);
    accessPolicy.setDomain(DOMAIN_ID);
    when(repository.findByDomainAndClientAndUserAndResource(DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID)).thenReturn(Maybe.empty());
    TestObserver<AccessPolicy> testObserver = service.updateAccessPolicy(accessPolicy, DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID, POLICY_ID).test();
    testObserver.assertNotComplete().assertError(ResourceNotFoundException.class);
    verify(repository, times(1)).findByDomainAndClientAndUserAndResource(DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID);
    verify(accessPolicyRepository, never()).findById(POLICY_ID);
    verify(accessPolicyRepository, never()).update(any());
}
Also used : AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) Test(org.junit.Test)

Example 7 with AccessPolicy

use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.

the class ResourceServiceTest method updateAccessPolicy.

@Test
public void updateAccessPolicy() {
    AccessPolicy accessPolicy = new AccessPolicy();
    accessPolicy.setId(POLICY_ID);
    accessPolicy.setResource(RESOURCE_ID);
    accessPolicy.setDomain(DOMAIN_ID);
    when(accessPolicyRepository.findById(POLICY_ID)).thenReturn(Maybe.just(accessPolicy));
    when(accessPolicyRepository.update(any())).thenReturn(Single.just(accessPolicy));
    TestObserver<AccessPolicy> testObserver = service.updateAccessPolicy(accessPolicy, DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID, POLICY_ID).test();
    testObserver.assertComplete().assertNoErrors();
    testObserver.assertValue(accessPolicy1 -> accessPolicy1.getId().equals(POLICY_ID));
    verify(repository, times(1)).findByDomainAndClientAndUserAndResource(DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID);
    verify(accessPolicyRepository, times(1)).findById(POLICY_ID);
    verify(accessPolicyRepository, times(1)).update(any());
}
Also used : AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) Test(org.junit.Test)

Example 8 with AccessPolicy

use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.

the class ResourceServiceTest method findAccessPolicy_byId.

@Test
public void findAccessPolicy_byId() {
    AccessPolicy accessPolicy = new AccessPolicy();
    accessPolicy.setId(POLICY_ID);
    accessPolicy.setResource(RESOURCE_ID);
    accessPolicy.setDomain(DOMAIN_ID);
    when(accessPolicyRepository.findById(POLICY_ID)).thenReturn(Maybe.just(accessPolicy));
    TestObserver<AccessPolicy> testObserver = service.findAccessPolicy(POLICY_ID).test();
    testObserver.assertComplete().assertNoErrors();
    testObserver.assertValue(accessPolicy1 -> accessPolicy1.getId().equals(POLICY_ID));
    verify(accessPolicyRepository, times(1)).findById(POLICY_ID);
}
Also used : AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) Test(org.junit.Test)

Example 9 with AccessPolicy

use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.

the class ResourceServiceTest method createAccessPolicy.

@Test
public void createAccessPolicy() {
    AccessPolicy accessPolicy = new AccessPolicy();
    accessPolicy.setId(POLICY_ID);
    accessPolicy.setResource(RESOURCE_ID);
    accessPolicy.setDomain(DOMAIN_ID);
    when(accessPolicyRepository.create(accessPolicy)).thenReturn(Single.just(accessPolicy));
    TestObserver<AccessPolicy> testObserver = service.createAccessPolicy(accessPolicy, DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID).test();
    testObserver.assertComplete().assertNoErrors();
    testObserver.assertValue(accessPolicy1 -> accessPolicy1.getId().equals(POLICY_ID));
    verify(repository, times(1)).findByDomainAndClientAndUserAndResource(DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID);
    verify(accessPolicyRepository, times(1)).create(accessPolicy);
}
Also used : AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) Test(org.junit.Test)

Example 10 with AccessPolicy

use of io.gravitee.am.model.uma.policy.AccessPolicy in project gravitee-access-management by gravitee-io.

the class ResourceServiceTest method findAccessPoliciesByResources.

@Test
public void findAccessPoliciesByResources() {
    AccessPolicy accessPolicy = new AccessPolicy();
    accessPolicy.setId(POLICY_ID);
    accessPolicy.setResource(RESOURCE_ID);
    accessPolicy.setDomain(DOMAIN_ID);
    List<String> resourceIds = Collections.singletonList(RESOURCE_ID);
    when(accessPolicyRepository.findByResources(resourceIds)).thenReturn(Flowable.just(accessPolicy));
    TestObserver<List<AccessPolicy>> testObserver = service.findAccessPoliciesByResources(resourceIds).toList().test();
    testObserver.assertComplete().assertNoErrors();
    testObserver.assertValue(accessPolicies -> accessPolicies.size() == 1);
    verify(accessPolicyRepository, times(1)).findByResources(resourceIds);
}
Also used : AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy) Test(org.junit.Test)

Aggregations

AccessPolicy (io.gravitee.am.model.uma.policy.AccessPolicy)25 Test (org.junit.Test)19 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)7 JWT (io.gravitee.am.common.jwt.JWT)3 Client (io.gravitee.am.model.oidc.Client)3 List (java.util.List)3 Token (io.gravitee.am.gateway.handler.oauth2.service.token.Token)2 AccessToken (io.gravitee.am.gateway.handler.oauth2.service.token.impl.AccessToken)2 Page (io.gravitee.am.model.common.Page)2 Resource (io.gravitee.am.model.uma.Resource)2 AccessPolicyType (io.gravitee.am.model.uma.policy.AccessPolicyType)2 NewResource (io.gravitee.am.service.model.NewResource)2 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)2 JsonObject (io.vertx.core.json.JsonObject)2 Date (java.util.Date)2 InvalidRequestException (io.gravitee.am.common.exception.oauth2.InvalidRequestException)1 OAuth2Request (io.gravitee.am.gateway.handler.oauth2.service.request.OAuth2Request)1 PolicyChainException (io.gravitee.am.gateway.policy.PolicyChainException)1 AccessPolicyCondition (io.gravitee.am.model.uma.policy.AccessPolicyCondition)1 TechnicalException (io.gravitee.am.repository.exceptions.TechnicalException)1