This repository has been archived by the owner on Aug 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
93 lines (83 loc) · 2.56 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var assert = require("assert");
var SfnCookie = require("./");
var Cookie = SfnCookie.default;
var parse = SfnCookie.parse;
var parseMany = SfnCookie.parseMany;
var serialize = SfnCookie.serialize;
var date = new Date(),
cookie1 = new Cookie("username=Luna"),
cookie2 = new Cookie("username=Luna; Max-Age=120; HttpOnly"),
cookie3 = new Cookie("username", "Luna"),
cookie4 = new Cookie("username", "Luna", { maxAge: 120, httpOnly: true }),
cookie5 = new Cookie({
name: "username",
value: "Luna",
maxAge: 120,
expires: date,
sameSite: "Strict",
domain: "localhost",
path: "/",
httpOnly: true,
secure: true
}),
cookie6 = new Cookie("username", "Luna", {
maxAge: 120,
expires: date,
sameSite: "Strict",
domain: "localhost",
path: "/",
httpOnly: true,
secure: true
}),
fullCookieStr = `username=Luna; Max-Age=120; Expires=${date.toUTCString()}; SameSite=Strict; Domain=localhost; Path=/; HttpOnly; Secure`;
assert.deepEqual(cookie1, { name: "username", value: "Luna" });
assert.equal(cookie1.toString(), "username=Luna");
assert.deepStrictEqual(Object.assign({}, cookie2), {
name: "username",
value: "Luna",
maxAge: 120,
httpOnly: true
});
assert.equal(cookie2.toString(), "username=Luna; Max-Age=120; HttpOnly");
assert.deepEqual(cookie3, { name: "username", value: "Luna" });
assert.equal(cookie3.toString(), "username=Luna");
assert.deepStrictEqual(Object.assign({}, cookie4), {
name: "username",
value: "Luna",
maxAge: 120,
httpOnly: true
});
assert.equal(cookie4.toString(), "username=Luna; Max-Age=120; HttpOnly");
assert.deepStrictEqual(Object.assign({}, cookie5), {
name: "username",
value: "Luna",
maxAge: 120,
expires: date,
sameSite: "Strict",
domain: "localhost",
path: "/",
httpOnly: true,
secure: true
});
assert.equal(cookie5.toString(), fullCookieStr);
assert.deepStrictEqual(Object.assign({}, cookie6), {
name: "username",
value: "Luna",
maxAge: 120,
expires: date,
sameSite: "Strict",
domain: "localhost",
path: "/",
httpOnly: true,
secure: true
});
assert.equal(cookie6.toString(), fullCookieStr);
assert.equal(serialize(cookie6), fullCookieStr);
assert.deepStrictEqual(parse(fullCookieStr), Object.assign(cookie6, {
expires: date.toUTCString()
}));
assert.deepStrictEqual(parseMany("username=Luna; gender=female"), [
new Cookie("username", "Luna"),
new Cookie("gender", "female")
]);
console.log("#### OK ####");