react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / request / node_modules / tough-cookie / test / lifetime_test.js
81146 views/*!1* Copyright (c) 2015, Salesforce.com, Inc.2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions are met:6*7* 1. Redistributions of source code must retain the above copyright notice,8* this list of conditions and the following disclaimer.9*10* 2. Redistributions in binary form must reproduce the above copyright notice,11* this list of conditions and the following disclaimer in the documentation12* and/or other materials provided with the distribution.13*14* 3. Neither the name of Salesforce.com nor the names of its contributors may15* be used to endorse or promote products derived from this software without16* specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"19* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE22* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR23* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF24* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS25* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN26* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)27* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE28* POSSIBILITY OF SUCH DAMAGE.29*/3031'use strict';32var vows = require('vows');33var assert = require('assert');34var tough = require('../lib/cookie');35var Cookie = tough.Cookie;3637vows38.describe('Lifetime')39.addBatch({40"TTL with max-age": function () {41var c = new Cookie();42c.maxAge = 123;43assert.equal(c.TTL(), 123000);44assert.equal(c.expiryTime(new Date(9000000)), 9123000);45},46"TTL with zero max-age": function () {47var c = new Cookie();48c.key = 'a';49c.value = 'b';50c.maxAge = 0; // should be treated as "earliest representable"51assert.equal(c.TTL(), 0);52assert.equal(c.expiryTime(new Date(9000000)), -Infinity);53assert.ok(!c.validate()); // not valid, really: non-zero-digit *DIGIT54},55"TTL with negative max-age": function () {56var c = new Cookie();57c.key = 'a';58c.value = 'b';59c.maxAge = -1; // should be treated as "earliest representable"60assert.equal(c.TTL(), 0);61assert.equal(c.expiryTime(new Date(9000000)), -Infinity);62assert.ok(!c.validate()); // not valid, really: non-zero-digit *DIGIT63},64"TTL with max-age and expires": function () {65var c = new Cookie();66c.maxAge = 123;67c.expires = new Date(Date.now() + 9000);68assert.equal(c.TTL(), 123000);69assert.ok(c.isPersistent());70},71"TTL with expires": function () {72var c = new Cookie();73var now = Date.now();74c.expires = new Date(now + 9000);75assert.equal(c.TTL(now), 9000);76assert.equal(c.expiryTime(), c.expires.getTime());77},78"TTL with old expires": function () {79var c = new Cookie();80c.setExpires('17 Oct 2010 00:00:00 GMT');81assert.ok(c.TTL() < 0);82assert.ok(c.isPersistent());83},84"default TTL": {85topic: function () {86return new Cookie();87},88"is Infinite-future": function (c) {89assert.equal(c.TTL(), Infinity)90},91"is a 'session' cookie": function (c) {92assert.ok(!c.isPersistent())93}94}95})96.export(module);979899