mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(elbv2): validate listener port ranges (#6459)
This commit is contained in:
1 parent
2c0f48e203
commit
f6126964aa
4 files changed
+68
-1
No files matched your search
@@ -468,6 +468,7 @@ public class ElbV2QueryHandler {
|
||||
String listenerArn = p.getFirst("ListenerArn");
|
||||
String protocol = p.getFirst("Protocol");
|
||||
Integer port = parseIntOrNull(p.getFirst("Port"));
|
||||
ElbV2Service.validatePort(port, "port");
|
||||
String sslPolicy = p.getFirst("SslPolicy");
|
||||
List<String> certs = parseCertificateList(p, "Certificates");
|
||||
List<Action> defaultActions = parseActions(p, "DefaultActions", false);
|
||||
|
||||
@@ -603,6 +603,7 @@ public class ElbV2Service implements ResourceProvider, ServerCertificateReferenc
|
||||
String sslPolicy, List<String> certificates,
|
||||
List<Action> defaultActions, List<String> alpnPolicy,
|
||||
Map<String, String> initialTags) {
|
||||
validatePort(port, "port");
|
||||
requireLoadBalancer(region, lbArn);
|
||||
|
||||
Map<String, Listener> regionListeners = listeners.computeIfAbsent(region, k -> new ConcurrentHashMap<>());
|
||||
@@ -742,6 +743,7 @@ public class ElbV2Service implements ResourceProvider, ServerCertificateReferenc
|
||||
public Listener modifyListener(String region, String listenerArn, String protocol, Integer port,
|
||||
String sslPolicy, List<String> certificates,
|
||||
List<Action> defaultActions, List<String> alpnPolicy) {
|
||||
validatePort(port, "port");
|
||||
while (true) {
|
||||
Listener initial = requireListener(region, listenerArn);
|
||||
LoadBalancer initialLb = requireLoadBalancer(region, initial.getLoadBalancerArn());
|
||||
@@ -1585,7 +1587,7 @@ public class ElbV2Service implements ResourceProvider, ServerCertificateReferenc
|
||||
}
|
||||
}
|
||||
|
||||
private static void validatePort(Integer port, String member) {
|
||||
static void validatePort(Integer port, String member) {
|
||||
List<String> violations = new ArrayList<>();
|
||||
addPortViolation(violations, port, member);
|
||||
if (!violations.isEmpty()) {
|
||||
|
||||
@@ -55,6 +55,22 @@ class ElbV2IntegrationTest {
|
||||
+ "Member must have value less than or equal to 65535"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"CreateListener,0", "CreateListener,65536", "ModifyListener,0", "ModifyListener,65536"})
|
||||
void listenerPortValidationPrecedesLookup(String action, int port) {
|
||||
String constraint = port == 0 ? "greater than or equal to 1" : "less than or equal to 65535";
|
||||
given().header("Authorization", AUTH)
|
||||
.formParam("Action", action)
|
||||
.formParam("LoadBalancerArn", "missing-balancer")
|
||||
.formParam("ListenerArn", "missing-listener")
|
||||
.formParam("Protocol", "HTTP")
|
||||
.formParam("Port", port)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
|
||||
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value '" + port
|
||||
+ "' at 'port' failed to satisfy constraint: Member must have value " + constraint));
|
||||
}
|
||||
|
||||
// ── Load Balancers ────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
@@ -258,6 +258,54 @@ class ElbV2ServiceTest {
|
||||
verifyNoInteractions(dataPlane, healthChecker);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {-1, 0, 65536, Integer.MAX_VALUE})
|
||||
void createListenerRejectsInvalidPortWithoutPublishing(int port) {
|
||||
String lb = service.createLoadBalancer(REGION, "listener-range", "internal", "application", "ipv4",
|
||||
ALB_SUBNETS, List.of(), Map.of()).getLoadBalancerArn();
|
||||
clearInvocations(dataPlane);
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.createListener(REGION, lb,
|
||||
"HTTP", port, null, List.of(), List.of(), List.of(), Map.of()));
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals(400, error.getHttpStatus());
|
||||
assertTrue(service.describeListeners(REGION, lb, List.of()).isEmpty());
|
||||
assertTrue(service.describeRules(REGION, null, List.of()).isEmpty());
|
||||
verifyNoInteractions(dataPlane);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {-1, 0, 65536, Integer.MAX_VALUE})
|
||||
void modifyListenerRejectsInvalidPortWithoutMutation(int port) {
|
||||
String lb = service.createLoadBalancer(REGION, "listener-change", "internal", "application", "ipv4",
|
||||
ALB_SUBNETS, List.of(), Map.of()).getLoadBalancerArn();
|
||||
Listener listener = service.createListener(REGION, lb, "HTTP", 8080, null,
|
||||
List.of(), List.of(), List.of(), Map.of());
|
||||
clearInvocations(dataPlane);
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.modifyListener(REGION,
|
||||
listener.getListenerArn(), "HTTPS", port, "changed", List.of(HELD_CERTIFICATE), null, null));
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals(8080, listener.getPort());
|
||||
assertEquals("HTTP", listener.getProtocol());
|
||||
assertNull(listener.getSslPolicy());
|
||||
assertTrue(listener.getCertificates().isEmpty());
|
||||
verifyNoInteractions(dataPlane);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {1, 65535})
|
||||
void listenerPortBoundariesAndOmittedUpdateAreAccepted(int port) {
|
||||
String lb = service.createLoadBalancer(REGION, "listener-boundary", "internal", "application", "ipv4",
|
||||
ALB_SUBNETS, List.of(), Map.of()).getLoadBalancerArn();
|
||||
Listener listener = service.createListener(REGION, lb, "HTTP", port, null,
|
||||
List.of(), List.of(), List.of(), Map.of());
|
||||
assertEquals(port, listener.getPort());
|
||||
int replacement = port == 1 ? 65535 : 1;
|
||||
service.modifyListener(REGION, listener.getListenerArn(), null, replacement, null, null, null, null);
|
||||
assertEquals(replacement, listener.getPort());
|
||||
service.modifyListener(REGION, listener.getListenerArn(), null, null, null, null, null, null);
|
||||
assertEquals(replacement, listener.getPort());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullAndEmptySource
|
||||
void httpsCreateNeedsADefaultBeforeAllocatingAListener(List<String> certificates) {
|
||||
|
||||
Reference in new issue
Block a user