Search in sources :

Example 1 with ControllerServiceBlockingStub

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

the class ControllerGrpcAuthFocusedTest method createReaderGroupStrict.

private void createReaderGroupStrict(String scope, String group, ReaderGroupConfig config) {
    Exceptions.checkNotNullOrEmpty(scope, "scope");
    Exceptions.checkNotNullOrEmpty(group, "group name");
    Preconditions.checkNotNull(config, "ReaderGroupConfig");
    ControllerServiceBlockingStub stub = prepareBlockingCallStubStrict(UserNames.ADMIN, DEFAULT_PASSWORD);
    Controller.CreateReaderGroupResponse status = stub.createReaderGroup(ModelHelper.decode(scope, group, config));
    if (!status.getStatus().equals(Controller.CreateReaderGroupResponse.Status.SUCCESS)) {
        throw new RuntimeException("Failed to create reader-group");
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub) Controller(io.pravega.controller.stream.api.grpc.v1.Controller)

Example 2 with ControllerServiceBlockingStub

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

the class ControllerGrpcAuthFocusedTest method getUriSucceedsForPrivilegedUser.

@Test(timeout = 20000)
public void getUriSucceedsForPrivilegedUser() {
    String scope = "scope1";
    String stream = "stream1";
    // Arrange
    createScopeAndStream(scope, stream, prepareFromFixedScaleTypePolicy(2));
    ControllerServiceBlockingStub stub = prepareBlockingCallStub(UserNames.ADMIN, DEFAULT_PASSWORD);
    // Act
    NodeUri nodeUri1 = stub.getURI(segmentId(scope, stream, 0));
    NodeUri nodeUri2 = stub.getURI(segmentId(scope, stream, 1));
    // Verify
    assertEquals("localhost", nodeUri1.getEndpoint());
    assertEquals(12345, nodeUri1.getPort());
    assertEquals("localhost", nodeUri2.getEndpoint());
    assertEquals(12345, nodeUri2.getPort());
}
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 3 with ControllerServiceBlockingStub

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

the class ControllerGrpcAuthFocusedTest method listStreamThrowsExceptionWhenUserHasNoAccessToScope.

@Test(timeout = 20000)
public void listStreamThrowsExceptionWhenUserHasNoAccessToScope() {
    // Arrange
    createScopeAndStreams("scope1", Arrays.asList("stream1", "stream2", "stream3"), prepareFromFixedScaleTypePolicy(2));
    ControllerServiceBlockingStub stub = prepareBlockingCallStub(UserNames.SCOPE2_READ, DEFAULT_PASSWORD);
    Controller.StreamsInScopeRequest request = Controller.StreamsInScopeRequest.newBuilder().setScope(Controller.ScopeInfo.newBuilder().setScope("scope1").build()).setContinuationToken(Controller.ContinuationToken.newBuilder().build()).build();
    // Act and assert
    AssertExtensions.assertThrows("Expected auth failure.", () -> stub.listStreamsInScope(request), e -> e.getMessage().contains("PERMISSION_DENIED"));
}
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 4 with ControllerServiceBlockingStub

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

the class ControllerGrpcAuthFocusedTest method createScopeFailsForNonExistentUser.

@Test(timeout = 20000)
public void createScopeFailsForNonExistentUser() {
    // Arrange
    ControllerServiceBlockingStub blockingStub = prepareBlockingCallStub("whatever", "whatever");
    // Verify
    thrown.expect(StatusRuntimeException.class);
    thrown.expectMessage("UNAUTHENTICATED");
    // Act
    blockingStub.createScope(Controller.ScopeInfo.newBuilder().setScope("dummy").build());
}
Also used : ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub) Test(org.junit.Test)

Example 5 with ControllerServiceBlockingStub

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

the class ControllerGrpcAuthFocusedTest method prepareBlockingCallStubStrict.

private ControllerServiceBlockingStub prepareBlockingCallStubStrict(String username, String password) {
    Exceptions.checkNotNullOrEmpty(username, "username");
    Exceptions.checkNotNullOrEmpty(password, "password");
    ControllerServiceBlockingStub stub = ControllerServiceGrpc.newBlockingStub(inProcessChannelStrict);
    // 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)

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