fix(test): disable the GuardDuty organization admin GuardDutyMembersIntegrationTest enables (#3348)

* fix(test): disable the GuardDuty organization admin GuardDutyMembersIntegrationTest enables

GuardDutyMembersIntegrationTest enables account 444444444444 as a GuardDuty
organization admin and never disables it. Those admin accounts are shared by
every @QuarkusTest class in the same Surefire fork, and Macie answers the same
/admin route, so MacieOrganizationIntegrationTest.sharedAdminRouteKeepsGuardDutyBehavior
fails whenever it runs after this class: it asks for an empty admin list on the
GuardDuty credential scope and gets 444444444444 back.

Disable the admin in @AfterEach, guarded by a flag so the teardown only runs for
the test that enabled one and a single-method run of the class still works.

* test(guardduty): reset the teardown flag after the admin is disabled

The flag survives the disable, so a switch to PER_CLASS instance lifecycle would
have the next test's teardown issue a second /admin/disable and fail on the
expected 400.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-09-10 16:37:15 -04:00
1 parent cbfa034470
commit 3669c8e84c
1 file changed
+23
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.guardduty;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -11,11 +12,32 @@ import static org.hamcrest.Matchers.hasSize;
@QuarkusTest
class GuardDutyMembersIntegrationTest {
private boolean enabledOrganizationAdmin;
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
/**
* GuardDuty's organization admin accounts are shared by every test in the JVM, and Macie
* answers the same {@code /admin} route, so an admin left behind here makes
* {@code MacieOrganizationIntegrationTest.sharedAdminRouteKeepsGuardDutyBehavior} see one
* where it expects none. The flag keeps the teardown to the test that enabled it, so a
* single-method run of this class still works.
*/
@AfterEach
void disableTheOrganizationAdminThisTestEnabled() {
if (enabledOrganizationAdmin) {
given().contentType("application/json")
.header("Authorization", auth("444444444444"))
.body("{\"adminAccountId\":\"444444444444\"}")
.post("/admin/disable")
.then().statusCode(200);
enabledOrganizationAdmin = false;
}
}
@Test
void createsUnassociatedMembersByDefault() {
String detectorId = createDetector("111111111111");
@@ -49,6 +71,7 @@ class GuardDutyMembersIntegrationTest {
.body("{\"adminAccountId\":\"444444444444\"}")
.post("/admin/enable")
.then().statusCode(200);
enabledOrganizationAdmin = true;
String detectorId = createDetector("444444444444");