react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / request / node_modules / tough-cookie / test / ietf_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 fs = require('fs');35var path = require('path');36var url = require('url');37var tough = require('../lib/cookie');38var Cookie = tough.Cookie;39var CookieJar = tough.CookieJar;4041function readJson(filePath) {42filePath = path.join(__dirname, filePath);43return JSON.parse(fs.readFileSync(filePath).toString());44}4546function setGetCookieVows() {47var theVows = {};48var data = readJson('./ietf_data/parser.json');4950data.forEach(function (testCase) {51theVows[testCase.test] = function () {52var jar = new CookieJar();53var expected = testCase['sent']54var sentFrom = 'http://home.example.org/cookie-parser?' + testCase.test;55var sentTo = testCase['sent-to'] ?56url.resolve('http://home.example.org', testCase['sent-to']) :57'http://home.example.org/cookie-parser-result?' + testCase.test;5859testCase['received'].forEach(function (cookieStr) {60jar.setCookieSync(cookieStr, sentFrom, {ignoreError: true});61});6263var actual = jar.getCookiesSync(sentTo);64actual = actual.sort(tough.cookieCompare);6566assert.strictEqual(actual.length, expected.length);6768actual.forEach(function (actualCookie, idx) {69var expectedCookie = expected[idx];70assert.strictEqual(actualCookie.key, expectedCookie.name);71assert.strictEqual(actualCookie.value, expectedCookie.value);72});73};74});7576return {'Set/get cookie tests': theVows};77}7879function dateVows() {80var theVows = {};8182[83'./ietf_data/dates/bsd-examples.json',84'./ietf_data/dates/examples.json'85].forEach(function (filePath) {86var data = readJson(filePath);87var fileName = path.basename(filePath);8889data.forEach(function (testCase) {90theVows[fileName + ' : ' + testCase.test] = function () {91var actual = tough.parseDate(testCase.test);92actual = actual ? actual.toUTCString() : null;93assert.strictEqual(actual, testCase.expected);94};95});96});9798return {'Date': theVows};99}100101vows102.describe('IETF http state tests')103.addBatch(setGetCookieVows())104.addBatch(dateVows())105.export(module);106107108