Skip to content

Commit c231330

Browse files
committed
Move the startup message to enable usage when trying SSL modes
1 parent 7b55c3f commit c231330

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

vertx-pg-client/src/main/java/io/vertx/pgclient/impl/PgConnectionFactory.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,8 @@ protected Future<Connection> doConnectInternal(SqlConnectOptions options, Contex
7575
} catch (Exception e) {
7676
return context.failedFuture(e);
7777
}
78-
String username = options.getUser();
79-
String password = options.getPassword();
80-
String database = options.getDatabase();
8178
SocketAddress server = options.getSocketAddress();
82-
Map<String, String> properties = options.getProperties() != null ? Collections.unmodifiableMap(options.getProperties()) : null;
83-
return doConnect(server, context, pgOptions).flatMap(conn -> {
84-
PgSocketConnection socket = (PgSocketConnection) conn;
85-
socket.init();
86-
return Future.<Connection>future(p -> socket.sendStartupMessage(username, password, database, properties, p))
87-
.map(conn);
88-
});
79+
return doConnect(server, context, options);
8980
}
9081

9182
public void cancelRequest(PgConnectOptions options, int processId, int secretKey, Handler<AsyncResult<Void>> handler) {
@@ -104,26 +95,39 @@ private Future<Connection> doConnect(SocketAddress server, ContextInternal conte
10495
Future<Connection> connFuture;
10596
switch (sslMode) {
10697
case DISABLE:
107-
connFuture = doConnect(server, context, false, options);
98+
connFuture = doConnect(server, options, context, false, options);
10899
break;
109100
case ALLOW:
110-
connFuture = doConnect(server, context,false, options).recover(err -> doConnect(server, context,true, options));
101+
connFuture = doConnect(server, options, context,false, options).recover(err -> doConnect(server, options, context,true, options));
111102
break;
112103
case PREFER:
113-
connFuture = doConnect(server, context,true, options).recover(err -> doConnect(server, context,false, options));
104+
connFuture = doConnect(server, options, context,true, options).recover(err -> doConnect(server, options, context,false, options));
114105
break;
115106
case REQUIRE:
116107
case VERIFY_CA:
117108
case VERIFY_FULL:
118-
connFuture = doConnect(server, context, true, options);
109+
connFuture = doConnect(server, options, context, true, options);
119110
break;
120111
default:
121112
return context.failedFuture(new IllegalArgumentException("Unsupported SSL mode"));
122113
}
123114
return connFuture;
124115
}
125116

126-
private Future<Connection> doConnect(SocketAddress server, ContextInternal context, boolean ssl, PgConnectOptions options) {
117+
private Future<Connection> doConnect(SocketAddress server, PgConnectOptions connectOptions, ContextInternal context, boolean ssl, PgConnectOptions options) {
118+
return doConnect_(server, connectOptions, context, ssl, options).flatMap(conn -> {
119+
String username = options.getUser();
120+
String password = options.getPassword();
121+
String database = options.getDatabase();
122+
Map<String, String> properties = options.getProperties() != null ? Collections.unmodifiableMap(options.getProperties()) : null;
123+
PgSocketConnection socket = (PgSocketConnection) conn;
124+
socket.init();
125+
return Future.<Connection>future(p -> socket.sendStartupMessage(username, password, database, properties, p))
126+
.map(conn);
127+
});
128+
}
129+
130+
private Future<Connection> doConnect_(SocketAddress server, PgConnectOptions connectOptions, ContextInternal context, boolean ssl, PgConnectOptions options) {
127131
Future<NetSocket> soFut;
128132
try {
129133
soFut = netClient(options).connect(server, (String) null);

vertx-pg-client/src/test/java/io/vertx/pgclient/junit/ContainerPgRule.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ private void initServer(String version) throws Exception {
8181
.withClasspathResourceMapping("tls/server.crt", "/server.crt", BindMode.READ_ONLY)
8282
.withClasspathResourceMapping("tls/server.key", "/server.key", BindMode.READ_ONLY)
8383
.withClasspathResourceMapping("tls/ssl.sh", "/docker-entrypoint-initdb.d/ssl.sh", BindMode.READ_ONLY);
84-
if (forceSsl) {
85-
server
86-
.withClasspathResourceMapping("tls/pg_hba.conf", "/tmp/pg_hba.conf", BindMode.READ_ONLY)
87-
.withClasspathResourceMapping("tls/force_ssl.sh", "/docker-entrypoint-initdb.d/force_ssl.sh", BindMode.READ_ONLY);
88-
89-
}
84+
if (forceSsl) {
85+
server
86+
.withClasspathResourceMapping("tls/pg_hba.conf", "/tmp/pg_hba.conf", BindMode.READ_ONLY)
87+
.withClasspathResourceMapping("tls/force_ssl.sh", "/docker-entrypoint-initdb.d/force_ssl.sh", BindMode.READ_ONLY);
88+
}
9089
}
9190
if (System.getProperties().containsKey("containerFixedPort")) {
9291
server.withFixedExposedPort(POSTGRESQL_PORT, POSTGRESQL_PORT);

0 commit comments

Comments
 (0)