-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create signed cookie for CloudFront (#29)
- Loading branch information
1 parent
f6299fc
commit ab13639
Showing
8 changed files
with
237 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
getCdnUrl, | ||
getKeyPairId, | ||
getCookies, | ||
getDateLessThan, | ||
} from "./cloudfront.js"; | ||
|
||
describe("getCdnUrl", () => { | ||
it("should return a cdn URL object", () => { | ||
const result = getCdnUrl("app.archive.example.com"); | ||
expect(result.host).toBe("archive.example.com"); | ||
expect(result.origin).toBe("https://archive.example.com"); | ||
}); | ||
|
||
it("should throw an error for invalid host", () => { | ||
expect(() => getCdnUrl("archive.example.com")).toThrow("Invalid host"); | ||
}); | ||
}); | ||
|
||
describe("getKeyPairId", () => { | ||
it("should return an id", () => { | ||
const id = getKeyPairId(); | ||
expect(id).toBe("GENERATED_BY_AWS"); | ||
}); | ||
}); | ||
|
||
describe("getDateLessThan", () => { | ||
it("should return a date in the future", () => { | ||
const date = getDateLessThan(); | ||
expect(date).toBeGreaterThan(Date.now() / 1000); | ||
}); | ||
}); | ||
|
||
describe("getCookies", () => { | ||
it("should return cookies for CloudFront", () => { | ||
const dateLessThan = getDateLessThan(); | ||
const resource = "https://archive.example.com/*"; | ||
|
||
const result = getCookies({ | ||
resource, | ||
dateLessThan, | ||
}); | ||
|
||
expect(result).toBeDefined(); | ||
expect(result["CloudFront-Key-Pair-Id"]).toBeDefined(); | ||
expect(result["CloudFront-Policy"]).toBeDefined(); | ||
expect(result["CloudFront-Signature"]).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters