Search in sources :

Example 6 with ControllerServiceBlockingStub

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

the class ControllerGrpcAuthFocusedTest method pingTransactionSucceedsForAuthorizedUser.

@Test(timeout = 20000)
public void pingTransactionSucceedsForAuthorizedUser() {
    String scope = "scope1";
    String stream = "stream1";
    createScopeAndStream(scope, stream, prepareFromFixedScaleTypePolicy(2));
    TxnId transactionId = createTransaction(StreamInfo.newBuilder().setScope(scope).setStream(stream).build(), 2000);
    ControllerServiceBlockingStub stub = prepareBlockingCallStub(UserNames.SCOPE1_STREAM1_READUPDATE, DEFAULT_PASSWORD);
    PingTxnStatus status = stub.pingTransaction(Controller.PingTxnRequest.newBuilder().setStreamInfo(StreamInfo.newBuilder().setScope(scope).setStream(stream).build()).setTxnId(transactionId).setLease(1000).build());
    assertEquals(PingTxnStatus.Status.OK, status.getStatus());
}
Also used : TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub) AuthFileUtils.credentialsAndAclAsString(io.pravega.auth.AuthFileUtils.credentialsAndAclAsString) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) Test(org.junit.Test)

Example 7 with ControllerServiceBlockingStub

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

the class ControllerGrpcAuthFocusedTest method getUriFailsForNonExistentUser.

@Test(timeout = 20000)
public void getUriFailsForNonExistentUser() {
    String scope = "scope1";
    String stream = "stream1";
    // Arrange
    createScopeAndStream(scope, stream, prepareFromFixedScaleTypePolicy(2));
    ControllerServiceBlockingStub stub = prepareBlockingCallStub("nonexistentuser", "whatever");
    // Verify
    thrown.expect(StatusRuntimeException.class);
    thrown.expectMessage("UNAUTHENTICATED");
    // Act
    NodeUri nodeUri1 = stub.getURI(segmentId(scope, stream, 0));
}
Also used : ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub) NodeUri(io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri) AuthFileUtils.credentialsAndAclAsString(io.pravega.auth.AuthFileUtils.credentialsAndAclAsString) Test(org.junit.Test)

Example 8 with ControllerServiceBlockingStub

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

the class ControllerGrpcAuthFocusedTest method listScopes.

@Test(timeout = 20000)
public void listScopes() {
    // Arrange
    ControllerServiceBlockingStub stub = prepareBlockingCallStub(UserNames.ADMIN, DEFAULT_PASSWORD);
    createScope(stub, "scope1");
    createScope(stub, "scope2");
    createScope(stub, "scope3");
    createScope(stub, "scope4");
    stub = prepareBlockingCallStub(UserNames.SCOPE_READER1_READ, DEFAULT_PASSWORD);
    Controller.ScopesRequest request = Controller.ScopesRequest.newBuilder().setContinuationToken(Controller.ContinuationToken.newBuilder().build()).build();
    // Act
    Controller.ScopesResponse response = stub.listScopes(request);
    // Assert
    assertEquals(1, response.getScopesList().size());
    assertEquals("4", response.getContinuationToken().getToken());
    stub = prepareBlockingCallStub(UserNames.SCOPE_READER1_3_READ, DEFAULT_PASSWORD);
    request = Controller.ScopesRequest.newBuilder().setContinuationToken(Controller.ContinuationToken.newBuilder().build()).build();
    // Act
    response = stub.listScopes(request);
    // Assert
    assertEquals(2, response.getScopesList().size());
    assertEquals("3", response.getContinuationToken().getToken());
}
Also used : ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Test(org.junit.Test)

Example 9 with ControllerServiceBlockingStub

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

the class ControllerGrpcAuthFocusedTest method prepareBlockingCallStub.

private ControllerServiceBlockingStub prepareBlockingCallStub(String username, String password) {
    Exceptions.checkNotNullOrEmpty(username, "username");
    Exceptions.checkNotNullOrEmpty(password, "password");
    ControllerServiceBlockingStub stub = ControllerServiceGrpc.newBlockingStub(inProcessChannel);
    // Set call credentials
    Credentials credentials = new DefaultCredentials(password, username);
    if (credentials != null) {
        PravegaCredentialsWrapper wrapper = new PravegaCredentialsWrapper(credentials);
        stub = stub.withCallCredentials(MoreCallCredentials.from(wrapper));
    }
    return stub;
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub) PravegaCredentialsWrapper(io.pravega.client.control.impl.PravegaCredentialsWrapper) MoreCallCredentials(io.grpc.auth.MoreCallCredentials) DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) Credentials(io.pravega.shared.security.auth.Credentials)

Example 10 with ControllerServiceBlockingStub

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

the class ControllerGrpcAuthFocusedTest method pingTransactionFailsForUnAuthorizedUser.

@Test(timeout = 20000)
public void pingTransactionFailsForUnAuthorizedUser() {
    String scope = "scope1";
    String stream = "stream1";
    createScopeAndStream(scope, stream, prepareFromFixedScaleTypePolicy(2));
    TxnId transactionId = createTransaction(StreamInfo.newBuilder().setScope(scope).setStream(stream).build(), 2000);
    ControllerServiceBlockingStub stub = prepareBlockingCallStub(UserNames.SCOPE1_STREAM1_READ, DEFAULT_PASSWORD);
    // Set the expected exception
    thrown.expect(StatusRuntimeException.class);
    thrown.expectMessage("PERMISSION_DENIED");
    PingTxnStatus status = stub.pingTransaction(Controller.PingTxnRequest.newBuilder().setStreamInfo(StreamInfo.newBuilder().setScope(scope).setStream(stream).build()).setTxnId(transactionId).setLease(1000).build());
}
Also used : TxnId(io.pravega.controller.stream.api.grpc.v1.Controller.TxnId) ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub) AuthFileUtils.credentialsAndAclAsString(io.pravega.auth.AuthFileUtils.credentialsAndAclAsString) PingTxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus) 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