Search in sources :

Example 1 with InvalidPermissionRequestException

use of io.gravitee.am.service.exception.InvalidPermissionRequestException in project gravitee-access-management by gravitee-io.

the class PermissionTicketServiceTest method create_errorSingleResource_missingResource.

@Test
public void create_errorSingleResource_missingResource() {
    // Prepare request & resource
    List<PermissionRequest> request = Arrays.asList(new PermissionRequest().setResourceId("one").setResourceScopes(Arrays.asList("a", "b")));
    when(resourceService.findByDomainAndClientAndResources(DOMAIN_ID, CLIENT_ID, Arrays.asList("one"))).thenReturn(Flowable.empty());
    TestObserver<PermissionTicket> testObserver = service.create(request, DOMAIN_ID, CLIENT_ID).test();
    testObserver.assertNotComplete();
    testObserver.assertError(err -> ((InvalidPermissionRequestException) err).getOAuth2ErrorCode().equals("invalid_resource_id"));
    verify(repository, times(0)).create(any());
}
Also used : PermissionRequest(io.gravitee.am.model.uma.PermissionRequest) PermissionTicket(io.gravitee.am.model.uma.PermissionTicket) InvalidPermissionRequestException(io.gravitee.am.service.exception.InvalidPermissionRequestException) Test(org.junit.Test)

Example 2 with InvalidPermissionRequestException

use of io.gravitee.am.service.exception.InvalidPermissionRequestException in project gravitee-access-management by gravitee-io.

the class PermissionTicketServiceTest method create_errorSingleResource_missingScope.

@Test
public void create_errorSingleResource_missingScope() {
    // Prepare request & resource
    List<PermissionRequest> request = Arrays.asList(new PermissionRequest().setResourceId("one").setResourceScopes(Arrays.asList("a", "b")));
    when(resourceService.findByDomainAndClientAndResources(DOMAIN_ID, CLIENT_ID, Arrays.asList("one"))).thenReturn(Flowable.just(new Resource().setId("one").setResourceScopes(Arrays.asList("not", "same"))));
    TestObserver<PermissionTicket> testObserver = service.create(request, DOMAIN_ID, CLIENT_ID).test();
    testObserver.assertNotComplete();
    testObserver.assertError(err -> ((InvalidPermissionRequestException) err).getOAuth2ErrorCode().equals("invalid_scope"));
    verify(repository, times(0)).create(any());
}
Also used : PermissionRequest(io.gravitee.am.model.uma.PermissionRequest) PermissionTicket(io.gravitee.am.model.uma.PermissionTicket) Resource(io.gravitee.am.model.uma.Resource) InvalidPermissionRequestException(io.gravitee.am.service.exception.InvalidPermissionRequestException) Test(org.junit.Test)

Example 3 with InvalidPermissionRequestException

use of io.gravitee.am.service.exception.InvalidPermissionRequestException in project gravitee-access-management by gravitee-io.

the class PermissionTicketServiceTest method create_errorMultipleResource_missingScope.

@Test
public void create_errorMultipleResource_missingScope() {
    // Prepare request
    List<PermissionRequest> request = Arrays.asList(new PermissionRequest().setResourceId("one").setResourceScopes(Arrays.asList("a", "b")), new PermissionRequest().setResourceId("two").setResourceScopes(Arrays.asList("c", "d")));
    // Prepare Resource
    Flowable<Resource> found = Flowable.just(new Resource().setId("one").setResourceScopes(Arrays.asList("a", "b")), new Resource().setId("two").setResourceScopes(Arrays.asList("not", "same")));
    when(resourceService.findByDomainAndClientAndResources(DOMAIN_ID, CLIENT_ID, Arrays.asList("one", "two"))).thenReturn(found);
    TestObserver<PermissionTicket> testObserver = service.create(request, DOMAIN_ID, CLIENT_ID).test();
    testObserver.assertNotComplete();
    testObserver.assertError(err -> ((InvalidPermissionRequestException) err).getOAuth2ErrorCode().equals("invalid_scope"));
    verify(repository, times(0)).create(any());
}
Also used : PermissionRequest(io.gravitee.am.model.uma.PermissionRequest) PermissionTicket(io.gravitee.am.model.uma.PermissionTicket) Resource(io.gravitee.am.model.uma.Resource) InvalidPermissionRequestException(io.gravitee.am.service.exception.InvalidPermissionRequestException) Test(org.junit.Test)

Example 4 with InvalidPermissionRequestException

use of io.gravitee.am.service.exception.InvalidPermissionRequestException in project gravitee-access-management by gravitee-io.

the class PermissionTicketServiceTest method create_errorMultipleResource_moreThanOneResourceOwner.

@Test
public void create_errorMultipleResource_moreThanOneResourceOwner() {
    // Prepare request
    List<PermissionRequest> request = Arrays.asList(new PermissionRequest().setResourceId("one").setResourceScopes(Arrays.asList("a", "b")), new PermissionRequest().setResourceId("two").setResourceScopes(Arrays.asList("c", "d")));
    // Prepare Resource
    Flowable<Resource> found = Flowable.fromIterable(request).map(s -> new Resource().setId(s.getResourceId()).setResourceScopes(s.getResourceScopes()).setUserId("user_" + s.getResourceId()));
    when(resourceService.findByDomainAndClientAndResources(DOMAIN_ID, CLIENT_ID, Arrays.asList("one", "two"))).thenReturn(found);
    TestObserver<PermissionTicket> testObserver = service.create(request, DOMAIN_ID, CLIENT_ID).test();
    testObserver.assertNotComplete();
    testObserver.assertError(err -> ((InvalidPermissionRequestException) err).getOAuth2ErrorCode().equals("invalid_resource_id"));
    verify(repository, times(0)).create(any());
}
Also used : PermissionRequest(io.gravitee.am.model.uma.PermissionRequest) PermissionTicket(io.gravitee.am.model.uma.PermissionTicket) Resource(io.gravitee.am.model.uma.Resource) InvalidPermissionRequestException(io.gravitee.am.service.exception.InvalidPermissionRequestException) Test(org.junit.Test)

Example 5 with InvalidPermissionRequestException

use of io.gravitee.am.service.exception.InvalidPermissionRequestException in project gravitee-access-management by gravitee-io.

the class PermissionTicketServiceTest method create_errorMultipleResource_missingResource.

@Test
public void create_errorMultipleResource_missingResource() {
    // Prepare request
    List<PermissionRequest> request = Arrays.asList(new PermissionRequest().setResourceId("one").setResourceScopes(Arrays.asList("a", "b")), new PermissionRequest().setResourceId("two").setResourceScopes(Arrays.asList("c", "d")));
    // Prepare Resource
    Flowable<Resource> found = FlowableRange.just(new Resource().setId("one").setResourceScopes(Arrays.asList("not", "same")));
    when(resourceService.findByDomainAndClientAndResources(DOMAIN_ID, CLIENT_ID, Arrays.asList("one", "two"))).thenReturn(found);
    TestObserver<PermissionTicket> testObserver = service.create(request, DOMAIN_ID, CLIENT_ID).test();
    testObserver.assertNotComplete();
    testObserver.assertError(err -> ((InvalidPermissionRequestException) err).getOAuth2ErrorCode().equals("invalid_resource_id"));
    verify(repository, times(0)).create(any());
}
Also used : PermissionRequest(io.gravitee.am.model.uma.PermissionRequest) PermissionTicket(io.gravitee.am.model.uma.PermissionTicket) Resource(io.gravitee.am.model.uma.Resource) InvalidPermissionRequestException(io.gravitee.am.service.exception.InvalidPermissionRequestException) Test(org.junit.Test)

Aggregations

PermissionRequest (io.gravitee.am.model.uma.PermissionRequest)5 PermissionTicket (io.gravitee.am.model.uma.PermissionTicket)5 InvalidPermissionRequestException (io.gravitee.am.service.exception.InvalidPermissionRequestException)5 Test (org.junit.Test)5 Resource (io.gravitee.am.model.uma.Resource)4