tough-cookie 1.2.0 → 2.2.1

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/test/ietf_test.js DELETED
@@ -1,106 +0,0 @@
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
-
32
- 'use strict';
33
- var vows = require('vows');
34
- var assert = require('assert');
35
- var fs = require('fs');
36
- var path = require('path');
37
- var url = require('url');
38
- var tough = require('../lib/cookie');
39
- var Cookie = tough.Cookie;
40
- var CookieJar = tough.CookieJar;
41
-
42
- function readJson(filePath) {
43
- filePath = path.join(__dirname, filePath);
44
- return JSON.parse(fs.readFileSync(filePath).toString());
45
- }
46
-
47
- function setGetCookieVows() {
48
- var theVows = {};
49
- var data = readJson('./ietf_data/parser.json');
50
-
51
- data.forEach(function (testCase) {
52
- theVows[testCase.test] = function () {
53
- var jar = new CookieJar();
54
- var expected = testCase['sent']
55
- var sentFrom = 'http://home.example.org/cookie-parser?' + testCase.test;
56
- var sentTo = testCase['sent-to'] ?
57
- url.resolve('http://home.example.org', testCase['sent-to']) :
58
- 'http://home.example.org/cookie-parser-result?' + testCase.test;
59
-
60
- testCase['received'].forEach(function (cookieStr) {
61
- jar.setCookieSync(cookieStr, sentFrom, {ignoreError: true});
62
- });
63
-
64
- var actual = jar.getCookiesSync(sentTo);
65
- actual = actual.sort(tough.cookieCompare);
66
-
67
- assert.strictEqual(actual.length, expected.length);
68
-
69
- actual.forEach(function (actualCookie, idx) {
70
- var expectedCookie = expected[idx];
71
- assert.strictEqual(actualCookie.key, expectedCookie.name);
72
- assert.strictEqual(actualCookie.value, expectedCookie.value);
73
- });
74
- };
75
- });
76
-
77
- return {'Set/get cookie tests': theVows};
78
- }
79
-
80
- function dateVows() {
81
- var theVows = {};
82
-
83
- [
84
- './ietf_data/dates/bsd-examples.json',
85
- './ietf_data/dates/examples.json'
86
- ].forEach(function (filePath) {
87
- var data = readJson(filePath);
88
- var fileName = path.basename(filePath);
89
-
90
- data.forEach(function (testCase) {
91
- theVows[fileName + ' : ' + testCase.test] = function () {
92
- var actual = tough.parseDate(testCase.test);
93
- actual = actual ? actual.toUTCString() : null;
94
- assert.strictEqual(actual, testCase.expected);
95
- };
96
- });
97
- });
98
-
99
- return {'Date': theVows};
100
- }
101
-
102
- vows
103
- .describe('IETF http state tests')
104
- .addBatch(setGetCookieVows())
105
- .addBatch(dateVows())
106
- .export(module);
@@ -1,97 +0,0 @@
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
-
32
- 'use strict';
33
- var vows = require('vows');
34
- var assert = require('assert');
35
- var tough = require('../lib/cookie');
36
- var Cookie = tough.Cookie;
37
-
38
- vows
39
- .describe('Lifetime')
40
- .addBatch({
41
- "TTL with max-age": function () {
42
- var c = new Cookie();
43
- c.maxAge = 123;
44
- assert.equal(c.TTL(), 123000);
45
- assert.equal(c.expiryTime(new Date(9000000)), 9123000);
46
- },
47
- "TTL with zero max-age": function () {
48
- var c = new Cookie();
49
- c.key = 'a';
50
- c.value = 'b';
51
- c.maxAge = 0; // should be treated as "earliest representable"
52
- assert.equal(c.TTL(), 0);
53
- assert.equal(c.expiryTime(new Date(9000000)), -Infinity);
54
- assert.ok(!c.validate()); // not valid, really: non-zero-digit *DIGIT
55
- },
56
- "TTL with negative max-age": function () {
57
- var c = new Cookie();
58
- c.key = 'a';
59
- c.value = 'b';
60
- c.maxAge = -1; // should be treated as "earliest representable"
61
- assert.equal(c.TTL(), 0);
62
- assert.equal(c.expiryTime(new Date(9000000)), -Infinity);
63
- assert.ok(!c.validate()); // not valid, really: non-zero-digit *DIGIT
64
- },
65
- "TTL with max-age and expires": function () {
66
- var c = new Cookie();
67
- c.maxAge = 123;
68
- c.expires = new Date(Date.now() + 9000);
69
- assert.equal(c.TTL(), 123000);
70
- assert.ok(c.isPersistent());
71
- },
72
- "TTL with expires": function () {
73
- var c = new Cookie();
74
- var now = Date.now();
75
- c.expires = new Date(now + 9000);
76
- assert.equal(c.TTL(now), 9000);
77
- assert.equal(c.expiryTime(), c.expires.getTime());
78
- },
79
- "TTL with old expires": function () {
80
- var c = new Cookie();
81
- c.setExpires('17 Oct 2010 00:00:00 GMT');
82
- assert.ok(c.TTL() < 0);
83
- assert.ok(c.isPersistent());
84
- },
85
- "default TTL": {
86
- topic: function () {
87
- return new Cookie();
88
- },
89
- "is Infinite-future": function (c) {
90
- assert.equal(c.TTL(), Infinity)
91
- },
92
- "is a 'session' cookie": function (c) {
93
- assert.ok(!c.isPersistent())
94
- }
95
- }
96
- })
97
- .export(module);
@@ -1,294 +0,0 @@
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
-
32
- 'use strict';
33
- var vows = require('vows');
34
- var assert = require('assert');
35
- var tough = require('../lib/cookie');
36
- var Cookie = tough.Cookie;
37
-
38
- vows
39
- .describe('Parsing')
40
- .addBatch({
41
- "simple": {
42
- topic: function() {
43
- return Cookie.parse('a=bcd') || null;
44
- },
45
- "parsed": function(c) { assert.ok(c) },
46
- "key": function(c) { assert.equal(c.key, 'a') },
47
- "value": function(c) { assert.equal(c.value, 'bcd') },
48
- "no path": function(c) { assert.equal(c.path, null) },
49
- "no domain": function(c) { assert.equal(c.domain, null) },
50
- "no extensions": function(c) { assert.ok(!c.extensions) }
51
- },
52
- "with expiry": {
53
- topic: function() {
54
- return Cookie.parse('a=bcd; Expires=Tue, 18 Oct 2011 07:05:03 GMT') || null;
55
- },
56
- "parsed": function(c) { assert.ok(c) },
57
- "key": function(c) { assert.equal(c.key, 'a') },
58
- "value": function(c) { assert.equal(c.value, 'bcd') },
59
- "has expires": function(c) {
60
- assert.ok(c.expires !== Infinity, 'expiry is infinite when it shouldn\'t be');
61
- assert.equal(c.expires.getTime(), 1318921503000);
62
- }
63
- },
64
- "with expiry and path": {
65
- topic: function() {
66
- return Cookie.parse('abc="xyzzy!"; Expires=Tue, 18 Oct 2011 07:05:03 GMT; Path=/aBc') || null;
67
- },
68
- "parsed": function(c) { assert.ok(c) },
69
- "key": function(c) { assert.equal(c.key, 'abc') },
70
- "value": function(c) { assert.equal(c.value, '"xyzzy!"') },
71
- "has expires": function(c) {
72
- assert.ok(c.expires !== Infinity, 'expiry is infinite when it shouldn\'t be');
73
- assert.equal(c.expires.getTime(), 1318921503000);
74
- },
75
- "has path": function(c) { assert.equal(c.path, '/aBc'); },
76
- "no httponly or secure": function(c) {
77
- assert.ok(!c.httpOnly);
78
- assert.ok(!c.secure);
79
- }
80
- },
81
- "with everything": {
82
- topic: function() {
83
- return Cookie.parse('abc="xyzzy!"; Expires=Tue, 18 Oct 2011 07:05:03 GMT; Path=/aBc; Domain=example.com; Secure; HTTPOnly; Max-Age=1234; Foo=Bar; Baz') || null;
84
- },
85
- "parsed": function(c) { assert.ok(c) },
86
- "key": function(c) { assert.equal(c.key, 'abc') },
87
- "value": function(c) { assert.equal(c.value, '"xyzzy!"') },
88
- "has expires": function(c) {
89
- assert.ok(c.expires !== Infinity, 'expiry is infinite when it shouldn\'t be');
90
- assert.equal(c.expires.getTime(), 1318921503000);
91
- },
92
- "has path": function(c) { assert.equal(c.path, '/aBc'); },
93
- "has domain": function(c) { assert.equal(c.domain, 'example.com'); },
94
- "has httponly": function(c) { assert.equal(c.httpOnly, true); },
95
- "has secure": function(c) { assert.equal(c.secure, true); },
96
- "has max-age": function(c) { assert.equal(c.maxAge, 1234); },
97
- "has extensions": function(c) {
98
- assert.ok(c.extensions);
99
- assert.equal(c.extensions[0], 'Foo=Bar');
100
- assert.equal(c.extensions[1], 'Baz');
101
- }
102
- },
103
- "invalid expires": function() {
104
- var c = Cookie.parse("a=b; Expires=xyzzy");
105
- assert.ok(c);
106
- assert.equal(c.expires, Infinity);
107
- },
108
- "zero max-age": function() {
109
- var c = Cookie.parse("a=b; Max-Age=0");
110
- assert.ok(c);
111
- assert.equal(c.maxAge, 0);
112
- },
113
- "negative max-age": function() {
114
- var c = Cookie.parse("a=b; Max-Age=-1");
115
- assert.ok(c);
116
- assert.equal(c.maxAge, -1);
117
- },
118
- "empty domain": function() {
119
- var c = Cookie.parse("a=b; domain=");
120
- assert.ok(c);
121
- assert.equal(c.domain, null);
122
- },
123
- "dot domain": function() {
124
- var c = Cookie.parse("a=b; domain=.");
125
- assert.ok(c);
126
- assert.equal(c.domain, null);
127
- },
128
- "uppercase domain": function() {
129
- var c = Cookie.parse("a=b; domain=EXAMPLE.COM");
130
- assert.ok(c);
131
- assert.equal(c.domain, 'example.com');
132
- },
133
- "trailing dot in domain": {
134
- topic: function() {
135
- return Cookie.parse("a=b; Domain=example.com.", true) || null;
136
- },
137
- "has the domain": function(c) { assert.equal(c.domain,"example.com.") },
138
- "but doesn't validate": function(c) { assert.equal(c.validate(),false) }
139
- },
140
- "empty path": function() {
141
- var c = Cookie.parse("a=b; path=");
142
- assert.ok(c);
143
- assert.equal(c.path, null);
144
- },
145
- "no-slash path": function() {
146
- var c = Cookie.parse("a=b; path=xyzzy");
147
- assert.ok(c);
148
- assert.equal(c.path, null);
149
- },
150
- "trailing semi-colons after path": {
151
- topic: function () {
152
- return [
153
- "a=b; path=/;",
154
- "c=d;;;;"
155
- ];
156
- },
157
- "strips semi-colons": function (t) {
158
- var c1 = Cookie.parse(t[0]);
159
- var c2 = Cookie.parse(t[1]);
160
- assert.ok(c1);
161
- assert.ok(c2);
162
- assert.equal(c1.path, '/');
163
- }
164
- },
165
- "secure-with-value": function() {
166
- var c = Cookie.parse("a=b; Secure=xyzzy");
167
- assert.ok(c);
168
- assert.equal(c.secure, true);
169
- },
170
- "httponly-with-value": function() {
171
- var c = Cookie.parse("a=b; HttpOnly=xyzzy");
172
- assert.ok(c);
173
- assert.equal(c.httpOnly, true);
174
- },
175
- "garbage": {
176
- topic: function() {
177
- return Cookie.parse("\x08", true) || null;
178
- },
179
- "doesn't parse": function(c) { assert.equal(c,null) }
180
- },
181
- "public suffix domain": {
182
- topic: function() {
183
- return Cookie.parse("a=b; domain=kyoto.jp", true) || null;
184
- },
185
- "parses fine": function(c) {
186
- assert.ok(c);
187
- assert.equal(c.domain, 'kyoto.jp');
188
- },
189
- "but fails validation": function(c) {
190
- assert.ok(c);
191
- assert.ok(!c.validate());
192
- }
193
- },
194
- "public suffix foonet.net": {
195
- "top level": {
196
- topic: function() {
197
- return Cookie.parse("a=b; domain=foonet.net") || null;
198
- },
199
- "parses and is valid": function(c) {
200
- assert.ok(c);
201
- assert.equal(c.domain, 'foonet.net');
202
- assert.ok(c.validate());
203
- }
204
- },
205
- "www": {
206
- topic: function() {
207
- return Cookie.parse("a=b; domain=www.foonet.net") || null;
208
- },
209
- "parses and is valid": function(c) {
210
- assert.ok(c);
211
- assert.equal(c.domain, 'www.foonet.net');
212
- assert.ok(c.validate());
213
- }
214
- },
215
- "with a dot": {
216
- topic: function() {
217
- return Cookie.parse("a=b; domain=.foonet.net") || null;
218
- },
219
- "parses and is valid": function(c) {
220
- assert.ok(c);
221
- assert.equal(c.domain, 'foonet.net');
222
- assert.ok(c.validate());
223
- }
224
- }
225
- },
226
- "Ironically, Google 'GAPS' cookie has very little whitespace": {
227
- topic: function() {
228
- return Cookie.parse("GAPS=1:A1aaaaAaAAa1aaAaAaaAAAaaa1a11a:aaaAaAaAa-aaaA1-;Path=/;Expires=Thu, 17-Apr-2014 02:12:29 GMT;Secure;HttpOnly");
229
- },
230
- "parsed": function(c) { assert.ok(c) },
231
- "key": function(c) { assert.equal(c.key, 'GAPS') },
232
- "value": function(c) { assert.equal(c.value, '1:A1aaaaAaAAa1aaAaAaaAAAaaa1a11a:aaaAaAaAa-aaaA1-') },
233
- "path": function(c) {
234
- assert.notEqual(c.path, '/;Expires'); // BUG
235
- assert.equal(c.path, '/');
236
- },
237
- "expires": function(c) {
238
- assert.notEqual(c.expires, Infinity);
239
- assert.equal(c.expires.getTime(), 1397700749000);
240
- },
241
- "secure": function(c) { assert.ok(c.secure) },
242
- "httponly": function(c) { assert.ok(c.httpOnly) }
243
- },
244
- "lots of equal signs": {
245
- topic: function() {
246
- return Cookie.parse("queryPref=b=c&d=e; Path=/f=g; Expires=Thu, 17 Apr 2014 02:12:29 GMT; HttpOnly");
247
- },
248
- "parsed": function(c) { assert.ok(c) },
249
- "key": function(c) { assert.equal(c.key, 'queryPref') },
250
- "value": function(c) { assert.equal(c.value, 'b=c&d=e') },
251
- "path": function(c) {
252
- assert.equal(c.path, '/f=g');
253
- },
254
- "expires": function(c) {
255
- assert.notEqual(c.expires, Infinity);
256
- assert.equal(c.expires.getTime(), 1397700749000);
257
- },
258
- "httponly": function(c) { assert.ok(c.httpOnly) }
259
- },
260
- "spaces in value": {
261
- topic: function() {
262
- return Cookie.parse('a=one two three',false) || null;
263
- },
264
- "parsed": function(c) { assert.ok(c) },
265
- "key": function(c) { assert.equal(c.key, 'a') },
266
- "value": function(c) { assert.equal(c.value, 'one two three') },
267
- "no path": function(c) { assert.equal(c.path, null) },
268
- "no domain": function(c) { assert.equal(c.domain, null) },
269
- "no extensions": function(c) { assert.ok(!c.extensions) }
270
- },
271
- "quoted spaces in value": {
272
- topic: function() {
273
- return Cookie.parse('a="one two three"',false) || null;
274
- },
275
- "parsed": function(c) { assert.ok(c) },
276
- "key": function(c) { assert.equal(c.key, 'a') },
277
- "value": function(c) { assert.equal(c.value, '"one two three"') },
278
- "no path": function(c) { assert.equal(c.path, null) },
279
- "no domain": function(c) { assert.equal(c.domain, null) },
280
- "no extensions": function(c) { assert.ok(!c.extensions) }
281
- },
282
- "non-ASCII in value": {
283
- topic: function() {
284
- return Cookie.parse('farbe=weiß',false) || null;
285
- },
286
- "parsed": function(c) { assert.ok(c) },
287
- "key": function(c) { assert.equal(c.key, 'farbe') },
288
- "value": function(c) { assert.equal(c.value, 'weiß') },
289
- "no path": function(c) { assert.equal(c.path, null) },
290
- "no domain": function(c) { assert.equal(c.domain, null) },
291
- "no extensions": function(c) { assert.ok(!c.extensions) }
292
- }
293
- })
294
- .export(module);
@@ -1,143 +0,0 @@
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
-
32
- 'use strict';
33
- var vows = require('vows');
34
- var assert = require('assert');
35
- var async = require('async');
36
- var tough = require('../lib/cookie');
37
- var Cookie = tough.Cookie;
38
- var CookieJar = tough.CookieJar;
39
-
40
- var atNow = Date.now();
41
-
42
- function at(offset) {
43
- return {now: new Date(atNow + offset)};
44
- }
45
-
46
- vows
47
- .describe('Regression tests')
48
- .addBatch({
49
- "Issue 1": {
50
- topic: function () {
51
- var cj = new CookieJar();
52
- cj.setCookie('hello=world; path=/some/path/', 'http://domain/some/path/file', function (err, cookie) {
53
- this.callback(err, {cj: cj, cookie: cookie});
54
- }.bind(this));
55
- },
56
- "stored a cookie": function (t) {
57
- assert.ok(t.cookie);
58
- },
59
- "getting it back": {
60
- topic: function (t) {
61
- t.cj.getCookies('http://domain/some/path/file', function (err, cookies) {
62
- this.callback(err, {cj: t.cj, cookies: cookies || []});
63
- }.bind(this));
64
- },
65
- "got one cookie": function (t) {
66
- assert.lengthOf(t.cookies, 1);
67
- },
68
- "it's the right one": function (t) {
69
- var c = t.cookies[0];
70
- assert.equal(c.key, 'hello');
71
- assert.equal(c.value, 'world');
72
- }
73
- }
74
- }
75
- })
76
- .addBatch({
77
- "trailing semi-colon set into cj": {
78
- topic: function () {
79
- var cb = this.callback;
80
- var cj = new CookieJar();
81
- var ex = 'http://www.example.com';
82
- var tasks = [];
83
- tasks.push(function (next) {
84
- cj.setCookie('broken_path=testme; path=/;', ex, at(-1), next);
85
- });
86
- tasks.push(function (next) {
87
- cj.setCookie('b=2; Path=/;;;;', ex, at(-1), next);
88
- });
89
- async.parallel(tasks, function (err, cookies) {
90
- cb(null, {
91
- cj: cj,
92
- cookies: cookies
93
- });
94
- });
95
- },
96
- "check number of cookies": function (t) {
97
- assert.lengthOf(t.cookies, 2, "didn't set");
98
- },
99
- "check *broken_path* was set properly": function (t) {
100
- assert.equal(t.cookies[0].key, "broken_path");
101
- assert.equal(t.cookies[0].value, "testme");
102
- assert.equal(t.cookies[0].path, "/");
103
- },
104
- "check *b* was set properly": function (t) {
105
- assert.equal(t.cookies[1].key, "b");
106
- assert.equal(t.cookies[1].value, "2");
107
- assert.equal(t.cookies[1].path, "/");
108
- },
109
- "retrieve the cookie": {
110
- topic: function (t) {
111
- var cb = this.callback;
112
- t.cj.getCookies('http://www.example.com', {}, function (err, cookies) {
113
- t.cookies = cookies;
114
- cb(err, t);
115
- });
116
- },
117
- "get the cookie": function (t) {
118
- assert.lengthOf(t.cookies, 2);
119
- assert.equal(t.cookies[0].key, 'broken_path');
120
- assert.equal(t.cookies[0].value, 'testme');
121
- assert.equal(t.cookies[1].key, "b");
122
- assert.equal(t.cookies[1].value, "2");
123
- assert.equal(t.cookies[1].path, "/");
124
- }
125
- }
126
- }
127
- })
128
- .addBatch({
129
- "tough-cookie throws exception on malformed URI (GH-32)": {
130
- topic: function () {
131
- var url = "http://www.example.com/?test=100%";
132
- var cj = new CookieJar();
133
-
134
- cj.setCookieSync("Test=Test", url);
135
-
136
- return cj.getCookieStringSync(url);
137
- },
138
- "cookies are set": function (cookieStr) {
139
- assert.strictEqual(cookieStr, "Test=Test");
140
- }
141
- }
142
- })
143
- .export(module);