-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_test.ts
65 lines (59 loc) · 1.5 KB
/
parse_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { parseAuthorization, parseAuthParams } from "./parse.ts";
import {
assertEquals,
assertIsError,
assertThrows,
describe,
it,
} from "./_dev_deps.ts";
import authParam from "./auth_param.json" assert { type: "json" };
import authorization from "./authorization.json" assert { type: "json" };
describe("parseAuthorization", () => {
authorization.forEach((suite) => {
it(suite.name, () => {
if (suite.must_fail) {
assertThrows(() => parseAuthorization(suite.header));
} else {
assertEquals<unknown>(parseAuthorization(suite.header), suite.expected);
}
});
});
it("should be syntax error if the input is invalid syntax", () => {
let err;
try {
parseAuthorization("");
} catch (e) {
err = e;
} finally {
assertIsError(err, SyntaxError, "unexpected Authorization input");
}
});
it("should be error if the auth param keys include duplication", () => {
let err;
try {
parseAuthorization("test a=a, A=a");
} catch (e) {
err = e;
} finally {
assertIsError(
err,
Error,
"auth param keys should be case insensitive unique",
);
}
});
});
describe("parseAuthParams", () => {
authParam.forEach((v) => {
it(v.name, () => {
if (v.must_fail) {
assertThrows(() => parseAuthParams(v.header));
} else {
assertEquals<Record<string, unknown>>(
parseAuthParams(v.header),
v.expected!,
);
}
});
});
});