MCPcopy Create free account
hub / github.com/grpc/grpc-java / noClientAuthFailure

Method noClientAuthFailure

netty/src/test/java/io/grpc/netty/TlsTest.java:296–335  ·  view source on GitHub ↗

Tests that a server configured to require client authentication actually does require client authentication.

()

Source from the content-addressed store, hash-verified

294 * authentication.
295 */
296 @Test
297 public void noClientAuthFailure() throws Exception {
298 // Create & start a server.
299 File serverCertFile = TestUtils.loadCert("server1.pem");
300 File serverPrivateKeyFile = TestUtils.loadCert("server1.key");
301 X509Certificate[] serverTrustedCaCerts = {
302 TestUtils.loadX509Cert("ca.pem")
303 };
304 server = serverBuilder(0, serverCertFile, serverPrivateKeyFile, serverTrustedCaCerts)
305 .addService(new SimpleServiceImpl())
306 .build()
307 .start();
308
309 // Create a client. It has no credentials.
310 X509Certificate[] clientTrustedCaCerts = {
311 TestUtils.loadX509Cert("ca.pem")
312 };
313 channel = clientChannel(server.getPort(), clientContextBuilder
314 .trustManager(clientTrustedCaCerts)
315 .build());
316 SimpleServiceGrpc.SimpleServiceBlockingStub client = SimpleServiceGrpc.newBlockingStub(channel);
317
318 // Check that the TLS handshake fails.
319 try {
320 client.unaryRpc(SimpleRequest.getDefaultInstance());
321 fail("TLS handshake should have failed, but didn't; received RPC response");
322 } catch (StatusRuntimeException e) {
323 // GRPC reports this situation by throwing a StatusRuntimeException that wraps either a
324 // javax.net.ssl.SSLHandshakeException or a java.nio.channels.ClosedChannelException.
325 // Thus, reliably detecting the underlying cause is not feasible.
326 assertEquals(
327 Throwables.getStackTraceAsString(e),
328 Status.Code.UNAVAILABLE, e.getStatus().getCode());
329 }
330 // We really want to see TRANSIENT_FAILURE here, but if the test runs slowly the 1s backoff
331 // may be exceeded by the time the failure happens (since it counts from the start of the
332 // attempt). Even so, CONNECTING is a strong indicator that the handshake failed; otherwise we'd
333 assertThat(channel.getState(false))
334 .isAnyOf(ConnectivityState.TRANSIENT_FAILURE, ConnectivityState.CONNECTING);
335 }
336
337
338 /**

Callers

nothing calls this directly

Calls 15

loadCertMethod · 0.95
loadX509CertMethod · 0.95
serverBuilderMethod · 0.95
clientChannelMethod · 0.95
newBlockingStubMethod · 0.95
assertEqualsMethod · 0.80
getCodeMethod · 0.80
startMethod · 0.65
buildMethod · 0.65
unaryRpcMethod · 0.65
getStatusMethod · 0.65
getStateMethod · 0.65

Tested by

no test coverage detected