Search in sources :

Example 1 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project core-java by SpineEventEngine.

the class ValidationFilter method reportMissingTenantId.

private void reportMissingTenantId(Command command, StreamObserver<Response> responseObserver) {
    final CommandException noTenantDefined = InvalidCommandException.onMissingTenantId(command);
    commandBus.commandStore().storeWithError(command, noTenantDefined);
    final StatusRuntimeException exception = invalidArgumentWithCause(noTenantDefined, noTenantDefined.getError());
    responseObserver.onError(exception);
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 2 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project grpc-java by grpc.

the class TlsTest method clientRejectsUntrustedServerCert.

/**
   * Tests that a client configured using GrpcSslContexts refuses to talk to a server that has an
   * an untrusted certificate.
   */
@Test
public void clientRejectsUntrustedServerCert() throws Exception {
    // Create & start a server.
    File serverCertFile = TestUtils.loadCert("badserver.pem");
    File serverPrivateKeyFile = TestUtils.loadCert("badserver.key");
    X509Certificate[] serverTrustedCaCerts = { TestUtils.loadX509Cert("ca.pem") };
    server = serverBuilder(0, serverCertFile, serverPrivateKeyFile, serverTrustedCaCerts).addService(new TestServiceImpl(executor)).build().start();
    // Create a client.
    File clientCertChainFile = TestUtils.loadCert("client.pem");
    File clientPrivateKeyFile = TestUtils.loadCert("client.key");
    X509Certificate[] clientTrustedCaCerts = { TestUtils.loadX509Cert("ca.pem") };
    channel = clientChannel(server.getPort(), clientContextBuilder.keyManager(clientCertChainFile, clientPrivateKeyFile).trustManager(clientTrustedCaCerts).build());
    TestServiceGrpc.TestServiceBlockingStub client = TestServiceGrpc.newBlockingStub(channel);
    // Check that the TLS handshake fails.
    Empty request = Empty.getDefaultInstance();
    try {
        client.emptyCall(request);
        fail("TLS handshake should have failed, but didn't; received RPC response");
    } catch (StatusRuntimeException e) {
        // GRPC reports this situation by throwing a StatusRuntimeException that wraps either a
        // javax.net.ssl.SSLHandshakeException or a java.nio.channels.ClosedChannelException.
        // Thus, reliably detecting the underlying cause is not feasible.
        // TODO(carl-mastrangelo): eventually replace this with a hamcrest matcher.
        assertEquals(Throwables.getStackTraceAsString(e), Status.Code.UNAVAILABLE, e.getStatus().getCode());
    }
}
Also used : Empty(com.google.protobuf.EmptyProtos.Empty) StatusRuntimeException(io.grpc.StatusRuntimeException) File(java.io.File) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 3 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project grpc-java by grpc.

the class TlsTest method noClientAuthFailure.

/**
   * Tests that a server configured to require client authentication actually does require client
   * authentication.
   */
@Test
public void noClientAuthFailure() throws Exception {
    // Create & start a server.
    File serverCertFile = TestUtils.loadCert("server1.pem");
    File serverPrivateKeyFile = TestUtils.loadCert("server1.key");
    X509Certificate[] serverTrustedCaCerts = { TestUtils.loadX509Cert("ca.pem") };
    server = serverBuilder(0, serverCertFile, serverPrivateKeyFile, serverTrustedCaCerts).addService(new TestServiceImpl(executor)).build().start();
    // Create a client. It has no credentials.
    X509Certificate[] clientTrustedCaCerts = { TestUtils.loadX509Cert("ca.pem") };
    channel = clientChannel(server.getPort(), clientContextBuilder.trustManager(clientTrustedCaCerts).build());
    TestServiceGrpc.TestServiceBlockingStub client = TestServiceGrpc.newBlockingStub(channel);
    // Check that the TLS handshake fails.
    Empty request = Empty.getDefaultInstance();
    try {
        client.emptyCall(request);
        fail("TLS handshake should have failed, but didn't; received RPC response");
    } catch (StatusRuntimeException e) {
        // GRPC reports this situation by throwing a StatusRuntimeException that wraps either a
        // javax.net.ssl.SSLHandshakeException or a java.nio.channels.ClosedChannelException.
        // Thus, reliably detecting the underlying cause is not feasible.
        assertEquals(Throwables.getStackTraceAsString(e), Status.Code.UNAVAILABLE, e.getStatus().getCode());
    }
}
Also used : Empty(com.google.protobuf.EmptyProtos.Empty) StatusRuntimeException(io.grpc.StatusRuntimeException) File(java.io.File) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 4 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project grpc-java by grpc.

the class TlsTest method serverRejectsUntrustedClientCert.

/**
   * Tests that a server configured to require client authentication refuses to accept connections
   * from a client that has an untrusted certificate.
   */
@Test
public void serverRejectsUntrustedClientCert() throws Exception {
    // Create & start a server. It requires client authentication and trusts only the test CA.
    File serverCertFile = TestUtils.loadCert("server1.pem");
    File serverPrivateKeyFile = TestUtils.loadCert("server1.key");
    X509Certificate[] serverTrustedCaCerts = { TestUtils.loadX509Cert("ca.pem") };
    server = serverBuilder(0, serverCertFile, serverPrivateKeyFile, serverTrustedCaCerts).addService(new TestServiceImpl(executor)).build().start();
    // Create a client. Its credentials come from a CA that the server does not trust. The client
    // trusts both test CAs, so we can be sure that the handshake failure is due to the server
    // rejecting the client's cert, not the client rejecting the server's cert.
    File clientCertChainFile = TestUtils.loadCert("badclient.pem");
    File clientPrivateKeyFile = TestUtils.loadCert("badclient.key");
    X509Certificate[] clientTrustedCaCerts = { TestUtils.loadX509Cert("ca.pem") };
    channel = clientChannel(server.getPort(), clientContextBuilder.keyManager(clientCertChainFile, clientPrivateKeyFile).trustManager(clientTrustedCaCerts).build());
    TestServiceGrpc.TestServiceBlockingStub client = TestServiceGrpc.newBlockingStub(channel);
    // Check that the TLS handshake fails.
    Empty request = Empty.getDefaultInstance();
    try {
        client.emptyCall(request);
        fail("TLS handshake should have failed, but didn't; received RPC response");
    } catch (StatusRuntimeException e) {
        // GRPC reports this situation by throwing a StatusRuntimeException that wraps either a
        // javax.net.ssl.SSLHandshakeException or a java.nio.channels.ClosedChannelException.
        // Thus, reliably detecting the underlying cause is not feasible.
        assertEquals(Throwables.getStackTraceAsString(e), Status.Code.UNAVAILABLE, e.getStatus().getCode());
    }
}
Also used : Empty(com.google.protobuf.EmptyProtos.Empty) StatusRuntimeException(io.grpc.StatusRuntimeException) File(java.io.File) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 5 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project grpc-java by grpc.

the class NanoUtilsTest method parseInvalid.

@Test
public void parseInvalid() throws Exception {
    InputStream is = new ByteArrayInputStream(new byte[] { -127 });
    try {
        marshaller.parse(is);
        fail("Expected exception");
    } catch (StatusRuntimeException ex) {
        assertEquals(Status.Code.INTERNAL, ex.getStatus().getCode());
        assertTrue(ex.getCause() instanceof InvalidProtocolBufferNanoException);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StatusRuntimeException(io.grpc.StatusRuntimeException) InvalidProtocolBufferNanoException(com.google.protobuf.nano.InvalidProtocolBufferNanoException) Test(org.junit.Test)

Aggregations

StatusRuntimeException (io.grpc.StatusRuntimeException)240 Test (org.junit.Test)164 ApiException (com.google.api.gax.grpc.ApiException)74 Status (io.grpc.Status)25 StreamObserver (io.grpc.stub.StreamObserver)20 ByteString (com.google.protobuf.ByteString)18 ArrayList (java.util.ArrayList)18 Metadata (io.grpc.Metadata)14 SimpleServiceGrpc (io.grpc.testing.protobuf.SimpleServiceGrpc)13 ExecutionException (java.util.concurrent.ExecutionException)12 JanusGraphGrpcServerBaseTest (org.janusgraph.graphdb.grpc.JanusGraphGrpcServerBaseTest)12 Test (org.junit.jupiter.api.Test)12 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 ManagedChannel (io.grpc.ManagedChannel)9 StatusRuntimeException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException)8 BStruct (org.ballerinalang.model.values.BStruct)8 SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)7 ChannelCredentials (io.grpc.ChannelCredentials)6 ServerCredentials (io.grpc.ServerCredentials)6 TlsChannelCredentials (io.grpc.TlsChannelCredentials)6