-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
4,556 additions
and
5,356 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,35 +1,37 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { expect } from "@open-wc/testing"; | ||
|
||
import { base64urlToBuffer, bufferToBase64url } from "./base64url"; | ||
import "./arraybuffer.jest"; | ||
|
||
describe("base64url", () => { | ||
suite("base64url", () => { | ||
test("should convert simple base64url values to `ArrayBuffer`", () => { | ||
expect(base64urlToBuffer("")).toEqualBuffer(new Uint8Array([])); | ||
expect(base64urlToBuffer("AA")).toEqualBuffer(new Uint8Array([0])); | ||
expect(base64urlToBuffer("TEST")).toEqualBuffer( | ||
new Uint8Array([76, 68, 147]), | ||
// TODO: avoid round-trip while testing | ||
// https://www.chaijs.com/plugins/chai-bytes/ doesn't seem to work, due to compatibility issues with the default importt. | ||
expect(bufferToBase64url(base64urlToBuffer(""))).to.equal( | ||
bufferToBase64url(new Uint8Array([])), | ||
); | ||
expect(base64urlToBuffer("BAMCAQ")).toEqualBuffer( | ||
new Uint8Array([4, 3, 2, 1]), | ||
expect(bufferToBase64url(base64urlToBuffer("AA"))).to.equal( | ||
bufferToBase64url(new Uint8Array([0])), | ||
); | ||
expect(base64urlToBuffer("A-B-C-")).toEqualBuffer( | ||
new Uint8Array([3, 224, 126, 11]), | ||
expect(bufferToBase64url(base64urlToBuffer("TEST"))).to.equal( | ||
bufferToBase64url(new Uint8Array([76, 68, 147])), | ||
); | ||
expect(bufferToBase64url(base64urlToBuffer("BAMCAQ"))).to.equal( | ||
bufferToBase64url(new Uint8Array([4, 3, 2, 1])), | ||
); | ||
expect(bufferToBase64url(base64urlToBuffer("A-B-C-"))).to.equal( | ||
bufferToBase64url(new Uint8Array([3, 224, 126, 11])), | ||
); | ||
}); | ||
|
||
test("should convert simple `ArrayBuffer` values to base64url", () => { | ||
expect(bufferToBase64url(new Uint8Array([]))).toBe(""); | ||
expect(bufferToBase64url(new Uint8Array([0]))).toBe("AA"); | ||
expect(bufferToBase64url(new Uint8Array([4, 3, 2, 1]))).toBe("BAMCAQ"); | ||
expect(bufferToBase64url(new Uint8Array([]))).to.equal(""); | ||
expect(bufferToBase64url(new Uint8Array([0]))).to.equal("AA"); | ||
expect(bufferToBase64url(new Uint8Array([4, 3, 2, 1]))).to.equal("BAMCAQ"); | ||
}); | ||
|
||
test("should round-trip through `ArrayBuffer`", () => { | ||
// Fun fact: multiple base64url encodings can represent the same value. We expect | ||
// the output value to be different than the input in this case. | ||
expect(bufferToBase64url(base64urlToBuffer("ABCDEF"))) | ||
.toBe("ABCDEA"); | ||
expect(bufferToBase64url(base64urlToBuffer("ABCDEF"))).to.equal("ABCDEA"); | ||
}); | ||
}); |
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
Oops, something went wrong.