Search in sources :

Example 16 with GrpcAuthHelper

use of io.pravega.controller.server.security.auth.GrpcAuthHelper in project pravega by pravega.

the class PravegaTablesScopeTest method testRemoveTagsUnderScope.

@Test(timeout = 5000)
@SuppressWarnings("unchecked")
public void testRemoveTagsUnderScope() {
    // Setup Mocks.
    GrpcAuthHelper authHelper = mock(GrpcAuthHelper.class);
    when(authHelper.retrieveMasterToken()).thenReturn("");
    SegmentHelper segmentHelper = mock(SegmentHelper.class);
    PravegaTablesStoreHelper storeHelper = new PravegaTablesStoreHelper(segmentHelper, authHelper, executorService());
    PravegaTablesScope tablesScope = spy(new PravegaTablesScope(scope, storeHelper));
    doReturn(CompletableFuture.completedFuture(indexTable)).when(tablesScope).getAllStreamTagsInScopeTableNames(stream, context);
    // Simulate an empty value being returned.
    TableSegmentEntry entry = TableSegmentEntry.versioned(tagBytes, new byte[0], 1L);
    when(segmentHelper.readTable(eq(indexTable), any(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(singletonList(entry)));
    when(segmentHelper.updateTableEntries(eq(indexTable), any(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(singletonList(TableSegmentKeyVersion.from(2L))));
    when(segmentHelper.removeTableKeys(eq(indexTable), any(), anyString(), anyLong())).thenAnswer(invocation -> {
        // Capture the key value sent during removeTableKeys.
        keySnapshot = (List<TableSegmentKey>) invocation.getArguments()[1];
        return CompletableFuture.completedFuture(null);
    });
    // Invoke the removeTags method.
    tablesScope.removeTagsUnderScope(stream, Set.of(tag), context).join();
    // Verify if correctly detect that the data is empty and the entry is cleaned up.
    verify(segmentHelper, times(1)).removeTableKeys(eq(indexTable), eq(keySnapshot), anyString(), anyLong());
    // Verify if the version number is as expected.
    assertEquals(2L, keySnapshot.get(0).getVersion().getSegmentVersion());
}
Also used : TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) SegmentHelper(io.pravega.controller.server.SegmentHelper) Test(org.junit.Test)

Example 17 with GrpcAuthHelper

use of io.pravega.controller.server.security.auth.GrpcAuthHelper in project pravega by pravega.

the class InMemoryControllerServiceImplTest method supplierCreatesAppropriateTokenForRGStreamsBasedOnAccessOperation.

@Test
public void supplierCreatesAppropriateTokenForRGStreamsBasedOnAccessOperation() {
    GrpcAuthHelper mockAuthHelper = spy(new GrpcAuthHelper(true, "tokenSigningKey", 600));
    ControllerServiceImpl objectUnderTest = new ControllerServiceImpl(null, mockAuthHelper, requestTracker, true, true, 200);
    String resource = new AuthorizationResourceImpl().ofInternalStream("testScope", "_RGtestApp");
    Controller.StreamInfo request = createStreamInfoProtobufMessage("testScope", "_RGtestApp", AccessOperation.READ_WRITE);
    doReturn("").when(mockAuthHelper).checkAuthorization(resource, AuthHandler.Permissions.READ);
    doReturn("dummy.delegation.token").when(mockAuthHelper).createDelegationToken("prn::/scope:testScope/stream:_RGtestApp", 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 18 with GrpcAuthHelper

use of io.pravega.controller.server.security.auth.GrpcAuthHelper 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 19 with GrpcAuthHelper

use of io.pravega.controller.server.security.auth.GrpcAuthHelper 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 20 with GrpcAuthHelper

use of io.pravega.controller.server.security.auth.GrpcAuthHelper 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)28 Test (org.junit.Test)22 SegmentHelper (io.pravega.controller.server.SegmentHelper)10 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)10 StreamMetadataStore (io.pravega.controller.store.stream.StreamMetadataStore)9 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)8 AuthorizationResourceImpl (io.pravega.shared.security.auth.AuthorizationResourceImpl)8 UUID (java.util.UUID)8 TaskMetadataStore (io.pravega.controller.store.task.TaskMetadataStore)7 ArrayList (java.util.ArrayList)7 EventStreamWriterMock (io.pravega.controller.mocks.EventStreamWriterMock)6 EventHelper (io.pravega.controller.task.EventHelper)6 List (java.util.List)6 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)5 AbortEvent (io.pravega.shared.controller.event.AbortEvent)5 CommitEvent (io.pravega.shared.controller.event.CommitEvent)5 ControllerEventStreamWriterMock (io.pravega.controller.mocks.ControllerEventStreamWriterMock)4 BucketStore (io.pravega.controller.store.stream.BucketStore)4 TableMetadataTasks (io.pravega.controller.task.KeyValueTable.TableMetadataTasks)4 StreamMetadataTasks (io.pravega.controller.task.Stream.StreamMetadataTasks)4