mirror of
https://github.com/floci-io/floci.git
synced 2026-11-30 17:05:21 -05:00
Most tests in IamServiceLinkedRoleIntegrationTest create a role as a fixture and have no reason to remove it, so the class finished with a dozen roles still under /aws-service-role/, plus the instance profile the protection test needs. A QuarkusTest shares one application across classes, so those outlived the class and were visible to anything listing roles or instance profiles unscoped. Nothing fails on it today, because every unscoped ListRoles in the tree picks its own role out of the result by name instead of asserting over the whole list, which makes this a hazard waiting for the first test that does not. The cleanup is an @AfterAll. Quarkus points RestAssured at the application only for the duration of a test method and resets the port afterwards, so a teardown going through RestAssured has to say where the application is; the test port is random, which leaves the injected test URI as the only place to read it from. With the port supplied, the application answers normally there, and a failure in @AfterAll is reported by surefire against the class, so a cleanup that stops working does not pass quietly. It creates a role of its own before sweeping and asserts the listing sees it, because nothing else in this class pins ListRoles by PathPrefix. Without that, a listing that stopped returning anything for the path would leave the sweep with nothing to delete and the run would still finish clean. Deleting the instance profile expects 200 for the same reason: this action answers NoSuchEntity once the profile is gone, so the status is the evidence that there was something to clean. Once at the end rather than after each test, on purpose. Orders 1 to 8 are one narrative where a role created by one test is the next one's fixture and the delete in order 6 is itself under test, so cleaning between tests would take it apart. Which roles are this class's own is decided against a snapshot of the path taken before its first test, rather than by a list of the principals it uses or by sweeping the path whole. A list goes stale the first time a test is added. The whole path is not this class's to clear: other classes create service-linked roles in the same shared application, and a class running later can still be holding one. A class placed after this one in the same run saw /aws-service-role/ come back empty with the sweep unscoped, and sees ElastiCache's role, created by an earlier class, still there with the snapshot in place. The profile goes by name, since other classes keep their own profiles at the same path. The snapshot is taken on the first test rather than in @BeforeAll, where the injected URI is still null and nothing can reach the application yet. If no test got that far, the teardown returns without sweeping: it created nothing and has no record of what was already there, and failing there would bury whatever stopped the snapshot. The profile delete is guarded by a flag the creating test sets, because a focused run of a single method fires the teardown too and would otherwise demand a profile nothing had made. The probe role the teardown creates is removed in a finally, so an assertion that stops the sweep cannot leave it behind; nothing is asserted there, since a throw would bury whatever failed first. Two kinds of role live under that path and the cleanup has to know both. Most are service-linked and only DeleteServiceLinkedRole will take them, while the protection tests park ordinary roles there with CreateRole, and that action answers NoSuchEntity for those because the mark comes from the minting action rather than from the path. A 404 while deleting is what surfaced the difference, and only a 404 falls through to DeleteRole: any other status leaves the role for the closing assertion to name rather than hiding behind a second attempt. One fixture sits outside that path. The test that puts DeleteServiceLinkedRole in front of an ordinary role parks it at the account root, where a listing by PathPrefix never reaches it, so that test removes it itself with DeleteRole. Expecting 200 there is also the assertion that the rejected delete left the role alone, which is what the sibling test at a service-linked path reaches for GetRole to say. Also renumbers a duplicate @Order(24), which left two tests with an unspecified order relative to each other in a class that is ordered on purpose. Refs #5293