Skip to content

Commit 7e2a860

Browse files
committed
fix(cloudfront-signer): add date type testcase
1 parent eb13367 commit 7e2a860

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

packages/cloudfront-signer/src/sign.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,9 @@ describe("getSignedCookies", () => {
606606
});
607607

608608
describe("getSignedUrl- when signing a URL with a date range", () => {
609-
const dateString = "2024-05-17";
609+
const dateString = "2024-05-17T12:30:45.000Z";
610610
const dateNumber = 1125674245900;
611+
const dateObject = new Date(dateString);
611612
it("allows string input compatible with Date constructor", () => {
612613
const epochDateLessThan = Math.round(new Date(dateString).getTime() / 1000);
613614
const resultUrl = getSignedUrl({
@@ -646,6 +647,26 @@ describe("getSignedUrl- when signing a URL with a date range", () => {
646647
passphrase,
647648
});
648649

650+
expect(resultUrl).toContain(`Expires=${epochDateLessThan}`);
651+
expect(resultCookies["CloudFront-Expires"]).toBe(epochDateLessThan);
652+
});
653+
it("allows Date object input", () => {
654+
const epochDateLessThan = Math.round(dateObject.getTime() / 1000);
655+
const resultUrl = getSignedUrl({
656+
url,
657+
keyPairId,
658+
dateLessThan: dateObject as unknown as string,
659+
privateKey,
660+
passphrase,
661+
});
662+
const resultCookies = getSignedCookies({
663+
url,
664+
keyPairId,
665+
dateLessThan: dateObject as unknown as string,
666+
privateKey,
667+
passphrase,
668+
});
669+
649670
expect(resultUrl).toContain(`Expires=${epochDateLessThan}`);
650671
expect(resultCookies["CloudFront-Expires"]).toBe(epochDateLessThan);
651672
});

0 commit comments

Comments
 (0)