tough-cookie 0.12.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +12 -0
- package/.npmignore +1 -0
- package/.travis.yml +2 -1
- package/LICENSE +22 -26
- package/README.md +32 -20
- package/generate-pubsuffix.js +54 -34
- package/lib/cookie.js +112 -69
- package/lib/memstore.js +44 -24
- package/lib/pubsuffix.js +27 -17
- package/lib/store.js +30 -0
- package/package.json +4 -4
- package/test/api_test.js +388 -0
- package/test/cookie_jar_test.js +468 -0
- package/test/cookie_sorting_test.js +90 -0
- package/test/cookie_to_json_test.js +164 -0
- package/test/cookie_to_string_test.js +162 -0
- package/test/date_test.js +79 -0
- package/test/domain_and_path_test.js +201 -0
- package/test/ietf_data/dates/bsd-examples.json +168 -0
- package/test/ietf_data/dates/examples.json +48 -0
- package/test/ietf_data/parser.json +1959 -0
- package/test/ietf_test.js +106 -0
- package/test/lifetime_test.js +97 -0
- package/test/parsing_test.js +356 -0
- package/test/regression_test.js +128 -0
- package/tough-cookie-deps.tsv +6 -0
- package/test.js +0 -1625
package/lib/memstore.js
CHANGED
|
@@ -1,8 +1,38 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015, Salesforce.com, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
|
7
|
+
*
|
|
8
|
+
* 1. Redistributions of source code must retain the above copyright notice,
|
|
9
|
+
* this list of conditions and the following disclaimer.
|
|
10
|
+
*
|
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
* and/or other materials provided with the distribution.
|
|
14
|
+
*
|
|
15
|
+
* 3. Neither the name of Salesforce.com nor the names of its contributors may
|
|
16
|
+
* be used to endorse or promote products derived from this software without
|
|
17
|
+
* specific prior written permission.
|
|
18
|
+
*
|
|
19
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
22
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
23
|
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
24
|
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
25
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
26
|
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
27
|
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
28
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
29
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
|
30
|
+
*/
|
|
1
31
|
'use strict';
|
|
2
32
|
var tough = require('./cookie');
|
|
3
33
|
var Store = require('./store').Store;
|
|
4
34
|
var permuteDomain = tough.permuteDomain;
|
|
5
|
-
var
|
|
35
|
+
var pathMatch = tough.pathMatch;
|
|
6
36
|
var util = require('util');
|
|
7
37
|
|
|
8
38
|
function MemoryCookieStore() {
|
|
@@ -37,7 +67,7 @@ MemoryCookieStore.prototype.findCookies = function(domain, path, cb) {
|
|
|
37
67
|
|
|
38
68
|
var pathMatcher;
|
|
39
69
|
if (!path) {
|
|
40
|
-
// null
|
|
70
|
+
// null means "all paths"
|
|
41
71
|
pathMatcher = function matchAll(domainIndex) {
|
|
42
72
|
for (var curPath in domainIndex) {
|
|
43
73
|
var pathIndex = domainIndex[curPath];
|
|
@@ -47,30 +77,20 @@ MemoryCookieStore.prototype.findCookies = function(domain, path, cb) {
|
|
|
47
77
|
}
|
|
48
78
|
};
|
|
49
79
|
|
|
50
|
-
} else if (path === '/') {
|
|
51
|
-
pathMatcher = function matchSlash(domainIndex) {
|
|
52
|
-
var pathIndex = domainIndex['/'];
|
|
53
|
-
if (!pathIndex) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
for (var key in pathIndex) {
|
|
57
|
-
results.push(pathIndex[key]);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
80
|
} else {
|
|
62
|
-
var paths = permutePath(path) || [path];
|
|
63
81
|
pathMatcher = function matchRFC(domainIndex) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
82
|
+
//NOTE: we should use path-match algorithm from S5.1.4 here
|
|
83
|
+
//(see : https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/canonical_cookie.cc#L299)
|
|
84
|
+
Object.keys(domainIndex).forEach(function (cookiePath) {
|
|
85
|
+
if (pathMatch(path, cookiePath)) {
|
|
86
|
+
var pathIndex = domainIndex[cookiePath];
|
|
87
|
+
|
|
88
|
+
for (var key in pathIndex) {
|
|
89
|
+
results.push(pathIndex[key]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
74
94
|
}
|
|
75
95
|
|
|
76
96
|
var domains = permuteDomain(domain) || [domain];
|
package/lib/pubsuffix.js
CHANGED
|
@@ -4,25 +4,35 @@
|
|
|
4
4
|
****************************************************/
|
|
5
5
|
|
|
6
6
|
module.exports.getPublicSuffix = function getPublicSuffix(domain) {
|
|
7
|
-
|
|
8
|
-
* Copyright
|
|
9
|
-
*
|
|
10
|
-
* of this software and associated documentation files (the "Software"), to
|
|
11
|
-
* deal in the Software without restriction, including without limitation the
|
|
12
|
-
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
13
|
-
* sell copies of the Software, and to permit persons to whom the Software is
|
|
14
|
-
* furnished to do so, subject to the following conditions:
|
|
7
|
+
/*!
|
|
8
|
+
* Copyright (c) 2015, Salesforce.com, Inc.
|
|
9
|
+
* All rights reserved.
|
|
15
10
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
11
|
+
* Redistribution and use in source and binary forms, with or without
|
|
12
|
+
* modification, are permitted provided that the following conditions are met:
|
|
18
13
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
14
|
+
* 1. Redistributions of source code must retain the above copyright notice,
|
|
15
|
+
* this list of conditions and the following disclaimer.
|
|
16
|
+
*
|
|
17
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
18
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
19
|
+
* and/or other materials provided with the distribution.
|
|
20
|
+
*
|
|
21
|
+
* 3. Neither the name of Salesforce.com nor the names of its contributors may
|
|
22
|
+
* be used to endorse or promote products derived from this software without
|
|
23
|
+
* specific prior written permission.
|
|
24
|
+
*
|
|
25
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
26
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
27
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
28
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
29
|
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
30
|
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
31
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
32
|
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
33
|
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
34
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
35
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
|
26
36
|
*/
|
|
27
37
|
if (!domain) return null;
|
|
28
38
|
if (domain.match(/^\./)) return null;
|
package/lib/store.js
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015, Salesforce.com, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
|
7
|
+
*
|
|
8
|
+
* 1. Redistributions of source code must retain the above copyright notice,
|
|
9
|
+
* this list of conditions and the following disclaimer.
|
|
10
|
+
*
|
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
* and/or other materials provided with the distribution.
|
|
14
|
+
*
|
|
15
|
+
* 3. Neither the name of Salesforce.com nor the names of its contributors may
|
|
16
|
+
* be used to endorse or promote products derived from this software without
|
|
17
|
+
* specific prior written permission.
|
|
18
|
+
*
|
|
19
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
22
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
23
|
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
24
|
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
25
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
26
|
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
27
|
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
28
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
29
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
|
30
|
+
*/
|
|
1
31
|
'use strict';
|
|
2
32
|
/*jshint unused:false */
|
|
3
33
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"author": "
|
|
3
|
-
"license": "
|
|
2
|
+
"author": "Jeremy Stashewsky <jstashewsky@salesforce.com>",
|
|
3
|
+
"license": "BSD-3-Clause",
|
|
4
4
|
"name": "tough-cookie",
|
|
5
5
|
"description": "RFC6265 Cookies and Cookie Jar for node.js",
|
|
6
6
|
"keywords": [
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"RFC6265",
|
|
14
14
|
"RFC2965"
|
|
15
15
|
],
|
|
16
|
-
"version": "0.
|
|
16
|
+
"version": "0.13.0",
|
|
17
17
|
"homepage": "https://github.com/goinstant/tough-cookie",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"main": "./lib/cookie",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"test": "vows test.js"
|
|
27
|
+
"test": "vows test/*_test.js"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
30
|
"node": ">=0.4.12"
|
package/test/api_test.js
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015, Salesforce.com, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
|
7
|
+
*
|
|
8
|
+
* 1. Redistributions of source code must retain the above copyright notice,
|
|
9
|
+
* this list of conditions and the following disclaimer.
|
|
10
|
+
*
|
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
* and/or other materials provided with the distribution.
|
|
14
|
+
*
|
|
15
|
+
* 3. Neither the name of Salesforce.com nor the names of its contributors may
|
|
16
|
+
* be used to endorse or promote products derived from this software without
|
|
17
|
+
* specific prior written permission.
|
|
18
|
+
*
|
|
19
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
22
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
23
|
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
24
|
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
25
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
26
|
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
27
|
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
28
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
29
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
|
30
|
+
*/
|
|
31
|
+
'use strict';
|
|
32
|
+
var vows = require('vows');
|
|
33
|
+
var assert = require('assert');
|
|
34
|
+
var async = require('async');
|
|
35
|
+
var tough = require('../lib/cookie');
|
|
36
|
+
var Cookie = tough.Cookie;
|
|
37
|
+
var CookieJar = tough.CookieJar;
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
var atNow = Date.now();
|
|
41
|
+
|
|
42
|
+
function at(offset) {
|
|
43
|
+
return {now: new Date(atNow + offset)};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
vows
|
|
47
|
+
.describe('API')
|
|
48
|
+
.addBatch({
|
|
49
|
+
"All defined": function () {
|
|
50
|
+
assert.ok(Cookie);
|
|
51
|
+
assert.ok(CookieJar);
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
.addBatch({
|
|
55
|
+
"Constructor": {
|
|
56
|
+
topic: function () {
|
|
57
|
+
return new Cookie({
|
|
58
|
+
key: 'test',
|
|
59
|
+
value: 'b',
|
|
60
|
+
maxAge: 60
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
'check for key property': function (c) {
|
|
64
|
+
assert.ok(c);
|
|
65
|
+
assert.equal(c.key, 'test');
|
|
66
|
+
},
|
|
67
|
+
'check for value property': function (c) {
|
|
68
|
+
assert.equal(c.value, 'b');
|
|
69
|
+
},
|
|
70
|
+
'check for maxAge': function (c) {
|
|
71
|
+
assert.equal(c.maxAge, 60);
|
|
72
|
+
},
|
|
73
|
+
'check for default values for unspecified properties': function (c) {
|
|
74
|
+
assert.equal(c.expires, "Infinity");
|
|
75
|
+
assert.equal(c.secure, false);
|
|
76
|
+
assert.equal(c.httpOnly, false);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
.addBatch({
|
|
81
|
+
"expiry option": {
|
|
82
|
+
topic: function () {
|
|
83
|
+
var cb = this.callback;
|
|
84
|
+
var cj = new CookieJar();
|
|
85
|
+
cj.setCookie('near=expiry; Domain=example.com; Path=/; Max-Age=1', 'http://www.example.com', at(-1), function (err, cookie) {
|
|
86
|
+
|
|
87
|
+
cb(err, {cj: cj, cookie: cookie});
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
"set the cookie": function (t) {
|
|
91
|
+
assert.ok(t.cookie, "didn't set?!");
|
|
92
|
+
assert.equal(t.cookie.key, 'near');
|
|
93
|
+
},
|
|
94
|
+
"then, retrieving": {
|
|
95
|
+
topic: function (t) {
|
|
96
|
+
var cb = this.callback;
|
|
97
|
+
setTimeout(function () {
|
|
98
|
+
t.cj.getCookies('http://www.example.com', {http: true, expire: false}, function (err, cookies) {
|
|
99
|
+
t.cookies = cookies;
|
|
100
|
+
cb(err, t);
|
|
101
|
+
});
|
|
102
|
+
}, 2000);
|
|
103
|
+
},
|
|
104
|
+
"got the cookie": function (t) {
|
|
105
|
+
assert.lengthOf(t.cookies, 1);
|
|
106
|
+
assert.equal(t.cookies[0].key, 'near');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
.addBatch({
|
|
112
|
+
"allPaths option": {
|
|
113
|
+
topic: function () {
|
|
114
|
+
var cj = new CookieJar();
|
|
115
|
+
var tasks = [];
|
|
116
|
+
tasks.push(cj.setCookie.bind(cj, 'nopath_dom=qq; Path=/; Domain=example.com', 'http://example.com', {}));
|
|
117
|
+
tasks.push(cj.setCookie.bind(cj, 'path_dom=qq; Path=/foo; Domain=example.com', 'http://example.com', {}));
|
|
118
|
+
tasks.push(cj.setCookie.bind(cj, 'nopath_host=qq; Path=/', 'http://www.example.com', {}));
|
|
119
|
+
tasks.push(cj.setCookie.bind(cj, 'path_host=qq; Path=/foo', 'http://www.example.com', {}));
|
|
120
|
+
tasks.push(cj.setCookie.bind(cj, 'other=qq; Path=/', 'http://other.example.com/', {}));
|
|
121
|
+
tasks.push(cj.setCookie.bind(cj, 'other2=qq; Path=/foo', 'http://other.example.com/foo', {}));
|
|
122
|
+
var cb = this.callback;
|
|
123
|
+
async.parallel(tasks, function (err, results) {
|
|
124
|
+
cb(err, {cj: cj, cookies: results});
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
"all set": function (t) {
|
|
128
|
+
assert.equal(t.cookies.length, 6);
|
|
129
|
+
assert.ok(t.cookies.every(function (c) {
|
|
130
|
+
return !!c
|
|
131
|
+
}));
|
|
132
|
+
},
|
|
133
|
+
"getting without allPaths": {
|
|
134
|
+
topic: function (t) {
|
|
135
|
+
var cb = this.callback;
|
|
136
|
+
var cj = t.cj;
|
|
137
|
+
cj.getCookies('http://www.example.com/', {}, function (err, cookies) {
|
|
138
|
+
cb(err, {cj: cj, cookies: cookies});
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
"found just two cookies": function (t) {
|
|
142
|
+
assert.equal(t.cookies.length, 2);
|
|
143
|
+
},
|
|
144
|
+
"all are path=/": function (t) {
|
|
145
|
+
assert.ok(t.cookies.every(function (c) {
|
|
146
|
+
return c.path === '/'
|
|
147
|
+
}));
|
|
148
|
+
},
|
|
149
|
+
"no 'other' cookies": function (t) {
|
|
150
|
+
assert.ok(!t.cookies.some(function (c) {
|
|
151
|
+
return (/^other/).test(c.name)
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
"getting without allPaths for /foo": {
|
|
156
|
+
topic: function (t) {
|
|
157
|
+
var cb = this.callback;
|
|
158
|
+
var cj = t.cj;
|
|
159
|
+
cj.getCookies('http://www.example.com/foo', {}, function (err, cookies) {
|
|
160
|
+
cb(err, {cj: cj, cookies: cookies});
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
"found four cookies": function (t) {
|
|
164
|
+
assert.equal(t.cookies.length, 4);
|
|
165
|
+
},
|
|
166
|
+
"no 'other' cookies": function (t) {
|
|
167
|
+
assert.ok(!t.cookies.some(function (c) {
|
|
168
|
+
return (/^other/).test(c.name)
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
"getting with allPaths:true": {
|
|
173
|
+
topic: function (t) {
|
|
174
|
+
var cb = this.callback;
|
|
175
|
+
var cj = t.cj;
|
|
176
|
+
cj.getCookies('http://www.example.com/', {allPaths: true}, function (err, cookies) {
|
|
177
|
+
cb(err, {cj: cj, cookies: cookies});
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
"found four cookies": function (t) {
|
|
181
|
+
assert.equal(t.cookies.length, 4);
|
|
182
|
+
},
|
|
183
|
+
"no 'other' cookies": function (t) {
|
|
184
|
+
assert.ok(!t.cookies.some(function (c) {
|
|
185
|
+
return (/^other/).test(c.name)
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
.addBatch({
|
|
192
|
+
"Remove cookies": {
|
|
193
|
+
topic: function () {
|
|
194
|
+
var jar = new CookieJar();
|
|
195
|
+
var cookie = Cookie.parse("a=b; Domain=example.com; Path=/");
|
|
196
|
+
var cookie2 = Cookie.parse("a=b; Domain=foo.com; Path=/");
|
|
197
|
+
var cookie3 = Cookie.parse("foo=bar; Domain=foo.com; Path=/");
|
|
198
|
+
jar.setCookie(cookie, 'http://example.com/index.html', function () {
|
|
199
|
+
});
|
|
200
|
+
jar.setCookie(cookie2, 'http://foo.com/index.html', function () {
|
|
201
|
+
});
|
|
202
|
+
jar.setCookie(cookie3, 'http://foo.com/index.html', function () {
|
|
203
|
+
});
|
|
204
|
+
return jar;
|
|
205
|
+
},
|
|
206
|
+
"all from matching domain": function (jar) {
|
|
207
|
+
jar.store.removeCookies('example.com', null, function (err) {
|
|
208
|
+
assert(err == null);
|
|
209
|
+
|
|
210
|
+
jar.store.findCookies('example.com', null, function (err, cookies) {
|
|
211
|
+
assert(err == null);
|
|
212
|
+
assert(cookies != null);
|
|
213
|
+
assert(cookies.length === 0, 'cookie was not removed');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
jar.store.findCookies('foo.com', null, function (err, cookies) {
|
|
217
|
+
assert(err == null);
|
|
218
|
+
assert(cookies != null);
|
|
219
|
+
assert(cookies.length === 2, 'cookies should not have been removed');
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
},
|
|
223
|
+
"from cookie store matching domain and key": function (jar) {
|
|
224
|
+
jar.store.removeCookie('foo.com', '/', 'foo', function (err) {
|
|
225
|
+
assert(err == null);
|
|
226
|
+
|
|
227
|
+
jar.store.findCookies('foo.com', null, function (err, cookies) {
|
|
228
|
+
assert(err == null);
|
|
229
|
+
assert(cookies != null);
|
|
230
|
+
assert(cookies.length === 1, 'cookie was not removed correctly');
|
|
231
|
+
assert(cookies[0].key === 'a', 'wrong cookie was removed');
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
})
|
|
237
|
+
.addBatch({
|
|
238
|
+
"Synchronous CookieJar": {
|
|
239
|
+
"setCookieSync": {
|
|
240
|
+
topic: function () {
|
|
241
|
+
var jar = new CookieJar();
|
|
242
|
+
var cookie = Cookie.parse("a=b; Domain=example.com; Path=/");
|
|
243
|
+
cookie = jar.setCookieSync(cookie, 'http://example.com/index.html');
|
|
244
|
+
return cookie;
|
|
245
|
+
},
|
|
246
|
+
"returns a copy of the cookie": function (cookie) {
|
|
247
|
+
assert.instanceOf(cookie, Cookie);
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
"setCookieSync strict parse error": {
|
|
251
|
+
topic: function () {
|
|
252
|
+
var jar = new CookieJar();
|
|
253
|
+
var opts = {strict: true};
|
|
254
|
+
try {
|
|
255
|
+
jar.setCookieSync("farbe=weiß", 'http://example.com/index.html', opts);
|
|
256
|
+
return false;
|
|
257
|
+
} catch (e) {
|
|
258
|
+
return e;
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
"throws the error": function (err) {
|
|
262
|
+
assert.instanceOf(err, Error);
|
|
263
|
+
assert.equal(err.message, "Cookie failed to parse");
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
"getCookiesSync": {
|
|
267
|
+
topic: function () {
|
|
268
|
+
var jar = new CookieJar();
|
|
269
|
+
var url = 'http://example.com/index.html';
|
|
270
|
+
jar.setCookieSync("a=b; Domain=example.com; Path=/", url);
|
|
271
|
+
jar.setCookieSync("c=d; Domain=example.com; Path=/", url);
|
|
272
|
+
return jar.getCookiesSync(url);
|
|
273
|
+
},
|
|
274
|
+
"returns the cookie array": function (err, cookies) {
|
|
275
|
+
assert.ok(!err);
|
|
276
|
+
assert.ok(Array.isArray(cookies));
|
|
277
|
+
assert.lengthOf(cookies, 2);
|
|
278
|
+
cookies.forEach(function (cookie) {
|
|
279
|
+
assert.instanceOf(cookie, Cookie);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
|
|
284
|
+
"getCookieStringSync": {
|
|
285
|
+
topic: function () {
|
|
286
|
+
var jar = new CookieJar();
|
|
287
|
+
var url = 'http://example.com/index.html';
|
|
288
|
+
jar.setCookieSync("a=b; Domain=example.com; Path=/", url);
|
|
289
|
+
jar.setCookieSync("c=d; Domain=example.com; Path=/", url);
|
|
290
|
+
return jar.getCookieStringSync(url);
|
|
291
|
+
},
|
|
292
|
+
"returns the cookie header string": function (err, str) {
|
|
293
|
+
assert.ok(!err);
|
|
294
|
+
assert.typeOf(str, 'string');
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
"getSetCookieStringsSync": {
|
|
299
|
+
topic: function () {
|
|
300
|
+
var jar = new CookieJar();
|
|
301
|
+
var url = 'http://example.com/index.html';
|
|
302
|
+
jar.setCookieSync("a=b; Domain=example.com; Path=/", url);
|
|
303
|
+
jar.setCookieSync("c=d; Domain=example.com; Path=/", url);
|
|
304
|
+
return jar.getSetCookieStringsSync(url);
|
|
305
|
+
},
|
|
306
|
+
"returns the cookie header string": function (err, headers) {
|
|
307
|
+
assert.ok(!err);
|
|
308
|
+
assert.ok(Array.isArray(headers));
|
|
309
|
+
assert.lengthOf(headers, 2);
|
|
310
|
+
headers.forEach(function (header) {
|
|
311
|
+
assert.typeOf(header, 'string');
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
})
|
|
317
|
+
.addBatch({
|
|
318
|
+
"Synchronous API on async CookieJar": {
|
|
319
|
+
topic: function () {
|
|
320
|
+
return new tough.Store();
|
|
321
|
+
},
|
|
322
|
+
"setCookieSync": {
|
|
323
|
+
topic: function (store) {
|
|
324
|
+
var jar = new CookieJar(store);
|
|
325
|
+
try {
|
|
326
|
+
jar.setCookieSync("a=b", 'http://example.com/index.html');
|
|
327
|
+
return false;
|
|
328
|
+
} catch (e) {
|
|
329
|
+
return e;
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
"fails": function (err) {
|
|
333
|
+
assert.instanceOf(err, Error);
|
|
334
|
+
assert.equal(err.message,
|
|
335
|
+
'CookieJar store is not synchronous; use async API instead.');
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
"getCookiesSync": {
|
|
339
|
+
topic: function (store) {
|
|
340
|
+
var jar = new CookieJar(store);
|
|
341
|
+
try {
|
|
342
|
+
jar.getCookiesSync('http://example.com/index.html');
|
|
343
|
+
return false;
|
|
344
|
+
} catch (e) {
|
|
345
|
+
return e;
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
"fails": function (err) {
|
|
349
|
+
assert.instanceOf(err, Error);
|
|
350
|
+
assert.equal(err.message,
|
|
351
|
+
'CookieJar store is not synchronous; use async API instead.');
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
"getCookieStringSync": {
|
|
355
|
+
topic: function (store) {
|
|
356
|
+
var jar = new CookieJar(store);
|
|
357
|
+
try {
|
|
358
|
+
jar.getCookieStringSync('http://example.com/index.html');
|
|
359
|
+
return false;
|
|
360
|
+
} catch (e) {
|
|
361
|
+
return e;
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
"fails": function (err) {
|
|
365
|
+
assert.instanceOf(err, Error);
|
|
366
|
+
assert.equal(err.message,
|
|
367
|
+
'CookieJar store is not synchronous; use async API instead.');
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
"getSetCookieStringsSync": {
|
|
371
|
+
topic: function (store) {
|
|
372
|
+
var jar = new CookieJar(store);
|
|
373
|
+
try {
|
|
374
|
+
jar.getSetCookieStringsSync('http://example.com/index.html');
|
|
375
|
+
return false;
|
|
376
|
+
} catch (e) {
|
|
377
|
+
return e;
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
"fails": function (err) {
|
|
381
|
+
assert.instanceOf(err, Error);
|
|
382
|
+
assert.equal(err.message,
|
|
383
|
+
'CookieJar store is not synchronous; use async API instead.');
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
})
|
|
388
|
+
.export(module);
|