Search in sources :

Example 21 with ControllerServiceBlockingStub

use of io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub in project pravega by pravega.

the class ControllerGrpcAuthFocusedTest method listKVTFiltersResultWhenUserHasAccessToSubsetOfTables.

@Test(timeout = 20000)
public void listKVTFiltersResultWhenUserHasAccessToSubsetOfTables() {
    // Arrange
    String scope = "scope1";
    ControllerServiceBlockingStub stub = prepareBlockingCallStub(UserNames.ADMIN, DEFAULT_PASSWORD);
    createScope(stub, scope);
    doAnswer(x -> CompletableFuture.completedFuture(true)).when(this.kvtStore).checkScopeExists(any(), any(), any());
    doAnswer(x -> CompletableFuture.completedFuture(new ImmutablePair<>(Lists.newArrayList("table1", "table2"), "2"))).when(this.kvtStore).listKeyValueTables(anyString(), eq(""), anyInt(), any(), any());
    doAnswer(x -> CompletableFuture.completedFuture(new ImmutablePair<>(Lists.newArrayList("table3", "table4"), "4"))).when(this.kvtStore).listKeyValueTables(anyString(), eq("2"), anyInt(), any(), any());
    doAnswer(x -> CompletableFuture.completedFuture(new ImmutablePair<>(Collections.emptyList(), "4"))).when(this.kvtStore).listKeyValueTables(anyString(), eq("4"), anyInt(), any(), any());
    stub = prepareBlockingCallStub(UserNames.SCOPE1_TABLE1_LIST_READ, DEFAULT_PASSWORD);
    Controller.KVTablesInScopeRequest request = Controller.KVTablesInScopeRequest.newBuilder().setScope(Controller.ScopeInfo.newBuilder().setScope(scope).build()).setContinuationToken(Controller.ContinuationToken.newBuilder().build()).build();
    // Act
    Controller.KVTablesInScopeResponse response = stub.listKeyValueTablesInScope(request);
    // Assert
    assertEquals(1, response.getKvtablesCount());
    stub = prepareBlockingCallStub(UserNames.SCOPE1_TABLE1_3_LIST_READ, DEFAULT_PASSWORD);
    request = Controller.KVTablesInScopeRequest.newBuilder().setScope(Controller.ScopeInfo.newBuilder().setScope(scope).build()).setContinuationToken(Controller.ContinuationToken.newBuilder().build()).build();
    // Act
    response = stub.listKeyValueTablesInScope(request);
    // Assert
    assertEquals(2, response.getKvtablesCount());
}
Also used : ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) AuthFileUtils.credentialsAndAclAsString(io.pravega.auth.AuthFileUtils.credentialsAndAclAsString) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Test(org.junit.Test)

Aggregations

ControllerServiceBlockingStub (io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub)20 Test (org.junit.Test)14 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)10 AuthFileUtils.credentialsAndAclAsString (io.pravega.auth.AuthFileUtils.credentialsAndAclAsString)9 StatusRuntimeException (io.grpc.StatusRuntimeException)3 MoreCallCredentials (io.grpc.auth.MoreCallCredentials)2 PravegaCredentialsWrapper (io.pravega.client.control.impl.PravegaCredentialsWrapper)2 NodeUri (io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri)2 PingTxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus)2 TxnId (io.pravega.controller.stream.api.grpc.v1.Controller.TxnId)2 Credentials (io.pravega.shared.security.auth.Credentials)2 DefaultCredentials (io.pravega.shared.security.auth.DefaultCredentials)2 StreamConfig (io.pravega.controller.stream.api.grpc.v1.Controller.StreamConfig)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1