mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(elbv2): fail DescribeRules with RuleNotFound for an unknown rule ARN (#7492)
This commit is contained in:
1 parent
c456847899
commit
f8408ae3d4
4 files changed
+143
-2
No files matched your search
+56
@@ -0,0 +1,56 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client;
|
||||
import software.amazon.awssdk.services.elasticloadbalancingv2.model.RuleNotFoundException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@DisplayName("ELBv2 rule lookup errors")
|
||||
class ElbV2RuleLookupTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("DescribeRules with a deleted rule ARN fails with RuleNotFound instead of returning a partial list")
|
||||
void deletedRuleIsNotAnEmptyOrPartialSuccess() {
|
||||
Assumptions.assumeFalse(TestFixtures.isRealAws(), "Uses the emulator's default VPC fixtures");
|
||||
try (ElasticLoadBalancingV2Client client = TestFixtures.elbV2Client()) {
|
||||
String balancer = client.createLoadBalancer(r -> r.name(TestFixtures.uniqueName("sdk-rule"))
|
||||
.type("application").subnets(TestFixtures.defaultVpcSubnets()))
|
||||
.loadBalancers().get(0).loadBalancerArn();
|
||||
try {
|
||||
String listener = client.createListener(r -> r.loadBalancerArn(balancer).port(8080).protocol("HTTP")
|
||||
.defaultActions(a -> a.type("fixed-response").fixedResponseConfig(f ->
|
||||
f.statusCode("200").contentType("text/plain").messageBody("listener"))))
|
||||
.listeners().get(0).listenerArn();
|
||||
String retained = createRule(client, listener, "/a/*", 100);
|
||||
String removed = createRule(client, listener, "/b/*", 110);
|
||||
client.deleteRule(r -> r.ruleArn(removed));
|
||||
|
||||
assertThat(client.describeRules(r -> r.ruleArns(retained)).rules())
|
||||
.extracting(rule -> rule.ruleArn()).containsExactly(retained);
|
||||
for (List<String> requested : List.of(List.of(removed), List.of(retained, removed))) {
|
||||
RuleNotFoundException error = assertThrows(RuleNotFoundException.class,
|
||||
() -> client.describeRules(r -> r.ruleArns(requested)));
|
||||
assertThat(error.statusCode()).isEqualTo(400);
|
||||
assertThat(error.awsErrorDetails().errorCode()).isEqualTo("RuleNotFound");
|
||||
assertThat(error.requestId()).isNotBlank();
|
||||
}
|
||||
} finally {
|
||||
client.deleteLoadBalancer(r -> r.loadBalancerArn(balancer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String createRule(ElasticLoadBalancingV2Client client, String listener, String path, int priority) {
|
||||
return client.createRule(r -> r.listenerArn(listener).priority(priority)
|
||||
.conditions(c -> c.field("path-pattern").values(path))
|
||||
.actions(a -> a.type("fixed-response").fixedResponseConfig(f ->
|
||||
f.statusCode("200").contentType("text/plain").messageBody("rule"))))
|
||||
.rules().get(0).ruleArn();
|
||||
}
|
||||
}
|
||||
@@ -951,8 +951,7 @@ public class ElbV2Service implements ResourceProvider, ServerCertificateReferenc
|
||||
|
||||
if (ruleArns != null && !ruleArns.isEmpty()) {
|
||||
return ruleArns.stream()
|
||||
.map(regionRules::get)
|
||||
.filter(Objects::nonNull)
|
||||
.map(arn -> requireRule(region, arn))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if (listenerArn != null && !listenerArn.isEmpty()) {
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package io.github.hectorvent.floci.services.elbv2;
|
||||
|
||||
import io.github.hectorvent.floci.testing.AwsTestClients;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.regions.Region;
|
||||
import software.amazon.awssdk.services.elasticloadbalancingv2.ElasticLoadBalancingV2Client;
|
||||
import software.amazon.awssdk.services.elasticloadbalancingv2.model.RuleNotFoundException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@QuarkusTest
|
||||
class ElbV2RuleLookupIntegrationTest {
|
||||
|
||||
@Test
|
||||
void unknownRuleArnIsNotAnEmptyOrPartialSuccess() {
|
||||
try (ElasticLoadBalancingV2Client client = AwsTestClients.create(
|
||||
ElasticLoadBalancingV2Client.builder(), "000000000000", Region.US_EAST_1)) {
|
||||
String balancer = client.createLoadBalancer(r -> r
|
||||
.name("sdk-rule-" + UUID.randomUUID().toString().substring(0, 8))
|
||||
.type("application").subnets(List.of("subnet-default-us-east-1-a", "subnet-default-us-east-1-b")))
|
||||
.loadBalancers().get(0).loadBalancerArn();
|
||||
try {
|
||||
String listener = client.createListener(r -> r.loadBalancerArn(balancer).port(8080).protocol("HTTP")
|
||||
.defaultActions(a -> a.type("fixed-response").fixedResponseConfig(f ->
|
||||
f.statusCode("200").contentType("text/plain").messageBody("listener"))))
|
||||
.listeners().get(0).listenerArn();
|
||||
String retained = createRule(client, listener, "/a/*", 100);
|
||||
String removed = createRule(client, listener, "/b/*", 110);
|
||||
client.deleteRule(r -> r.ruleArn(removed));
|
||||
|
||||
assertThat(client.describeRules(r -> r.ruleArns(retained)).rules().stream()
|
||||
.map(rule -> rule.ruleArn()).toList(), contains(retained));
|
||||
for (List<String> requested : List.of(List.of(removed), List.of(retained, removed))) {
|
||||
RuleNotFoundException error = assertThrows(RuleNotFoundException.class,
|
||||
() -> client.describeRules(r -> r.ruleArns(requested)));
|
||||
assertEquals(400, error.statusCode());
|
||||
assertEquals("RuleNotFound", error.awsErrorDetails().errorCode());
|
||||
assertNotNull(error.requestId());
|
||||
assertFalse(error.requestId().isBlank());
|
||||
}
|
||||
assertEquals(2, client.describeRules(r -> r.listenerArn(listener)).rules().size());
|
||||
} finally {
|
||||
client.deleteLoadBalancer(r -> r.loadBalancerArn(balancer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String createRule(ElasticLoadBalancingV2Client client, String listener, String path, int priority) {
|
||||
return client.createRule(r -> r.listenerArn(listener).priority(priority)
|
||||
.conditions(c -> c.field("path-pattern").values(path))
|
||||
.actions(a -> a.type("fixed-response").fixedResponseConfig(f ->
|
||||
f.statusCode("200").contentType("text/plain").messageBody("rule"))))
|
||||
.rules().get(0).ruleArn();
|
||||
}
|
||||
}
|
||||
@@ -766,6 +766,28 @@ class ElbV2ServiceTest {
|
||||
assertEquals("100", service.describeRules(REGION, null, List.of(moved.getRuleArn())).getFirst().getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeRulesRequiresEveryExplicitArn() {
|
||||
String tgArn = createTargetGroup("rule-lookup-tg");
|
||||
String listener = createListener("rule-lookup-lb", tgArn);
|
||||
Rule retained = service.createRule(REGION, listener, List.of(pathPattern("/a/*")),
|
||||
100, List.of(forwardAction(tgArn)), Map.of());
|
||||
Rule removed = service.createRule(REGION, listener, List.of(pathPattern("/b/*")),
|
||||
110, List.of(forwardAction(tgArn)), Map.of());
|
||||
service.deleteRule(REGION, removed.getRuleArn());
|
||||
|
||||
for (List<String> requested : List.of(List.of(removed.getRuleArn()),
|
||||
List.of(retained.getRuleArn(), removed.getRuleArn()),
|
||||
List.of(removed.getRuleArn(), retained.getRuleArn()))) {
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.describeRules(REGION, null, requested));
|
||||
assertEquals("RuleNotFound", error.getErrorCode());
|
||||
assertEquals(400, error.getHttpStatus());
|
||||
}
|
||||
assertEquals(List.of(retained), service.describeRules(REGION, null, List.of(retained.getRuleArn())));
|
||||
assertEquals(2, service.describeRules(REGION, listener, List.of()).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void setRulePrioritiesChecksEachListenerOnlyAgainstItsOwnRules() {
|
||||
String tgArn = createTargetGroup("sample-tg");
|
||||
|
||||
Reference in new issue
Block a user