From 3669c8e84ce2cadbbf039e2e6ebff96101905aa3 Mon Sep 17 00:00:00 2001 From: Kenshin Okinaka Date: Fri, 11 Sep 2026 05:37:15 +0900 Subject: [PATCH] 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. --- .../GuardDutyMembersIntegrationTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/test/java/io/github/hectorvent/floci/services/guardduty/GuardDutyMembersIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/guardduty/GuardDutyMembersIntegrationTest.java index 63c2104166..a2998d0271 100644 --- a/src/test/java/io/github/hectorvent/floci/services/guardduty/GuardDutyMembersIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/guardduty/GuardDutyMembersIntegrationTest.java @@ -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");