mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(tls): fail startup when public listener cannot bind (#3362)
This commit is contained in:
1 parent
c99ecea0da
commit
2fd55b53df
2 files changed
+33
-5
No files matched your search
+20
-4
@@ -9,9 +9,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -38,7 +37,7 @@ class TlsProxyServerReservedPortTest {
|
||||
// stage it directly on failedPorts.
|
||||
NetServer server = mock(NetServer.class);
|
||||
when(server.connectHandler(any())).thenReturn(server);
|
||||
when(server.listen()).thenReturn(Promise.<NetServer>promise().future());
|
||||
when(server.listen()).thenReturn(Future.succeededFuture(server), Promise.<NetServer>promise().future());
|
||||
|
||||
Vertx vertx = mock(Vertx.class);
|
||||
when(vertx.createNetClient()).thenReturn(mock(NetClient.class));
|
||||
@@ -54,6 +53,14 @@ class TlsProxyServerReservedPortTest {
|
||||
private static TlsProxyServer proxyWith(int flociPort, boolean tlsEnabled, int awsHttpsPort,
|
||||
Future<NetServer> outcome,
|
||||
java.util.function.Consumer<TlsProxyServer> beforeStart) {
|
||||
return proxyWith(flociPort, tlsEnabled, awsHttpsPort,
|
||||
Future.succeededFuture(mock(NetServer.class)), outcome, beforeStart);
|
||||
}
|
||||
|
||||
private static TlsProxyServer proxyWith(int flociPort, boolean tlsEnabled, int awsHttpsPort,
|
||||
Future<NetServer> publicOutcome,
|
||||
Future<NetServer> awsHttpsOutcome,
|
||||
java.util.function.Consumer<TlsProxyServer> beforeStart) {
|
||||
EmulatorConfig.TlsConfig tls = mock(EmulatorConfig.TlsConfig.class);
|
||||
when(tls.enabled()).thenReturn(tlsEnabled);
|
||||
when(tls.awsHttpsPort()).thenReturn(awsHttpsPort);
|
||||
@@ -63,7 +70,7 @@ class TlsProxyServerReservedPortTest {
|
||||
|
||||
NetServer server = mock(NetServer.class);
|
||||
when(server.connectHandler(any())).thenReturn(server);
|
||||
when(server.listen()).thenReturn(outcome);
|
||||
when(server.listen()).thenReturn(publicOutcome, awsHttpsOutcome);
|
||||
|
||||
Vertx vertx = mock(Vertx.class);
|
||||
when(vertx.createNetClient()).thenReturn(mock(NetClient.class));
|
||||
@@ -114,6 +121,15 @@ class TlsProxyServerReservedPortTest {
|
||||
assertFalse(proxy.reservesPort(443));
|
||||
}
|
||||
|
||||
@Test
|
||||
void failsStartupWhenThePublicPortCannotBind() {
|
||||
assertThrows(IllegalStateException.class, () -> proxyWith(4566, true, 443,
|
||||
Future.failedFuture(new RuntimeException("address already in use")),
|
||||
Future.succeededFuture(mock(NetServer.class)),
|
||||
ignored -> {
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotReserveAnUnrelatedPort() {
|
||||
TlsProxyServer proxy = proxyWith(4566, true, 443);
|
||||
|
||||
Reference in new issue
Block a user