tough-cookie 3.0.1 → 4.0.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/lib/memstore.js CHANGED
@@ -28,154 +28,163 @@
28
28
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
29
  * POSSIBILITY OF SUCH DAMAGE.
30
30
  */
31
- 'use strict';
32
- var Store = require('./store').Store;
33
- var permuteDomain = require('./permuteDomain').permuteDomain;
34
- var pathMatch = require('./pathMatch').pathMatch;
35
- var util = require('util');
36
-
37
- function MemoryCookieStore() {
38
- Store.call(this);
39
- this.idx = {};
40
- }
41
- util.inherits(MemoryCookieStore, Store);
42
- exports.MemoryCookieStore = MemoryCookieStore;
43
- MemoryCookieStore.prototype.idx = null;
44
-
45
- // Since it's just a struct in RAM, this Store is synchronous
46
- MemoryCookieStore.prototype.synchronous = true;
47
-
48
- // force a default depth:
49
- MemoryCookieStore.prototype.inspect = function() {
50
- return "{ idx: "+util.inspect(this.idx, false, 2)+' }';
51
- };
52
-
53
- // Use the new custom inspection symbol to add the custom inspect function if
54
- // available.
55
- if (util.inspect.custom) {
56
- MemoryCookieStore.prototype[util.inspect.custom] = MemoryCookieStore.prototype.inspect;
57
- }
58
-
59
- MemoryCookieStore.prototype.findCookie = function(domain, path, key, cb) {
60
- if (!this.idx[domain]) {
61
- return cb(null,undefined);
31
+ "use strict";
32
+ const { fromCallback } = require("universalify");
33
+ const Store = require("./store").Store;
34
+ const permuteDomain = require("./permuteDomain").permuteDomain;
35
+ const pathMatch = require("./pathMatch").pathMatch;
36
+ const util = require("util");
37
+
38
+ class MemoryCookieStore extends Store {
39
+ constructor() {
40
+ super();
41
+ this.synchronous = true;
42
+ this.idx = {};
43
+ if (util.inspect.custom) {
44
+ this[util.inspect.custom] = this.inspect;
45
+ }
62
46
  }
63
- if (!this.idx[domain][path]) {
64
- return cb(null,undefined);
47
+
48
+ inspect() {
49
+ return `{ idx: ${util.inspect(this.idx, false, 2)} }`;
65
50
  }
66
- return cb(null,this.idx[domain][path][key]||null);
67
- };
68
51
 
69
- MemoryCookieStore.prototype.findCookies = function(domain, path, cb) {
70
- var results = [];
71
- if (!domain) {
72
- return cb(null,[]);
52
+ findCookie(domain, path, key, cb) {
53
+ if (!this.idx[domain]) {
54
+ return cb(null, undefined);
55
+ }
56
+ if (!this.idx[domain][path]) {
57
+ return cb(null, undefined);
58
+ }
59
+ return cb(null, this.idx[domain][path][key] || null);
73
60
  }
61
+ findCookies(domain, path, allowSpecialUseDomain, cb) {
62
+ const results = [];
63
+ if (typeof allowSpecialUseDomain === "function") {
64
+ cb = allowSpecialUseDomain;
65
+ allowSpecialUseDomain = false;
66
+ }
67
+ if (!domain) {
68
+ return cb(null, []);
69
+ }
74
70
 
75
- var pathMatcher;
76
- if (!path) {
77
- // null means "all paths"
78
- pathMatcher = function matchAll(domainIndex) {
79
- for (var curPath in domainIndex) {
80
- var pathIndex = domainIndex[curPath];
81
- for (var key in pathIndex) {
82
- results.push(pathIndex[key]);
71
+ let pathMatcher;
72
+ if (!path) {
73
+ // null means "all paths"
74
+ pathMatcher = function matchAll(domainIndex) {
75
+ for (const curPath in domainIndex) {
76
+ const pathIndex = domainIndex[curPath];
77
+ for (const key in pathIndex) {
78
+ results.push(pathIndex[key]);
79
+ }
83
80
  }
84
- }
85
- };
81
+ };
82
+ } else {
83
+ pathMatcher = function matchRFC(domainIndex) {
84
+ //NOTE: we should use path-match algorithm from S5.1.4 here
85
+ //(see : https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/canonical_cookie.cc#L299)
86
+ Object.keys(domainIndex).forEach(cookiePath => {
87
+ if (pathMatch(path, cookiePath)) {
88
+ const pathIndex = domainIndex[cookiePath];
89
+ for (const key in pathIndex) {
90
+ results.push(pathIndex[key]);
91
+ }
92
+ }
93
+ });
94
+ };
95
+ }
86
96
 
87
- } else {
88
- pathMatcher = function matchRFC(domainIndex) {
89
- //NOTE: we should use path-match algorithm from S5.1.4 here
90
- //(see : https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/canonical_cookie.cc#L299)
91
- Object.keys(domainIndex).forEach(function (cookiePath) {
92
- if (pathMatch(path, cookiePath)) {
93
- var pathIndex = domainIndex[cookiePath];
97
+ const domains = permuteDomain(domain, allowSpecialUseDomain) || [domain];
98
+ const idx = this.idx;
99
+ domains.forEach(curDomain => {
100
+ const domainIndex = idx[curDomain];
101
+ if (!domainIndex) {
102
+ return;
103
+ }
104
+ pathMatcher(domainIndex);
105
+ });
94
106
 
95
- for (var key in pathIndex) {
96
- results.push(pathIndex[key]);
97
- }
98
- }
99
- });
100
- };
107
+ cb(null, results);
101
108
  }
102
109
 
103
- var domains = permuteDomain(domain) || [domain];
104
- var idx = this.idx;
105
- domains.forEach(function(curDomain) {
106
- var domainIndex = idx[curDomain];
107
- if (!domainIndex) {
108
- return;
110
+ putCookie(cookie, cb) {
111
+ if (!this.idx[cookie.domain]) {
112
+ this.idx[cookie.domain] = {};
109
113
  }
110
- pathMatcher(domainIndex);
111
- });
112
-
113
- cb(null,results);
114
- };
115
-
116
- MemoryCookieStore.prototype.putCookie = function(cookie, cb) {
117
- if (!this.idx[cookie.domain]) {
118
- this.idx[cookie.domain] = {};
114
+ if (!this.idx[cookie.domain][cookie.path]) {
115
+ this.idx[cookie.domain][cookie.path] = {};
116
+ }
117
+ this.idx[cookie.domain][cookie.path][cookie.key] = cookie;
118
+ cb(null);
119
119
  }
120
- if (!this.idx[cookie.domain][cookie.path]) {
121
- this.idx[cookie.domain][cookie.path] = {};
120
+ updateCookie(oldCookie, newCookie, cb) {
121
+ // updateCookie() may avoid updating cookies that are identical. For example,
122
+ // lastAccessed may not be important to some stores and an equality
123
+ // comparison could exclude that field.
124
+ this.putCookie(newCookie, cb);
122
125
  }
123
- this.idx[cookie.domain][cookie.path][cookie.key] = cookie;
124
- cb(null);
125
- };
126
-
127
- MemoryCookieStore.prototype.updateCookie = function(oldCookie, newCookie, cb) {
128
- // updateCookie() may avoid updating cookies that are identical. For example,
129
- // lastAccessed may not be important to some stores and an equality
130
- // comparison could exclude that field.
131
- this.putCookie(newCookie,cb);
132
- };
133
-
134
- MemoryCookieStore.prototype.removeCookie = function(domain, path, key, cb) {
135
- if (this.idx[domain] && this.idx[domain][path] && this.idx[domain][path][key]) {
136
- delete this.idx[domain][path][key];
126
+ removeCookie(domain, path, key, cb) {
127
+ if (
128
+ this.idx[domain] &&
129
+ this.idx[domain][path] &&
130
+ this.idx[domain][path][key]
131
+ ) {
132
+ delete this.idx[domain][path][key];
133
+ }
134
+ cb(null);
137
135
  }
138
- cb(null);
139
- };
140
-
141
- MemoryCookieStore.prototype.removeCookies = function(domain, path, cb) {
142
- if (this.idx[domain]) {
143
- if (path) {
144
- delete this.idx[domain][path];
145
- } else {
146
- delete this.idx[domain];
136
+ removeCookies(domain, path, cb) {
137
+ if (this.idx[domain]) {
138
+ if (path) {
139
+ delete this.idx[domain][path];
140
+ } else {
141
+ delete this.idx[domain];
142
+ }
147
143
  }
144
+ return cb(null);
148
145
  }
149
- return cb(null);
150
- };
151
-
152
- MemoryCookieStore.prototype.removeAllCookies = function(cb) {
153
- this.idx = {};
154
- return cb(null);
155
- }
156
-
157
- MemoryCookieStore.prototype.getAllCookies = function(cb) {
158
- var cookies = [];
159
- var idx = this.idx;
160
-
161
- var domains = Object.keys(idx);
162
- domains.forEach(function(domain) {
163
- var paths = Object.keys(idx[domain]);
164
- paths.forEach(function(path) {
165
- var keys = Object.keys(idx[domain][path]);
166
- keys.forEach(function(key) {
167
- if (key !== null) {
168
- cookies.push(idx[domain][path][key]);
169
- }
146
+ removeAllCookies(cb) {
147
+ this.idx = {};
148
+ return cb(null);
149
+ }
150
+ getAllCookies(cb) {
151
+ const cookies = [];
152
+ const idx = this.idx;
153
+
154
+ const domains = Object.keys(idx);
155
+ domains.forEach(domain => {
156
+ const paths = Object.keys(idx[domain]);
157
+ paths.forEach(path => {
158
+ const keys = Object.keys(idx[domain][path]);
159
+ keys.forEach(key => {
160
+ if (key !== null) {
161
+ cookies.push(idx[domain][path][key]);
162
+ }
163
+ });
170
164
  });
171
165
  });
172
- });
173
166
 
174
- // Sort by creationIndex so deserializing retains the creation order.
175
- // When implementing your own store, this SHOULD retain the order too
176
- cookies.sort(function(a,b) {
177
- return (a.creationIndex||0) - (b.creationIndex||0);
178
- });
167
+ // Sort by creationIndex so deserializing retains the creation order.
168
+ // When implementing your own store, this SHOULD retain the order too
169
+ cookies.sort((a, b) => {
170
+ return (a.creationIndex || 0) - (b.creationIndex || 0);
171
+ });
172
+
173
+ cb(null, cookies);
174
+ }
175
+ }
179
176
 
180
- cb(null, cookies);
181
- };
177
+ [
178
+ "findCookie",
179
+ "findCookies",
180
+ "putCookie",
181
+ "updateCookie",
182
+ "removeCookie",
183
+ "removeCookies",
184
+ "removeAllCookies",
185
+ "getAllCookies"
186
+ ].forEach(name => {
187
+ MemoryCookieStore[name] = fromCallback(MemoryCookieStore.prototype[name]);
188
+ });
189
+
190
+ exports.MemoryCookieStore = MemoryCookieStore;
package/lib/pathMatch.js CHANGED
@@ -33,13 +33,13 @@
33
33
  * "A request-path path-matches a given cookie-path if at least one of the
34
34
  * following conditions holds:"
35
35
  */
36
- function pathMatch (reqPath, cookiePath) {
36
+ function pathMatch(reqPath, cookiePath) {
37
37
  // "o The cookie-path and the request-path are identical."
38
38
  if (cookiePath === reqPath) {
39
39
  return true;
40
40
  }
41
41
 
42
- var idx = reqPath.indexOf(cookiePath);
42
+ const idx = reqPath.indexOf(cookiePath);
43
43
  if (idx === 0) {
44
44
  // "o The cookie-path is a prefix of the request-path, and the last
45
45
  // character of the cookie-path is %x2F ("/")."
@@ -29,12 +29,26 @@
29
29
  * POSSIBILITY OF SUCH DAMAGE.
30
30
  */
31
31
  "use strict";
32
- var pubsuffix = require('./pubsuffix-psl');
32
+ const pubsuffix = require("./pubsuffix-psl");
33
33
 
34
34
  // Gives the permutation of all possible domainMatch()es of a given domain. The
35
35
  // array is in shortest-to-longest order. Handy for indexing.
36
- function permuteDomain (domain) {
37
- var pubSuf = pubsuffix.getPublicSuffix(domain);
36
+ const SPECIAL_USE_DOMAINS = ["local"]; // RFC 6761
37
+ function permuteDomain(domain, allowSpecialUseDomain) {
38
+ let pubSuf = null;
39
+ if (allowSpecialUseDomain) {
40
+ const domainParts = domain.split(".");
41
+ if (SPECIAL_USE_DOMAINS.includes(domainParts[domainParts.length - 1])) {
42
+ pubSuf = `${domainParts[domainParts.length - 2]}.${
43
+ domainParts[domainParts.length - 1]
44
+ }`;
45
+ } else {
46
+ pubSuf = pubsuffix.getPublicSuffix(domain);
47
+ }
48
+ } else {
49
+ pubSuf = pubsuffix.getPublicSuffix(domain);
50
+ }
51
+
38
52
  if (!pubSuf) {
39
53
  return null;
40
54
  }
@@ -42,12 +56,12 @@ function permuteDomain (domain) {
42
56
  return [domain];
43
57
  }
44
58
 
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];
59
+ const prefix = domain.slice(0, -(pubSuf.length + 1)); // ".example.com"
60
+ const parts = prefix.split(".").reverse();
61
+ let cur = pubSuf;
62
+ const permutations = [cur];
49
63
  while (parts.length) {
50
- cur = parts.shift() + '.' + cur;
64
+ cur = `${parts.shift()}.${cur}`;
51
65
  permutations.push(cur);
52
66
  }
53
67
  return permutations;
@@ -28,8 +28,8 @@
28
28
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
29
  * POSSIBILITY OF SUCH DAMAGE.
30
30
  */
31
- 'use strict';
32
- var psl = require('psl');
31
+ "use strict";
32
+ const psl = require("psl");
33
33
 
34
34
  function getPublicSuffix(domain) {
35
35
  return psl.get(domain);
package/lib/store.js CHANGED
@@ -28,48 +28,49 @@
28
28
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
29
  * POSSIBILITY OF SUCH DAMAGE.
30
30
  */
31
- 'use strict';
31
+ "use strict";
32
32
  /*jshint unused:false */
33
33
 
34
- function Store() {
35
- }
36
- exports.Store = Store;
34
+ class Store {
35
+ constructor() {
36
+ this.synchronous = false;
37
+ }
37
38
 
38
- // Stores may be synchronous, but are still required to use a
39
- // Continuation-Passing Style API. The CookieJar itself will expose a "*Sync"
40
- // API that converts from synchronous-callbacks to imperative style.
41
- Store.prototype.synchronous = false;
39
+ findCookie(domain, path, key, cb) {
40
+ throw new Error("findCookie is not implemented");
41
+ }
42
42
 
43
- Store.prototype.findCookie = function(domain, path, key, cb) {
44
- throw new Error('findCookie is not implemented');
45
- };
43
+ findCookies(domain, path, allowSpecialUseDomain, cb) {
44
+ throw new Error("findCookies is not implemented");
45
+ }
46
46
 
47
- Store.prototype.findCookies = function(domain, path, cb) {
48
- throw new Error('findCookies is not implemented');
49
- };
47
+ putCookie(cookie, cb) {
48
+ throw new Error("putCookie is not implemented");
49
+ }
50
50
 
51
- Store.prototype.putCookie = function(cookie, cb) {
52
- throw new Error('putCookie is not implemented');
53
- };
51
+ updateCookie(oldCookie, newCookie, cb) {
52
+ // recommended default implementation:
53
+ // return this.putCookie(newCookie, cb);
54
+ throw new Error("updateCookie is not implemented");
55
+ }
54
56
 
55
- Store.prototype.updateCookie = function(oldCookie, newCookie, cb) {
56
- // recommended default implementation:
57
- // return this.putCookie(newCookie, cb);
58
- throw new Error('updateCookie is not implemented');
59
- };
57
+ removeCookie(domain, path, key, cb) {
58
+ throw new Error("removeCookie is not implemented");
59
+ }
60
60
 
61
- Store.prototype.removeCookie = function(domain, path, key, cb) {
62
- throw new Error('removeCookie is not implemented');
63
- };
61
+ removeCookies(domain, path, cb) {
62
+ throw new Error("removeCookies is not implemented");
63
+ }
64
64
 
65
- Store.prototype.removeCookies = function(domain, path, cb) {
66
- throw new Error('removeCookies is not implemented');
67
- };
65
+ removeAllCookies(cb) {
66
+ throw new Error("removeAllCookies is not implemented");
67
+ }
68
68
 
69
- Store.prototype.removeAllCookies = function(cb) {
70
- throw new Error('removeAllCookies is not implemented');
69
+ getAllCookies(cb) {
70
+ throw new Error(
71
+ "getAllCookies is not implemented (therefore jar cannot be serialized)"
72
+ );
73
+ }
71
74
  }
72
75
 
73
- Store.prototype.getAllCookies = function(cb) {
74
- throw new Error('getAllCookies is not implemented (therefore jar cannot be serialized)');
75
- };
76
+ exports.Store = Store;
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- module.exports = '3.0.1'
2
+ module.exports = '4.0.0'
package/package.json CHANGED
@@ -6,28 +6,52 @@
6
6
  },
7
7
  "contributors": [
8
8
  {
9
- "name": "Alexander Savin",
10
- "website": "https://github.com/apsavin"
9
+ "name": "Ivan Nikulin",
10
+ "website": "https://github.com/inikulin"
11
+ },
12
+ {
13
+ "name": "Shivan Kaul Sahib",
14
+ "website": "https://github.com/ShivanKaul"
15
+ },
16
+ {
17
+ "name": "Clint Ruoho",
18
+ "website": "https://github.com/ruoho"
11
19
  },
12
20
  {
13
21
  "name": "Ian Livingstone",
14
22
  "website": "https://github.com/ianlivingstone"
15
23
  },
16
24
  {
17
- "name": "Ivan Nikulin",
18
- "website": "https://github.com/inikulin"
25
+ "name": "Andrew Waterman",
26
+ "website": "https://github.com/awaterma"
19
27
  },
20
28
  {
21
- "name": "Lalit Kapoor",
22
- "website": "https://github.com/lalitkapoor"
29
+ "name": "Michael de Libero ",
30
+ "website": "https://github.com/medelibero-sfdc"
23
31
  },
24
32
  {
25
- "name": "Sam Thompson",
26
- "website": "https://github.com/sambthompson"
33
+ "name": "Jonathan Stewmon",
34
+ "website": "https://github.com/jstewmon"
35
+ },
36
+ {
37
+ "name": "Miguel Roncancio",
38
+ "website": "https://github.com/miggs125"
27
39
  },
28
40
  {
29
41
  "name": "Sebastian Mayr",
30
42
  "website": "https://github.com/Sebmaster"
43
+ },
44
+ {
45
+ "name": "Alexander Savin",
46
+ "website": "https://github.com/apsavin"
47
+ },
48
+ {
49
+ "name": "Lalit Kapoor",
50
+ "website": "https://github.com/lalitkapoor"
51
+ },
52
+ {
53
+ "name": "Sam Thompson",
54
+ "website": "https://github.com/sambthompson"
31
55
  }
32
56
  ],
33
57
  "license": "BSD-3-Clause",
@@ -43,7 +67,7 @@
43
67
  "RFC6265",
44
68
  "RFC2965"
45
69
  ],
46
- "version": "3.0.1",
70
+ "version": "4.0.0",
47
71
  "homepage": "https://github.com/salesforce/tough-cookie",
48
72
  "repository": {
49
73
  "type": "git",
@@ -59,21 +83,27 @@
59
83
  "scripts": {
60
84
  "version": "genversion lib/version.js && git add lib/version.js",
61
85
  "test": "vows test/*_test.js",
62
- "cover": "nyc --reporter=lcov --reporter=html vows test/*_test.js"
86
+ "cover": "nyc --reporter=lcov --reporter=html vows test/*_test.js",
87
+ "eslint": "eslint --env node --ext .js .",
88
+ "prettier": "prettier '**/*.{json,ts,yaml,md}'",
89
+ "format": "npm run eslint -- --fix"
63
90
  },
64
91
  "engines": {
65
92
  "node": ">=6"
66
93
  },
67
94
  "devDependencies": {
68
- "async": "^1.4.2",
95
+ "async": "^2.6.2",
96
+ "eslint": "^5.16.0",
97
+ "eslint-config-prettier": "^4.2.0",
98
+ "eslint-plugin-prettier": "^3.0.1",
69
99
  "genversion": "^2.1.0",
70
- "nyc": "^11.6.0",
71
- "string.prototype.repeat": "^0.2.0",
100
+ "nyc": "^14.0.0",
101
+ "prettier": "^1.17.0",
72
102
  "vows": "^0.8.2"
73
103
  },
74
104
  "dependencies": {
75
- "ip-regex": "^2.1.0",
76
- "psl": "^1.1.28",
77
- "punycode": "^2.1.1"
105
+ "psl": "^1.1.33",
106
+ "punycode": "^2.1.1",
107
+ "universalify": "^0.1.2"
78
108
  }
79
109
  }