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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations