2020-06-03 09:44:51 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { assertEquals } from "../testing/asserts.ts";
|
2020-09-27 06:22:32 -04:00
|
|
|
import { decode, encode } from "./base64url.ts";
|
2020-06-03 09:44:51 -04:00
|
|
|
|
|
|
|
const testsetString = [
|
|
|
|
["", ""],
|
|
|
|
["f", "Zg"],
|
|
|
|
["fo", "Zm8"],
|
|
|
|
["foo", "Zm9v"],
|
|
|
|
["foob", "Zm9vYg"],
|
|
|
|
["fooba", "Zm9vYmE"],
|
|
|
|
["foobar", "Zm9vYmFy"],
|
|
|
|
[">?>d?ß", "Pj8-ZD_f"],
|
|
|
|
];
|
|
|
|
|
|
|
|
const testsetBinary = [
|
|
|
|
[new TextEncoder().encode("\x00"), "AA"],
|
|
|
|
[new TextEncoder().encode("\x00\x00"), "AAA"],
|
|
|
|
[new TextEncoder().encode("\x00\x00\x00"), "AAAA"],
|
|
|
|
[new TextEncoder().encode("\x00\x00\x00\x00"), "AAAAAA"],
|
|
|
|
];
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("[encoding/base64url] testBase64urlEncodeString", () => {
|
2020-06-03 09:44:51 -04:00
|
|
|
for (const [input, output] of testsetString) {
|
|
|
|
assertEquals(encode(input), output);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("[encoding/base64url] testBase64urlEncodeBinary", () => {
|
2020-06-03 09:44:51 -04:00
|
|
|
for (const [input, output] of testsetBinary) {
|
|
|
|
assertEquals(encode(input), output);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test("[encoding/base64ur] testBase64urDecodeBinary", () => {
|
2020-06-03 09:44:51 -04:00
|
|
|
for (const [input, output] of testsetBinary) {
|
|
|
|
const outputBinary = new Uint8Array(decode(output as string));
|
|
|
|
assertEquals(outputBinary, input as Uint8Array);
|
|
|
|
}
|
|
|
|
});
|