-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
pruneCookieIAB.test.js
109 lines (80 loc) · 3.18 KB
/
pruneCookieIAB.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
Licensed per https://github.com/privacy-tech-lab/gpc-optmeowt/blob/main/LICENSE.md
privacy-tech-lab, https://privacytechlab.org/
*/
/*
pruneCookieIAB.test.js
================================================================================
pruneCookieIAB.test.js makes a cookie and checks various properties of the new cookie
*/
import assert from "assert";
import { pruneCookieIAB } from "../../src/background/cookiesIAB.js";
import { makeCookieIAB } from "../../src/background/cookiesIAB.js";
/**
* "Prunes" the values a retrieved cookie has set that a cookie
* "to-be-set" cannot have. Also updates the value and url according
* to the passed in values.
* @param {object} cookie
*/
describe("Checks if cookie is stored per domain/subdomain", () => {
it("Cookie with incorrect domain", () => {
var name = "test_cookie";
var value = "test_value";
var url = "http://test_url.com";
var ex_cookie = makeCookieIAB(name, value, url);
ex_cookie.domain = "abcd";
ex_cookie = pruneCookieIAB(ex_cookie, value, url);
assert.equal(ex_cookie.domain, null);
});
it("Cookie with correct domain", () => {
var name = "test_cookie";
var value = "test_value";
var url = "http://test_url.com";
var ex_cookie = makeCookieIAB(name, value, url);
ex_cookie.domain = ".";
ex_cookie = pruneCookieIAB(ex_cookie, value, url);
assert.equal(ex_cookie.domain, ".");
});
it("Cookie with hostOnly == null", () => {
var name = "test_cookie";
var value = "test_value";
var url = "http://test_url.com";
var ex_cookie = makeCookieIAB(name, value, url);
ex_cookie.domain = ".";
ex_cookie.hostOnly = null;
ex_cookie = pruneCookieIAB(ex_cookie, value, url);
assert.equal(ex_cookie.hostOnly, null);
});
it("Cookie with hostOnly != null", () => {
var name = "test_cookie";
var value = "test_value";
var url = "http://test_url.com";
var ex_cookie = makeCookieIAB(name, value, url);
ex_cookie.domain = ".";
ex_cookie.hostOnly = true;
ex_cookie = pruneCookieIAB(ex_cookie, value, url);
assert.equal(ex_cookie.hostOnly, undefined);
});
it("Cookie with session == null", () => {
var name = "test_cookie";
var value = "test_value";
var url = "http://test_url.com";
var ex_cookie = makeCookieIAB(name, value, url);
ex_cookie.domain = ".";
ex_cookie.hostOnly = null;
ex_cookie.session = null;
ex_cookie = pruneCookieIAB(ex_cookie, value, url);
assert.equal(ex_cookie.session, null);
});
it("Cookie with session != null", () => {
var name = "test_cookie";
var value = "test_value";
var url = "http://test_url.com";
var ex_cookie = makeCookieIAB(name, value, url);
ex_cookie.domain = ".";
ex_cookie.hostOnly = true;
ex_cookie.session = true;
ex_cookie = pruneCookieIAB(ex_cookie, value, url);
assert.equal(ex_cookie.session, undefined);
});
});