-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sign.test.ts
55 lines (51 loc) · 1.03 KB
/
sign.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
import { sign } from "../src"
test("Normal Sign", () => {
// Signing with a timestamp
expect(
sign(
"payload",
"secret",
{
timestamp: new Date("2022")
}
)
).toEqual("cGF5bG9hZA.DSsLgA.2-VCgm3zhf0JyqTDEJ3a9wvNPi_sCwhpEUwaP2kdViI");
// Signing with timestamp ad custom epoch
expect(
sign(
"payload",
"secret",
{
timestamp: new Date("2022"),
epoch: new Date("2022").getTime()
}
)
).toEqual("cGF5bG9hZA.AAAAAA.rtZx5pp4bqUPRFh1fMmoofm3Wiq3BwLNRlVUTSrcGpU");
})
test("Errors", () => {
// Timestamp Out of Range
expect(() => {
sign(
"payload",
"secret",
{
timestamp: new Date("10000"),
epoch: new Date("2022").getTime()
}
)
}).toThrowError(
"Timestamp must not be 0, less than 0, or greater than 3788478847"
);
// Empty Payload
expect(() => {
sign(
"",
"secret",
{
timestamp: new Date("2022")
}
)
}).toThrowError(
"payload cannot be empty"
)
})