Skip to content

Commit

Permalink
tests: Ensure the S3 signed URLs used for Groups access are temporall…
Browse files Browse the repository at this point in the history
…y stable

This is a carefully arranged property of them which I'd manually
validated when initially implementing.  As I have to change the
implementation to upgrade from the v2 to v3 AWS SDK, I want to
revalidate this property remains intact.
  • Loading branch information
tsibley committed Oct 19, 2023
1 parent b79aaaa commit f0b4c91
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/s3.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { jest } from "@jest/globals";
import { Group } from "../src/groups.js";


afterEach(() => {
jest.restoreAllMocks();
});


test("signed URLs are temporally stable and thus cacheable", async () => {
const blab = new Group("blab");

const narrativeMarkdown =
blab.source
.narrative("test/fixture".split("/"))
.subresource("md");

const now = jest.spyOn(Date, "now");
const time = 1697737617069; // Thu Oct 19 10:46:57.069 2023 America/Los_Angeles

now.mockReturnValue(time);
const url1 = await narrativeMarkdown.url();

now.mockReturnValue(time + 10 * 60 * 1000); // 10 minutes later (in ms)
const url2 = await narrativeMarkdown.url();

now.mockReturnValue(time + 120 * 60 * 1000); // 120 minutes (2 hours) later (in ms)
const url3 = await narrativeMarkdown.url();

expect(url1).toStrictEqual(url2);
expect(url1).not.toStrictEqual(url3);
});

0 comments on commit f0b4c91

Please sign in to comment.