tough-cookie 0.12.1 → 1.2.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 +48 -38
- package/generate-pubsuffix.js +114 -60
- package/lib/cookie.js +163 -182
- package/lib/memstore.js +45 -26
- package/lib/pathMatch.js +61 -0
- package/lib/permuteDomain.js +56 -0
- package/lib/pubsuffix.js +52 -23
- package/lib/store.js +30 -0
- package/package.json +8 -11
- package/public-suffix.txt +5511 -661
- package/test/api_test.js +372 -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 +294 -0
- package/test/regression_test.js +143 -0
- package/test.js +0 -1625
package/lib/memstore.js
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
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
|
-
var tough = require('./cookie');
|
|
3
32
|
var Store = require('./store').Store;
|
|
4
|
-
var permuteDomain =
|
|
5
|
-
var
|
|
33
|
+
var permuteDomain = require('./permuteDomain').permuteDomain;
|
|
34
|
+
var pathMatch = require('./pathMatch').pathMatch;
|
|
6
35
|
var util = require('util');
|
|
7
36
|
|
|
8
37
|
function MemoryCookieStore() {
|
|
@@ -37,7 +66,7 @@ MemoryCookieStore.prototype.findCookies = function(domain, path, cb) {
|
|
|
37
66
|
|
|
38
67
|
var pathMatcher;
|
|
39
68
|
if (!path) {
|
|
40
|
-
// null
|
|
69
|
+
// null means "all paths"
|
|
41
70
|
pathMatcher = function matchAll(domainIndex) {
|
|
42
71
|
for (var curPath in domainIndex) {
|
|
43
72
|
var pathIndex = domainIndex[curPath];
|
|
@@ -47,30 +76,20 @@ MemoryCookieStore.prototype.findCookies = function(domain, path, cb) {
|
|
|
47
76
|
}
|
|
48
77
|
};
|
|
49
78
|
|
|
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
79
|
} else {
|
|
62
|
-
var paths = permutePath(path) || [path];
|
|
63
80
|
pathMatcher = function matchRFC(domainIndex) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
81
|
+
//NOTE: we should use path-match algorithm from S5.1.4 here
|
|
82
|
+
//(see : https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/canonical_cookie.cc#L299)
|
|
83
|
+
Object.keys(domainIndex).forEach(function (cookiePath) {
|
|
84
|
+
if (pathMatch(path, cookiePath)) {
|
|
85
|
+
var pathIndex = domainIndex[cookiePath];
|
|
86
|
+
|
|
87
|
+
for (var key in pathIndex) {
|
|
88
|
+
results.push(pathIndex[key]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
};
|
|
74
93
|
}
|
|
75
94
|
|
|
76
95
|
var domains = permuteDomain(domain) || [domain];
|
package/lib/pathMatch.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
/*
|
|
33
|
+
* "A request-path path-matches a given cookie-path if at least one of the
|
|
34
|
+
* following conditions holds:"
|
|
35
|
+
*/
|
|
36
|
+
function pathMatch (reqPath, cookiePath) {
|
|
37
|
+
// "o The cookie-path and the request-path are identical."
|
|
38
|
+
if (cookiePath === reqPath) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var idx = reqPath.indexOf(cookiePath);
|
|
43
|
+
if (idx === 0) {
|
|
44
|
+
// "o The cookie-path is a prefix of the request-path, and the last
|
|
45
|
+
// character of the cookie-path is %x2F ("/")."
|
|
46
|
+
if (cookiePath.substr(-1) === "/") {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// " o The cookie-path is a prefix of the request-path, and the first
|
|
51
|
+
// character of the request-path that is not included in the cookie- path
|
|
52
|
+
// is a %x2F ("/") character."
|
|
53
|
+
if (reqPath.substr(cookiePath.length, 1) === "/") {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.pathMatch = pathMatch;
|
|
@@ -0,0 +1,56 @@
|
|
|
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 pubsuffix = require('./pubsuffix');
|
|
33
|
+
|
|
34
|
+
// Gives the permutation of all possible domainMatch()es of a given domain. The
|
|
35
|
+
// array is in shortest-to-longest order. Handy for indexing.
|
|
36
|
+
function permuteDomain (domain) {
|
|
37
|
+
var pubSuf = pubsuffix.getPublicSuffix(domain);
|
|
38
|
+
if (!pubSuf) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (pubSuf == domain) {
|
|
42
|
+
return [domain];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
var prefix = domain.slice(0, -(pubSuf.length + 1)); // ".example.com"
|
|
46
|
+
var parts = prefix.split('.').reverse();
|
|
47
|
+
var cur = pubSuf;
|
|
48
|
+
var permutations = [cur];
|
|
49
|
+
while (parts.length) {
|
|
50
|
+
cur = parts.shift() + '.' + cur;
|
|
51
|
+
permutations.push(cur);
|
|
52
|
+
}
|
|
53
|
+
return permutations;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.permuteDomain = permuteDomain;
|