-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
61 lines (49 loc) · 1.43 KB
/
test.js
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
import {
generateAccessKey,
checkAuth,
generateJwt
} from "./functions.js"
async function static_tests() {
let legacyKey = generateAccessKey(new Date());
if (!await checkAuth("Bearer " + legacyKey)) {
throw "legacy auth failed";
}
if (await checkAuth(legacyKey)) {
throw "legacy auth failed";
}
legacyKey = legacyKey.replace(/[^a-zA-Z0-9-_\s]/g, '');
if (!await checkAuth("Bearer " + legacyKey)) {
throw "legacy auth failed";
}
let jwt = await generateJwt(Date.parse("2075-05-11"), "abc123", Date.parse("1975-05-11"));
if (!await checkAuth("Bearer " + jwt)) {
throw "jwt auth failed 1";
}
if (!await checkAuth("Bearer " + jwt)) {
throw "jwt auth failed 2";
}
if (!await checkAuth(jwt)) {
throw "jwt auth failed 3";
}
if (!await checkAuth(jwt + " abc123")) {
throw "jwt auth failed 3";
}
if (!await checkAuth("Bearer " + jwt + " abc123")) {
throw "jwt auth failed 3";
}
jwt = await generateJwt(Date.parse("1975-05-11"), "abc123");
if (await checkAuth("Bearer " + jwt)) {
throw "jwt auth failed 4";
}
jwt = await generateJwt(Date.parse("1975-05-11"), "abc123", Date.parse("2075-05-11"));
if (await checkAuth("Bearer " + jwt)) {
throw "jwt auth failed 5";
}
}
(async () => {
try {
await static_tests()
} catch (e) {
console.log(e)
}
})();