Search in sources :

Example 6 with AuthorizationResourceImpl

use of io.pravega.shared.security.auth.AuthorizationResourceImpl in project pravega by pravega.

the class InMemoryControllerServiceImplTest method supplierCreatesTokenWithReadWhenRequestedPermissionIsUnexpected.

@Test
public void supplierCreatesTokenWithReadWhenRequestedPermissionIsUnexpected() {
    GrpcAuthHelper mockAuthHelper = spy(new GrpcAuthHelper(true, "tokenSigningKey", 600));
    ControllerServiceImpl objectUnderTest = new ControllerServiceImpl(null, mockAuthHelper, requestTracker, true, true, 200);
    String streamResource = new AuthorizationResourceImpl().ofStreamInScope("testScope", "testStream");
    Controller.StreamInfo request = createStreamInfoProtobufMessage("testScope", "testStream", AccessOperation.NONE);
    doReturn("").when(mockAuthHelper).checkAuthorization(streamResource, AuthHandler.Permissions.NONE);
    doReturn("").when(mockAuthHelper).checkAuthorization(streamResource, AuthHandler.Permissions.READ);
    doReturn("dummy.delegation.token").when(mockAuthHelper).createDelegationToken(streamResource, AuthHandler.Permissions.NONE);
    assertEquals("dummy.delegation.token", objectUnderTest.delegationTokenSupplier(request).get());
}
Also used : GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) AuthorizationResourceImpl(io.pravega.shared.security.auth.AuthorizationResourceImpl) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Test(org.junit.Test)

Example 7 with AuthorizationResourceImpl

use of io.pravega.shared.security.auth.AuthorizationResourceImpl in project pravega by pravega.

the class InMemoryControllerServiceImplTest method supplierCreatesTokenWithReadUpdateForInternalStreamsByDefault.

@Test
public void supplierCreatesTokenWithReadUpdateForInternalStreamsByDefault() {
    GrpcAuthHelper mockAuthHelper = spy(new GrpcAuthHelper(true, "tokenSigningKey", 600));
    ControllerServiceImpl objectUnderTest = new ControllerServiceImpl(null, mockAuthHelper, requestTracker, true, true, 200);
    String streamResource = new AuthorizationResourceImpl().ofStreamInScope("testScope", "_testStream");
    Controller.StreamInfo request = createStreamInfoProtobufMessage("testScope", "_testStream", null);
    System.out.println(request.getAccessOperation().name());
    doReturn("").when(mockAuthHelper).checkAuthorization(streamResource, AuthHandler.Permissions.READ_UPDATE);
    doReturn("dummy.delegation.token").when(mockAuthHelper).createDelegationToken(streamResource, AuthHandler.Permissions.READ_UPDATE);
    assertEquals("dummy.delegation.token", objectUnderTest.delegationTokenSupplier(request).get());
}
Also used : GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) AuthorizationResourceImpl(io.pravega.shared.security.auth.AuthorizationResourceImpl) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Test(org.junit.Test)

Example 8 with AuthorizationResourceImpl

use of io.pravega.shared.security.auth.AuthorizationResourceImpl in project pravega by pravega.

the class InMemoryControllerServiceImplTest method supplierCreatesAppropriateTokenForInternalStreamsBasedOnAccessOperation.

@Test
public void supplierCreatesAppropriateTokenForInternalStreamsBasedOnAccessOperation() {
    GrpcAuthHelper mockAuthHelper = spy(new GrpcAuthHelper(true, "tokenSigningKey", 600));
    ControllerServiceImpl objectUnderTest = new ControllerServiceImpl(null, mockAuthHelper, requestTracker, true, true, 200);
    String streamResource = new AuthorizationResourceImpl().ofInternalStream("testScope", "_testStream");
    Controller.StreamInfo request = createStreamInfoProtobufMessage("testScope", "_testStream", AccessOperation.READ_WRITE);
    doReturn("").when(mockAuthHelper).checkAuthorization(streamResource, AuthHandler.Permissions.READ_UPDATE);
    doReturn("dummy.delegation.token").when(mockAuthHelper).createDelegationToken(streamResource, AuthHandler.Permissions.READ_UPDATE);
    assertEquals("dummy.delegation.token", objectUnderTest.delegationTokenSupplier(request).get());
}
Also used : GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) AuthorizationResourceImpl(io.pravega.shared.security.auth.AuthorizationResourceImpl) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Test(org.junit.Test)

Aggregations

GrpcAuthHelper (io.pravega.controller.server.security.auth.GrpcAuthHelper)8 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)8 AuthorizationResourceImpl (io.pravega.shared.security.auth.AuthorizationResourceImpl)8 Test (org.junit.Test)8 AuthorizationResource (io.pravega.shared.security.auth.AuthorizationResource)1