fix(config): add the recorder arn to its status and filter by Arn (#8142)

DescribeConfigurationRecorderStatus did not return the recorder's arn,
a member botocore models on ConfigurationRecorderStatus, and neither
Describe call read the Arn request member both of them model.

Return the arn in the status. An Arn that does not name the recorder
now answers NoSuchConfigurationRecorderException, which both
operations model, as a name that matches nothing already did. Given
both Arn and ConfigurationRecorderNames, each must name the recorder;
the model and the API reference don't say what AWS does then. A
recorder saved before recorders had an ARN has no arn in its status,
and no Arn finds it, until its next Put.

Both Describe methods carried the same check that answers
NoSuchConfigurationRecorderException for an Arn that does not name the
recorder. It now lives in one private helper, as requireRule and
requireAuthorizationKey do for their checks. No behaviour change.

The two Arn tests called a private post helper that repeated
RestAssuredJsonUtils.awsAction. They now call awsAction directly.
This commit is contained in:
soreavis authored and GitHub committed 2026-11-12 16:50:20 -04:00
1 parent 0b6a6003b0
commit 6b129de242
7 files changed
+136 -20

No files matched your search

@@ -53,19 +53,19 @@ class AwsConfigAccountIsolationTest {
context.setAccountId(FIRST);
service.startConfigurationRecorder(REGION, "default");
context.setAccountId(SECOND);
assertFalse(service.describeConfigurationRecorderStatus(REGION, null).getFirst().recording());
assertNull(service.describeConfigurationRecorderStatus(REGION, null).getFirst().lastStartTime());
assertFalse(service.describeConfigurationRecorderStatus(REGION, null, null).getFirst().recording());
assertNull(service.describeConfigurationRecorderStatus(REGION, null, null).getFirst().lastStartTime());
service.deleteDeliveryChannel(REGION, "default");
service.startConfigurationRecorder(REGION, "default");
service.stopConfigurationRecorder(REGION, "default");
context.setAccountId(FIRST);
assertTrue(service.describeConfigurationRecorderStatus(REGION, null).getFirst().recording());
assertNull(service.describeConfigurationRecorderStatus(REGION, null).getFirst().lastStopTime());
assertTrue(service.describeConfigurationRecorderStatus(REGION, null, null).getFirst().recording());
assertNull(service.describeConfigurationRecorderStatus(REGION, null, null).getFirst().lastStopTime());
context.setAccountId(SECOND);
service.deleteConfigurationRecorder(REGION, "default");
context.setAccountId(FIRST);
assertTrue(service.describeConfigurationRecorderStatus(REGION, null).getFirst().recording());
assertNotNull(service.describeConfigurationRecorderStatus(REGION, null).getFirst().lastStartTime());
assertTrue(service.describeConfigurationRecorderStatus(REGION, null, null).getFirst().recording());
assertNotNull(service.describeConfigurationRecorderStatus(REGION, null, null).getFirst().lastStartTime());
}
@Test
@@ -48,7 +48,7 @@ class AwsConfigServicePersistenceTest {
first.putDeliveryChannel(REGION,
new DeliveryChannel("default", "config-bucket", null, null, null, null));
first.tagResource(REGION, rule.configRuleArn(), List.of(Map.of("Key", "env", "Value", "prod")));
String recorderArn = first.describeConfigurationRecorders(REGION, null).getFirst().arn();
String recorderArn = first.describeConfigurationRecorders(REGION, null, null).getFirst().arn();
AwsConfigService reloaded = restartedService();
@@ -58,8 +58,8 @@ class AwsConfigServicePersistenceTest {
reloaded.describeConformancePacks(REGION, null).stream()
.map(p -> p.conformancePackName()).toList());
assertEquals("default",
reloaded.describeConfigurationRecorders(REGION, null).getFirst().name());
assertEquals(recorderArn, reloaded.describeConfigurationRecorders(REGION, null).getFirst().arn());
reloaded.describeConfigurationRecorders(REGION, null, null).getFirst().name());
assertEquals(recorderArn, reloaded.describeConfigurationRecorders(REGION, null, null).getFirst().arn());
assertEquals("config-bucket",
reloaded.describeDeliveryChannels(REGION, null).getFirst().s3BucketName());
assertEquals("prod", reloaded.listTagsForResource(REGION, rule.configRuleArn()).getFirst().get("Value"));
@@ -148,22 +148,22 @@ class AwsConfigServicePersistenceTest {
first.putDeliveryChannel(REGION,
new DeliveryChannel("default", "config-bucket", null, null, null, null));
first.startConfigurationRecorder(REGION, "default");
Long startedAt = first.describeConfigurationRecorderStatus(REGION, null).getFirst().lastStartTime();
Long startedAt = first.describeConfigurationRecorderStatus(REGION, null, null).getFirst().lastStartTime();
assertNotNull(startedAt);
AwsConfigService reloaded = restartedService();
ConfigurationRecorderStatus afterStart =
reloaded.describeConfigurationRecorderStatus(REGION, null).getFirst();
reloaded.describeConfigurationRecorderStatus(REGION, null, null).getFirst();
assertTrue(afterStart.recording());
assertEquals(startedAt, afterStart.lastStartTime());
reloaded.stopConfigurationRecorder(REGION, "default");
Long stoppedAt = reloaded.describeConfigurationRecorderStatus(REGION, null).getFirst().lastStopTime();
Long stoppedAt = reloaded.describeConfigurationRecorderStatus(REGION, null, null).getFirst().lastStopTime();
assertNotNull(stoppedAt);
ConfigurationRecorderStatus afterStop =
restartedService().describeConfigurationRecorderStatus(REGION, null).getFirst();
restartedService().describeConfigurationRecorderStatus(REGION, null, null).getFirst();
assertFalse(afterStop.recording());
assertEquals(startedAt, afterStop.lastStartTime());
assertEquals(stoppedAt, afterStop.lastStopTime());
@@ -184,7 +184,7 @@ class AwsConfigServicePersistenceTest {
reloaded.putConfigurationRecorder(REGION, recorder, null);
ConfigurationRecorderStatus status =
reloaded.describeConfigurationRecorderStatus(REGION, null).getFirst();
reloaded.describeConfigurationRecorderStatus(REGION, null, null).getFirst();
assertFalse(status.recording());
assertNull(status.lastStartTime());
}
@@ -42,6 +42,8 @@ class AwsConfigServiceTaggingTest {
private static final String ACCOUNT = "000000000000";
private static final List<Map<String, String>> ENV_PROD = List.of(Map.of("Key", "env", "Value", "prod"));
private static final List<Map<String, String>> TEAM_RED = List.of(Map.of("Key", "team", "Value", "red"));
private static final String GHOST_RECORDER_ARN =
"arn:aws:config:us-east-1:000000000000:configuration-recorder/default/ghost";
private AwsConfigService service() {
return new AwsConfigService(new RegionResolver(REGION, ACCOUNT), null);
@@ -53,6 +55,12 @@ class AwsConfigServiceTaggingTest {
assertEquals(400, ex.getHttpStatus());
}
private static void assertNoSuchRecorder(Executable call) {
AwsException ex = assertThrows(AwsException.class, call);
assertEquals("NoSuchConfigurationRecorderException", ex.getErrorCode());
assertEquals(400, ex.getHttpStatus());
}
private static void assertAllThreeNotFound(AwsConfigService service, String region, String arn) {
assertNotFound(() -> service.tagResource(region, arn, ENV_PROD));
assertNotFound(() -> service.untagResource(region, arn, List.of("env")));
@@ -224,7 +232,45 @@ class AwsConfigServiceTaggingTest {
service.deleteConfigurationRecorder(REGION, "default");
assertTrue(service.describeConfigurationRecorders(REGION, null).isEmpty());
assertTrue(service.describeConfigurationRecorders(REGION, null, null).isEmpty());
}
@Test
void bothDescribeCallsReturnAndFilterByTheRecorderArn() {
AwsConfigService service = service();
service.putConfigurationRecorder(REGION, recorder("default"), null);
String arn = recorderArn(service);
assertEquals(arn, service.describeConfigurationRecorderStatus(REGION, null, null).getFirst().arn());
assertEquals(arn, service.describeConfigurationRecorders(REGION, null, arn).getFirst().arn());
assertEquals(arn, service.describeConfigurationRecorderStatus(REGION, null, arn).getFirst().arn());
assertEquals(arn, service.describeConfigurationRecorders(REGION, List.of("default"), arn).getFirst().arn());
assertEquals(arn,
service.describeConfigurationRecorderStatus(REGION, List.of("default"), arn).getFirst().arn());
}
@Test
void anArnOrNameThatMissesTheRecorderIsNoSuchConfigurationRecorder() {
AwsConfigService service = service();
assertNoSuchRecorder(() -> service.describeConfigurationRecorders(REGION, null, GHOST_RECORDER_ARN));
assertNoSuchRecorder(() -> service.describeConfigurationRecorderStatus(REGION, null, GHOST_RECORDER_ARN));
service.putConfigurationRecorder(REGION, recorder("default"), null);
String arn = recorderArn(service);
assertNoSuchRecorder(() -> service.describeConfigurationRecorders(REGION, null, GHOST_RECORDER_ARN));
assertNoSuchRecorder(() -> service.describeConfigurationRecorderStatus(REGION, null, GHOST_RECORDER_ARN));
assertNoSuchRecorder(() -> service.describeConfigurationRecorders(REGION, List.of("other"), arn));
assertNoSuchRecorder(() -> service.describeConfigurationRecorderStatus(REGION, List.of("other"), arn));
}
@Test
void aRecorderSavedWithoutAnArnHasNoArnInItsStatusAndNoArnFindsIt() {
AwsConfigService service = serviceWithARecorderSavedWithoutAnArn();
assertNull(service.describeConfigurationRecorderStatus(REGION, List.of("default"), null).getFirst().arn());
assertNoSuchRecorder(() -> service.describeConfigurationRecorders(REGION, null, GHOST_RECORDER_ARN));
assertNoSuchRecorder(() -> service.describeConfigurationRecorderStatus(REGION, null, GHOST_RECORDER_ARN));
}
@Test
@@ -345,6 +391,6 @@ class AwsConfigServiceTaggingTest {
}
private static String recorderArn(AwsConfigService service) {
return service.describeConfigurationRecorders(REGION, null).getFirst().arn();
return service.describeConfigurationRecorders(REGION, null, null).getFirst().arn();
}
}
@@ -536,4 +536,60 @@ class ConfigurationRecorderIntegrationTest {
.statusCode(400)
.body("__type", equalTo("ResourceNotFoundException"));
}
@Test
@Order(21)
void bothDescribeCallsReturnAndFilterByTheRecorderArn() {
RestAssuredJsonUtils.awsAction("StarlingDoveService", "PutConfigurationRecorder", """
{"ConfigurationRecorder": {"name": "default", "roleARN": "arn:aws:iam::123456789012:role/r"}}
""")
.then().statusCode(200);
String arn = RestAssuredJsonUtils.awsAction("StarlingDoveService", "DescribeConfigurationRecorders", "{}")
.then().statusCode(200)
.extract().path("ConfigurationRecorders[0].arn");
RestAssuredJsonUtils.awsAction("StarlingDoveService", "DescribeConfigurationRecorderStatus", "{}")
.then().statusCode(200)
.body("ConfigurationRecordersStatus[0].arn", equalTo(arn));
RestAssuredJsonUtils.awsAction("StarlingDoveService", "DescribeConfigurationRecorders", """
{"Arn": "%s"}
""".formatted(arn))
.then().statusCode(200)
.body("ConfigurationRecorders.arn", contains(arn));
RestAssuredJsonUtils.awsAction("StarlingDoveService", "DescribeConfigurationRecorderStatus", """
{"Arn": "%s", "ConfigurationRecorderNames": ["default"]}
""".formatted(arn))
.then().statusCode(200)
.body("ConfigurationRecordersStatus.arn", contains(arn));
}
@Test
@Order(22)
void anArnOrNameThatMissesTheRecorderIsNoSuchConfigurationRecorder() {
String arn = RestAssuredJsonUtils.awsAction("StarlingDoveService", "DescribeConfigurationRecorders", "{}")
.then().statusCode(200)
.extract().path("ConfigurationRecorders[0].arn");
String ghost = "arn:aws:config:us-east-1:000000000000:configuration-recorder/default/ghost";
RestAssuredJsonUtils.awsAction("StarlingDoveService", "DescribeConfigurationRecorders", """
{"Arn": "%s"}
""".formatted(ghost))
.then().statusCode(400)
.body("__type", equalTo("NoSuchConfigurationRecorderException"));
RestAssuredJsonUtils.awsAction("StarlingDoveService", "DescribeConfigurationRecorderStatus", """
{"Arn": "%s"}
""".formatted(ghost))
.then().statusCode(400)
.body("__type", equalTo("NoSuchConfigurationRecorderException"));
RestAssuredJsonUtils.awsAction("StarlingDoveService", "DescribeConfigurationRecorders", """
{"Arn": "%s", "ConfigurationRecorderNames": ["other"]}
""".formatted(arn))
.then().statusCode(400)
.body("__type", equalTo("NoSuchConfigurationRecorderException"));
RestAssuredJsonUtils.awsAction("StarlingDoveService", "DescribeConfigurationRecorderStatus", """
{"Arn": "%s", "ConfigurationRecorderNames": ["other"]}
""".formatted(arn))
.then().statusCode(400)
.body("__type", equalTo("NoSuchConfigurationRecorderException"));
}
}