react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / request / node_modules / tough-cookie / test / regression_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 async = require('async');35var tough = require('../lib/cookie');36var Cookie = tough.Cookie;37var CookieJar = tough.CookieJar;3839var atNow = Date.now();4041function at(offset) {42return {now: new Date(atNow + offset)};43}4445vows46.describe('Regression tests')47.addBatch({48"Issue 1": {49topic: function () {50var cj = new CookieJar();51cj.setCookie('hello=world; path=/some/path/', 'http://domain/some/path/file', function (err, cookie) {52this.callback(err, {cj: cj, cookie: cookie});53}.bind(this));54},55"stored a cookie": function (t) {56assert.ok(t.cookie);57},58"getting it back": {59topic: function (t) {60t.cj.getCookies('http://domain/some/path/file', function (err, cookies) {61this.callback(err, {cj: t.cj, cookies: cookies || []});62}.bind(this));63},64"got one cookie": function (t) {65assert.lengthOf(t.cookies, 1);66},67"it's the right one": function (t) {68var c = t.cookies[0];69assert.equal(c.key, 'hello');70assert.equal(c.value, 'world');71}72}73}74})75.addBatch({76"trailing semi-colon set into cj": {77topic: function () {78var cb = this.callback;79var cj = new CookieJar();80var ex = 'http://www.example.com';81var tasks = [];82tasks.push(function (next) {83cj.setCookie('broken_path=testme; path=/;', ex, at(-1), next);84});85tasks.push(function (next) {86cj.setCookie('b=2; Path=/;;;;', ex, at(-1), next);87});88async.parallel(tasks, function (err, cookies) {89cb(null, {90cj: cj,91cookies: cookies92});93});94},95"check number of cookies": function (t) {96assert.lengthOf(t.cookies, 2, "didn't set");97},98"check *broken_path* was set properly": function (t) {99assert.equal(t.cookies[0].key, "broken_path");100assert.equal(t.cookies[0].value, "testme");101assert.equal(t.cookies[0].path, "/");102},103"check *b* was set properly": function (t) {104assert.equal(t.cookies[1].key, "b");105assert.equal(t.cookies[1].value, "2");106assert.equal(t.cookies[1].path, "/");107},108"retrieve the cookie": {109topic: function (t) {110var cb = this.callback;111t.cj.getCookies('http://www.example.com', {}, function (err, cookies) {112t.cookies = cookies;113cb(err, t);114});115},116"get the cookie": function (t) {117assert.lengthOf(t.cookies, 2);118assert.equal(t.cookies[0].key, 'broken_path');119assert.equal(t.cookies[0].value, 'testme');120assert.equal(t.cookies[1].key, "b");121assert.equal(t.cookies[1].value, "2");122assert.equal(t.cookies[1].path, "/");123}124}125}126})127.addBatch({128"tough-cookie throws exception on malformed URI (GH-32)": {129topic: function () {130var url = "http://www.example.com/?test=100%";131var cj = new CookieJar();132133cj.setCookieSync("Test=Test", url);134135return cj.getCookieStringSync(url);136},137"cookies are set": function (cookieStr) {138assert.strictEqual(cookieStr, "Test=Test");139}140}141})142.export(module);143144145