|
67 | 67 | assert.ok(!c.isPersistent());
|
68 | 68 | }
|
69 | 69 | },
|
| 70 | + "Setting a basic cookie (URL)": { |
| 71 | + topic: function() { |
| 72 | + const cj = new CookieJar(); |
| 73 | + const c = Cookie.parse("a=b; Domain=example.com; Path=/"); |
| 74 | + assert.strictEqual(c.hostOnly, null); |
| 75 | + assert.instanceOf(c.creation, Date); |
| 76 | + assert.strictEqual(c.lastAccessed, null); |
| 77 | + c.creation = new Date(Date.now() - 10000); |
| 78 | + cj.setCookie( |
| 79 | + c, |
| 80 | + new URL("http://example.com/index.html"), |
| 81 | + this.callback |
| 82 | + ); |
| 83 | + }, |
| 84 | + works: function(c) { |
| 85 | + assert.instanceOf(c, Cookie); |
| 86 | + }, // C is for Cookie, good enough for me |
| 87 | + "gets timestamped": function(c) { |
| 88 | + assert.ok(c.creation); |
| 89 | + assert.ok(Date.now() - c.creation.getTime() < 5000); // recently stamped |
| 90 | + assert.ok(c.lastAccessed); |
| 91 | + assert.equal(c.creation, c.lastAccessed); |
| 92 | + assert.equal(c.TTL(), Infinity); |
| 93 | + assert.ok(!c.isPersistent()); |
| 94 | + } |
| 95 | + }, |
70 | 96 | "Setting a no-path cookie": {
|
71 | 97 | topic: function() {
|
72 | 98 | const cj = new CookieJar();
|
@@ -366,6 +392,17 @@ vows
|
366 | 392 | assert.equal(cookie.domain, "nodejs.org");
|
367 | 393 | }
|
368 | 394 | },
|
| 395 | + "then retrieving for http://nodejs.org (URL)": { |
| 396 | + topic: function(cj, oldResults) { |
| 397 | + assert.ok(oldResults); |
| 398 | + cj.getCookies(new URL("http://nodejs.org"), this.callback); |
| 399 | + }, |
| 400 | + "get a nodejs cookie": function(cookies) { |
| 401 | + assert.lengthOf(cookies, 1); |
| 402 | + const cookie = cookies[0]; |
| 403 | + assert.equal(cookie.domain, "nodejs.org"); |
| 404 | + } |
| 405 | + }, |
369 | 406 | "then retrieving for https://example.com": {
|
370 | 407 | topic: function(cj, oldResults) {
|
371 | 408 | assert.ok(oldResults);
|
|
0 commit comments