Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
[#595][#596]

Signed-off-by: Mark Paluch <[email protected]>
  • Loading branch information
mp911de committed Jul 11, 2023
1 parent b402400 commit 0d612f8
Showing 1 changed file with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 the original author or authors.
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,30 +32,6 @@

public class DowntimeIntegrationTests {

// Simulate server downtime, where connections are accepted and then closed immediately
static DisposableServer newServer() {
return TcpServer.create()
.doOnConnection(DisposableChannel::dispose)
.bindNow();
}

static PostgresqlConnectionFactory newConnectionFactory(DisposableServer server, SSLMode sslMode) {
return new PostgresqlConnectionFactory(
PostgresqlConnectionConfiguration.builder()
.host(server.host())
.port(server.port())
.username("test")
.sslMode(sslMode)
.build());
}

static void verifyError(SSLMode sslMode, Consumer<Throwable> assertions) {
DisposableServer server = newServer();
PostgresqlConnectionFactory connectionFactory = newConnectionFactory(server, sslMode);
connectionFactory.create().as(StepVerifier::create).verifyErrorSatisfies(assertions);
server.disposeNow();
}

@Test
void failSslHandshakeIfInboundClosed() {
verifyError(SSLMode.REQUIRE, error ->
Expand All @@ -72,11 +48,38 @@ void failSslTunnelIfInboundClosed() {
.cause()
.isInstanceOf(ClosedChannelException.class);

assertThat(error.getCause().getSuppressed().length).isOne();
assertThat(error.getCause().getSuppressed()).hasSize(1);

assertThat(error.getCause().getSuppressed()[0])
.hasMessage("Connection closed while SSL/TLS handshake was in progress");
});
}

// Simulate server downtime, where connections are accepted and then closed immediately
static DisposableServer newServer() {
return TcpServer.create()
.doOnConnection(DisposableChannel::dispose)
.bindNow();
}

static PostgresqlConnectionFactory newConnectionFactory(DisposableServer server, SSLMode sslMode) {
return new PostgresqlConnectionFactory(
PostgresqlConnectionConfiguration.builder()
.host(server.host())
.port(server.port())
.username("test")
.sslMode(sslMode)
.build());
}

static void verifyError(SSLMode sslMode, Consumer<Throwable> assertions) {
DisposableServer server = newServer();
PostgresqlConnectionFactory connectionFactory = newConnectionFactory(server, sslMode);
try {
connectionFactory.create().as(StepVerifier::create).verifyErrorSatisfies(assertions);
} finally {
server.disposeNow();
}
}

}

0 comments on commit 0d612f8

Please sign in to comment.