tough-cookie 0.10.0 → 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/lib/memstore.js CHANGED
@@ -1,32 +1,73 @@
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';
1
32
  var tough = require('./cookie');
33
+ var Store = require('./store').Store;
2
34
  var permuteDomain = tough.permuteDomain;
3
- var permutePath = tough.permutePath;
35
+ var pathMatch = tough.pathMatch;
4
36
  var util = require('util');
5
37
 
6
38
  function MemoryCookieStore() {
39
+ Store.call(this);
7
40
  this.idx = {};
8
41
  }
9
- module.exports.MemoryCookieStore = MemoryCookieStore;
42
+ util.inherits(MemoryCookieStore, Store);
43
+ exports.MemoryCookieStore = MemoryCookieStore;
10
44
  MemoryCookieStore.prototype.idx = null;
45
+ MemoryCookieStore.prototype.synchronous = true;
11
46
 
12
47
  // force a default depth:
13
- MemoryCookieStore.prototype.inspect = function inspect() {
48
+ MemoryCookieStore.prototype.inspect = function() {
14
49
  return "{ idx: "+util.inspect(this.idx, false, 2)+' }';
15
50
  };
16
51
 
17
- MemoryCookieStore.prototype.findCookie = function findCookie(domain, path, key, cb) {
18
- if (!this.idx[domain]) return cb(null,undefined);
19
- if (!this.idx[domain][path]) return cb(null,undefined);
52
+ MemoryCookieStore.prototype.findCookie = function(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
+ }
20
59
  return cb(null,this.idx[domain][path][key]||null);
21
60
  };
22
61
 
23
- MemoryCookieStore.prototype.findCookies = function findCookies(domain, path, cb) {
62
+ MemoryCookieStore.prototype.findCookies = function(domain, path, cb) {
24
63
  var results = [];
25
- if (!domain) return cb(null,[]);
64
+ if (!domain) {
65
+ return cb(null,[]);
66
+ }
26
67
 
27
68
  var pathMatcher;
28
69
  if (!path) {
29
- // null or '/' means "all paths"
70
+ // null means "all paths"
30
71
  pathMatcher = function matchAll(domainIndex) {
31
72
  for (var curPath in domainIndex) {
32
73
  var pathIndex = domainIndex[curPath];
@@ -36,42 +77,42 @@ MemoryCookieStore.prototype.findCookies = function findCookies(domain, path, cb)
36
77
  }
37
78
  };
38
79
 
39
- } else if (path === '/') {
40
- pathMatcher = function matchSlash(domainIndex) {
41
- var pathIndex = domainIndex['/'];
42
- if (!pathIndex) return;
43
- for (var key in pathIndex) {
44
- results.push(pathIndex[key]);
45
- }
46
- };
47
-
48
80
  } else {
49
- var paths = permutePath(path) || [path];
50
81
  pathMatcher = function matchRFC(domainIndex) {
51
- paths.forEach(function(curPath) {
52
- var pathIndex = domainIndex[curPath];
53
- if (!pathIndex) return;
54
- for (var key in pathIndex) {
55
- results.push(pathIndex[key]);
56
- }
57
- });
58
- };
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
+ };
59
94
  }
60
95
 
61
96
  var domains = permuteDomain(domain) || [domain];
62
97
  var idx = this.idx;
63
98
  domains.forEach(function(curDomain) {
64
99
  var domainIndex = idx[curDomain];
65
- if (!domainIndex) return;
100
+ if (!domainIndex) {
101
+ return;
102
+ }
66
103
  pathMatcher(domainIndex);
67
104
  });
68
105
 
69
106
  cb(null,results);
70
107
  };
71
108
 
72
- MemoryCookieStore.prototype.putCookie = function putCookie(cookie, cb) {
73
- if (!this.idx[cookie.domain]) this.idx[cookie.domain] = {};
74
- if (!this.idx[cookie.domain][cookie.path]) this.idx[cookie.domain][cookie.path] = {};
109
+ MemoryCookieStore.prototype.putCookie = function(cookie, cb) {
110
+ if (!this.idx[cookie.domain]) {
111
+ this.idx[cookie.domain] = {};
112
+ }
113
+ if (!this.idx[cookie.domain][cookie.path]) {
114
+ this.idx[cookie.domain][cookie.path] = {};
115
+ }
75
116
  this.idx[cookie.domain][cookie.path][cookie.key] = cookie;
76
117
  cb(null);
77
118
  };
@@ -91,7 +132,7 @@ MemoryCookieStore.prototype.removeCookie = function removeCookie(domain, path, k
91
132
  };
92
133
 
93
134
  MemoryCookieStore.prototype.removeCookies = function removeCookies(domain, path, cb) {
94
- if (!this.idx[domain]) {
135
+ if (this.idx[domain]) {
95
136
  if (path) {
96
137
  delete this.idx[domain][path];
97
138
  } else {
package/lib/pubsuffix.js CHANGED
@@ -4,25 +4,35 @@
4
4
  ****************************************************/
5
5
 
6
6
  module.exports.getPublicSuffix = function getPublicSuffix(domain) {
7
- /*
8
- * Copyright GoInstant, Inc. and other contributors. All rights reserved.
9
- * Permission is hereby granted, free of charge, to any person obtaining a copy
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
- * The above copyright notice and this permission notice shall be included in
17
- * all copies or substantial portions of the Software.
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
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
- * IN THE SOFTWARE.
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 ADDED
@@ -0,0 +1,67 @@
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
+ /*jshint unused:false */
33
+
34
+ function Store() {
35
+ }
36
+ exports.Store = Store;
37
+
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;
42
+
43
+ Store.prototype.findCookie = function(domain, path, key, cb) {
44
+ throw new Error('findCookie is not implemented');
45
+ };
46
+
47
+ Store.prototype.findCookies = function(domain, path, cb) {
48
+ throw new Error('findCookies is not implemented');
49
+ };
50
+
51
+ Store.prototype.putCookie = function(cookie, cb) {
52
+ throw new Error('putCookie is not implemented');
53
+ };
54
+
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
+ };
60
+
61
+ Store.prototype.removeCookie = function(domain, path, key, cb) {
62
+ throw new Error('removeCookie is not implemented');
63
+ };
64
+
65
+ Store.prototype.removeCookies = function removeCookies(domain, path, cb) {
66
+ throw new Error('removeCookies is not implemented');
67
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "author": "GoInstant Inc., a salesforce.com company",
3
- "license": "MIT",
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,18 +13,18 @@
13
13
  "RFC6265",
14
14
  "RFC2965"
15
15
  ],
16
- "version": "0.10.0",
17
- "homepage": "https://github.com/goinstant/node-cookie",
16
+ "version": "0.13.0",
17
+ "homepage": "https://github.com/goinstant/tough-cookie",
18
18
  "repository": {
19
19
  "type": "git",
20
- "url": "git://github.com/goinstant/node-cookie.git"
20
+ "url": "git://github.com/goinstant/tough-cookie.git"
21
21
  },
22
22
  "bugs": {
23
- "url": "https://github.com/goinstant/node-cookie/issues"
23
+ "url": "https://github.com/goinstant/tough-cookie/issues"
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"