Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,21 @@ async function waitForAccess(
});
return;
} catch (error) {
const code = (error as { name?: string }).name;
const observed = error as {
name?: string;
$metadata?: { httpStatusCode?: number };
};
if (
!code ||
![
"InvalidAccessKeyId",
"AccessDenied",
"SignatureDoesNotMatch",
].includes(code) ||
(observed.$metadata?.httpStatusCode !== 403 &&
![
"InvalidAccessKeyId",
"AccessDenied",
"SignatureDoesNotMatch",
].includes(observed.name ?? "")) ||
Date.now() >= until
)
throw fail("retirement_bucket_cleanup_access_failed");
// HEAD errors have no XML error body; use HTTP 403 as well as named errors.
// New S3 keys may propagate asynchronously. Observe access; never repeat creation.
await delay(Math.min(250, Math.max(1, until - Date.now())));
}
Expand Down
12 changes: 10 additions & 2 deletions landing-zone-configurator/app/tests/retirement-buckets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ it("derives exact project/region/name from reviewed bucket IDs and rejects prote

it("uses real signed S3 HTTP requests and XML serialization for versions, markers and multipart cleanup", async () => {
let deleted = false,
aborted = false;
aborted = false,
heads = 0;
const calls: string[] = [],
errors: string[] = [];
const server = createServer(async (request, response) => {
Expand All @@ -367,7 +368,7 @@ it("uses real signed S3 HTTP requests and XML serialization for versions, marker
response.setHeader("content-type", "application/xml");
const xml = (body: string) => response.end(body);
if (request.method === "HEAD") {
response.statusCode = 200;
response.statusCode = ++heads === 1 ? 403 : 200;
return response.end();
}
if (url.searchParams.has("object-lock")) {
Expand Down Expand Up @@ -442,6 +443,13 @@ it("uses real signed S3 HTTP requests and XML serialization for versions, marker
});
expect(errors).toEqual([]);
expect(deleted && aborted).toBe(true);
expect(heads).toBe(2);
expect(calls.slice(0, 2)).toEqual(["HEAD:", "HEAD:"]);
expect(
f.api.filter(
(c) => c.method === "POST" && c.url.includes("/access-key?"),
),
).toHaveLength(1);
expect(calls.some((c) => c.startsWith("POST:"))).toBe(true);
expect(f.api.filter((c) => c.method === "DELETE")).toHaveLength(2);
} finally {
Expand Down
Loading