react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / request / node_modules / tough-cookie / test / cookie_to_string_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('Cookie.toString()')39.addBatch({40"a simple cookie": {41topic: function () {42var c = new Cookie();43c.key = 'a';44c.value = 'b';45return c;46},47"validates": function (c) {48assert.ok(c.validate());49},50"to string": function (c) {51assert.equal(c.toString(), 'a=b');52}53},54"a cookie with spaces in the value": {55topic: function () {56var c = new Cookie();57c.key = 'a';58c.value = 'beta gamma';59return c;60},61"doesn't validate": function (c) {62assert.ok(!c.validate());63},64"'garbage in, garbage out'": function (c) {65assert.equal(c.toString(), 'a=beta gamma');66}67},68"with an empty value and HttpOnly": {69topic: function () {70var c = new Cookie();71c.key = 'a';72c.httpOnly = true;73return c;74},75"to string": function (c) {76assert.equal(c.toString(), 'a=; HttpOnly');77}78},79"with an expiry": {80topic: function () {81var c = new Cookie();82c.key = 'a';83c.value = 'b';84c.setExpires("Oct 18 2011 07:05:03 GMT");85return c;86},87"validates": function (c) {88assert.ok(c.validate());89},90"to string": function (c) {91assert.equal(c.toString(), 'a=b; Expires=Tue, 18 Oct 2011 07:05:03 GMT');92},93"to short string": function (c) {94assert.equal(c.cookieString(), 'a=b');95}96},97"with a max-age": {98topic: function () {99var c = new Cookie();100c.key = 'a';101c.value = 'b';102c.setExpires("Oct 18 2011 07:05:03 GMT");103c.maxAge = 12345;104return c;105},106"validates": function (c) {107assert.ok(c.validate()); // mabe this one *shouldn't*?108},109"to string": function (c) {110assert.equal(c.toString(), 'a=b; Expires=Tue, 18 Oct 2011 07:05:03 GMT; Max-Age=12345');111}112},113"with a bunch of things": function () {114var c = new Cookie();115c.key = 'a';116c.value = 'b';117c.setExpires("Oct 18 2011 07:05:03 GMT");118c.maxAge = 12345;119c.domain = 'example.com';120c.path = '/foo';121c.secure = true;122c.httpOnly = true;123c.extensions = ['MyExtension'];124assert.equal(c.toString(), 'a=b; Expires=Tue, 18 Oct 2011 07:05:03 GMT; Max-Age=12345; Domain=example.com; Path=/foo; Secure; HttpOnly; MyExtension');125},126"a host-only cookie": {127topic: function () {128var c = new Cookie();129c.key = 'a';130c.value = 'b';131c.hostOnly = true;132c.domain = 'shouldnt-stringify.example.com';133c.path = '/should-stringify';134return c;135},136"validates": function (c) {137assert.ok(c.validate());138},139"to string": function (c) {140assert.equal(c.toString(), 'a=b; Path=/should-stringify');141}142},143"minutes are '10'": {144topic: function () {145var c = new Cookie();146c.key = 'a';147c.value = 'b';148c.expires = new Date(1284113410000);149return c;150},151"validates": function (c) {152assert.ok(c.validate());153},154"to string": function (c) {155var str = c.toString();156assert.notEqual(str, 'a=b; Expires=Fri, 010 Sep 2010 010:010:010 GMT');157assert.equal(str, 'a=b; Expires=Fri, 10 Sep 2010 10:10:10 GMT');158}159}160})161.export(module);162163164