Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

statehood

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

statehood - npm Package Compare versions

Comparing version 2.1.1 to 3.0.0

192

lib/index.js

@@ -0,10 +1,12 @@

'use strict';
// Load modules
var Boom = require('boom');
var Cryptiles = require('cryptiles');
var Hoek = require('hoek');
var Iron = require('iron');
var Items = require('items');
var Joi = require('joi');
var Querystring = require('querystring');
const Boom = require('boom');
const Cryptiles = require('cryptiles');
const Hoek = require('hoek');
const Iron = require('iron');
const Items = require('items');
const Joi = require('joi');
const Querystring = require('querystring');

@@ -14,3 +16,3 @@

var internals = {};
const internals = {};

@@ -69,3 +71,3 @@

var settings = Hoek.applyToDefaults(this.settings, options || {}, true);
const settings = Hoek.applyToDefaults(this.settings, options || {}, true);
Joi.assert(settings, internals.schema, 'Invalid state definition: ' + name);

@@ -106,11 +108,9 @@

var self = this;
const state = {};
const names = [];
const verify = cookies.replace(internals.parseRx, ($0, $1, $2, $3) => {
var state = {};
var names = [];
var verify = cookies.replace(internals.parseRx, function ($0, $1, $2, $3) {
const name = $1;
const value = $2 || $3 || '';
var name = $1;
var value = $2 || $3 || '';
if (state[name]) {

@@ -139,7 +139,7 @@ if (!Array.isArray(state[name])) {

var failed = []; // All errors
var errored = []; // Unignored errors
var record = function (reason, name, value, definition) {
const failed = []; // All errors
const errored = []; // Unignored errors
const record = (reason, name, value, definition) => {
var details = {
const details = {
name: name,

@@ -159,7 +159,7 @@ value: value,

var parsed = {};
Items.serial(names, function (name, nextName) {
const parsed = {};
Items.serial(names, (name, nextName) => {
var value = state[name];
var definition = self.cookies[name] || self.settings;
const value = state[name];
const definition = this.cookies[name] || this.settings;

@@ -174,5 +174,5 @@ // Validate cookie

var values = [].concat(state[name]);
for (var v = 0, vl = values.length; v < vl; ++v) {
if (!values[v].match(internals.validateRx.valueRx.strict)) {
const values = [].concat(state[name]);
for (let i = 0; i < values.length; ++i) {
if (!values[i].match(internals.validateRx.valueRx.strict)) {
record('Invalid cookie value', name, value, definition);

@@ -194,3 +194,3 @@ return nextName();

if (!Array.isArray(value)) {
internals.unsign(name, value, definition, function (err, unsigned) {
internals.unsign(name, value, definition, (err, unsigned) => {

@@ -202,3 +202,3 @@ if (err) {

internals.decode(unsigned, definition, function (err, result) {
internals.decode(unsigned, definition, (err, result) => {

@@ -220,6 +220,6 @@ if (err) {

var arrayResult = [];
Items.serial(value, function (arrayValue, nextArray) {
const arrayResult = [];
Items.serial(value, (arrayValue, nextArray) => {
internals.unsign(name, arrayValue, definition, function (err, unsigned) {
internals.unsign(name, arrayValue, definition, (err, unsigned) => {

@@ -231,3 +231,3 @@ if (err) {

internals.decode(unsigned, definition, function (err, result) {
internals.decode(unsigned, definition, (err, result) => {

@@ -244,3 +244,3 @@ if (err) {

},
function (err) {
(err) => {

@@ -251,3 +251,3 @@ parsed[name] = arrayResult;

},
function (err) {
(err) => {

@@ -268,3 +268,3 @@ return next(errored.length ? Boom.badRequest('Invalid cookie value', errored) : null, parsed, failed);

var pos = value.lastIndexOf('.');
const pos = value.lastIndexOf('.');
if (pos === -1) {

@@ -274,4 +274,4 @@ return next(Boom.badRequest('Missing signature separator'));

var unsigned = value.slice(0, pos);
var sig = value.slice(pos + 1);
const unsigned = value.slice(0, pos);
const sig = value.slice(pos + 1);

@@ -282,3 +282,3 @@ if (!sig) {

var sigParts = sig.split('*');
const sigParts = sig.split('*');
if (sigParts.length !== 2) {

@@ -288,8 +288,8 @@ return next(Boom.badRequest('Invalid signature format'));

var hmacSalt = sigParts[0];
var hmac = sigParts[1];
const hmacSalt = sigParts[0];
const hmac = sigParts[1];
var macOptions = Hoek.clone(definition.sign.integrity || Iron.defaults.integrity);
const macOptions = Hoek.clone(definition.sign.integrity || Iron.defaults.integrity);
macOptions.salt = hmacSalt;
Iron.hmacWithPassword(definition.sign.password, macOptions, [internals.macPrefix, name, unsigned].join('\n'), function (err, mac) {
Iron.hmacWithPassword(definition.sign.password, macOptions, [internals.macPrefix, name, unsigned].join('\n'), (err, mac) => {

@@ -314,3 +314,3 @@ if (err) {

if (definition.encoding === 'iron') {
Iron.unseal(value, definition.password, definition.iron || Iron.defaults, function (err, unsealed) {
Iron.unseal(value, definition.password, definition.iron || Iron.defaults, (err, unsealed) => {

@@ -327,17 +327,15 @@ if (err) {

var result = value;
let result = value;
try {
switch (definition.encoding) {
case 'base64json':
var decoded = (new Buffer(value, 'base64')).toString('binary');
result = JSON.parse(decoded);
break;
case 'base64':
result = (new Buffer(value, 'base64')).toString('binary');
break;
case 'form':
result = Querystring.parse(value);
break;
if (definition.encoding === 'base64json') {
const decoded = (new Buffer(value, 'base64')).toString('binary');
result = JSON.parse(decoded);
}
else if (definition.encoding === 'base64') {
result = (new Buffer(value, 'base64')).toString('binary');
}
else { // encoding: 'form'
result = Querystring.parse(value);
}
}

@@ -354,4 +352,2 @@ catch (err) {

var self = this;
if (!cookies ||

@@ -367,13 +363,13 @@ (Array.isArray(cookies) && !cookies.length)) {

var header = [];
Items.serial(cookies, function (cookie, next) {
const header = [];
Items.serial(cookies, (cookie, next) => {
// Apply definition to local configuration
var base = self.cookies[cookie.name] || self.settings;
var definition = cookie.options ? Hoek.applyToDefaults(base, cookie.options, true) : base;
const base = this.cookies[cookie.name] || this.settings;
const definition = cookie.options ? Hoek.applyToDefaults(base, cookie.options, true) : base;
// Validate name
var nameRx = (definition.strictHeader ? internals.validateRx.nameRx.strict : internals.validateRx.nameRx.loose);
const nameRx = (definition.strictHeader ? internals.validateRx.nameRx.strict : internals.validateRx.nameRx.loose);
if (!nameRx.test(cookie.name)) {

@@ -385,3 +381,3 @@ return callback(Boom.badImplementation('Invalid cookie name: ' + cookie.name));

exports.prepareValue(cookie.name, cookie.value, definition, function (err, value) {
exports.prepareValue(cookie.name, cookie.value, definition, (err, value) => {

@@ -394,3 +390,3 @@ if (err) {

var valueRx = (definition.strictHeader ? internals.validateRx.valueRx.strict : internals.validateRx.valueRx.loose);
const valueRx = (definition.strictHeader ? internals.validateRx.valueRx.strict : internals.validateRx.valueRx.loose);
if (value &&

@@ -404,3 +400,3 @@ (typeof value !== 'string' || !value.match(valueRx))) {

var segment = cookie.name + '=' + (value || '');
let segment = cookie.name + '=' + (value || '');

@@ -410,16 +406,16 @@ if (definition.ttl !== null &&

var expires = new Date(definition.ttl ? Date.now() + definition.ttl : 0);
segment += '; Max-Age=' + Math.floor(definition.ttl / 1000) + '; Expires=' + expires.toUTCString();
const expires = new Date(definition.ttl ? Date.now() + definition.ttl : 0);
segment = segment + '; Max-Age=' + Math.floor(definition.ttl / 1000) + '; Expires=' + expires.toUTCString();
}
if (definition.isSecure) {
segment += '; Secure';
segment = segment + '; Secure';
}
if (definition.isHttpOnly) {
segment += '; HttpOnly';
segment = segment + '; HttpOnly';
}
if (definition.domain) {
var domain = definition.domain.toLowerCase();
const domain = definition.domain.toLowerCase();
if (!domain.match(internals.validateRx.domainLabelLenRx)) {

@@ -433,3 +429,3 @@ return callback(Boom.badImplementation('Cookie domain too long: ' + definition.domain));

segment += '; Domain=' + domain;
segment = segment + '; Domain=' + domain;
}

@@ -442,3 +438,3 @@

segment += '; Path=' + definition.path;
segment = segment + '; Path=' + definition.path;
}

@@ -450,3 +446,3 @@

},
function (err) {
(err) => {

@@ -464,3 +460,3 @@ return callback(null, header);

internals.encode(value, options, function (err, encoded) {
internals.encode(value, options, (err, encoded) => {

@@ -473,3 +469,3 @@ if (err) {

internals.sign(name, encoded, options.sign, function (err, signed) {
internals.sign(name, encoded, options.sign, (err, signed) => {

@@ -501,3 +497,3 @@ if (err) {

if (options.encoding === 'iron') {
Iron.seal(value, options.password, options.iron || Iron.defaults, function (err, sealed) {
Iron.seal(value, options.password, options.iron || Iron.defaults, (err, sealed) => {

@@ -514,17 +510,15 @@ if (err) {

var result = value;
let result = value;
try {
switch (options.encoding) {
case 'base64':
result = (new Buffer(value, 'binary')).toString('base64');
break;
case 'base64json':
var stringified = JSON.stringify(value);
result = (new Buffer(stringified, 'binary')).toString('base64');
break;
case 'form':
result = Querystring.stringify(value);
break;
if (options.encoding === 'base64') {
result = (new Buffer(value, 'binary')).toString('base64');
}
else if (options.encoding === 'base64json') {
const stringified = JSON.stringify(value);
result = (new Buffer(stringified, 'binary')).toString('base64');
}
else { // encoding: 'form'
result = Querystring.stringify(value);
}
}

@@ -547,3 +541,3 @@ catch (err) {

Iron.hmacWithPassword(options.password, options.integrity || Iron.defaults.integrity, [internals.macPrefix, name, value].join('\n'), function (err, mac) {
Iron.hmacWithPassword(options.password, options.integrity || Iron.defaults.integrity, [internals.macPrefix, name, value].join('\n'), (err, mac) => {

@@ -554,3 +548,3 @@ if (err) {

var signed = value + '.' + mac.salt + '*' + mac.digest;
const signed = value + '.' + mac.salt + '*' + mac.digest;
return callback(null, signed);

@@ -567,7 +561,7 @@ });

var exclude = [];
for (var i = 0, il = this.names.length; i < il; ++i) {
var name = this.names[i];
var definition = this.cookies[name];
var passCookie = definition.passThrough !== undefined ? definition.passThrough : fallback;
const exclude = [];
for (let i = 0; i < this.names.length; ++i) {
const name = this.names[i];
const definition = this.cookies[name];
const passCookie = definition.passThrough !== undefined ? definition.passThrough : fallback;
if (!passCookie) {

@@ -584,7 +578,7 @@ exclude.push(name);

var result = '';
var verify = cookies.replace(internals.pairsRx, function ($0, $1, $2) {
let result = '';
const verify = cookies.replace(internals.pairsRx, ($0, $1, $2) => {
if (excludes.indexOf($1) === -1) {
result += (result ? ';' : '') + $1 + '=' + $2;
result = result + (result ? ';' : '') + $1 + '=' + $2;
}

@@ -591,0 +585,0 @@

{
"name": "statehood",
"description": "HTTP State Management Utilities",
"version": "2.1.1",
"version": "3.0.0",
"repository": "git://github.com/hapijs/statehood",

@@ -14,15 +14,15 @@ "main": "lib/index.js",

"engines": {
"node": ">=0.10.32"
"node": ">=4.0.0"
},
"dependencies": {
"boom": "2.x.x",
"cryptiles": "2.x.x",
"hoek": "2.x.x",
"iron": "2.x.x",
"items": "1.x.x",
"joi": "6.x.x"
"boom": "3.x.x",
"cryptiles": "3.x.x",
"hoek": "3.x.x",
"iron": "3.x.x",
"items": "2.x.x",
"joi": "7.x.x"
},
"devDependencies": {
"code": "1.x.x",
"lab": "5.x.x"
"code": "2.x.x",
"lab": "7.x.x"
},

@@ -29,0 +29,0 @@ "scripts": {

@@ -0,10 +1,10 @@

'use strict';
// Load modules
var Code = require('code');
var Cryptiles = require('cryptiles');
var Hoek = require('hoek');
var Iron = require('iron');
var Lab = require('lab');
var Statehood = require('../');
const Code = require('code');
const Cryptiles = require('cryptiles');
const Iron = require('iron');
const Lab = require('lab');
const Statehood = require('../');

@@ -14,3 +14,3 @@

var internals = {};
const internals = {};

@@ -20,16 +20,16 @@

var lab = exports.lab = Lab.script();
var describe = lab.describe;
var it = lab.it;
var expect = Code.expect;
const lab = exports.lab = Lab.script();
const describe = lab.describe;
const it = lab.it;
const expect = Code.expect;
describe('Definitions', function () {
describe('Definitions', () => {
describe('add()', function () {
describe('add()', () => {
it('throws on missing name', function (done) {
it('throws on missing name', (done) => {
var definitions = new Statehood.Definitions();
expect(function () {
const definitions = new Statehood.Definitions();
expect(() => {

@@ -41,5 +41,5 @@ definitions.add();

it('uses defaults', function (done) {
it('uses defaults', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('test');

@@ -59,5 +59,5 @@ expect(definitions.cookies.test).to.deep.equal({

it('records name', function (done) {
it('records name', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('test');

@@ -68,5 +68,5 @@ expect(definitions.names).to.deep.equal(['test']);

it('adds definition with null value', function (done) {
it('adds definition with null value', (done) => {
var definitions = new Statehood.Definitions({ path: '/' });
const definitions = new Statehood.Definitions({ path: '/' });

@@ -83,8 +83,8 @@ definitions.add('base');

describe('parse()', function () {
describe('parse()', () => {
it('parses cookie', function (done) {
it('parses cookie', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a=b', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a=b', (err, states, failed) => {

@@ -98,6 +98,6 @@ expect(err).to.not.exist();

it('parses cookie (loose)', function (done) {
it('parses cookie (loose)', (done) => {
var definitions = new Statehood.Definitions({ strictHeader: false });
definitions.parse('a="1; b="2"; c=3; d[1]=4', function (err, states, failed) {
const definitions = new Statehood.Definitions({ strictHeader: false });
definitions.parse('a="1; b="2"; c=3; d[1]=4', (err, states, failed) => {

@@ -111,6 +111,6 @@ expect(err).to.not.exist();

it('parses cookie (empty)', function (done) {
it('parses cookie (empty)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a=', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a=', (err, states, failed) => {

@@ -124,6 +124,6 @@ expect(err).to.not.exist();

it('parses cookie (quoted empty)', function (done) {
it('parses cookie (quoted empty)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a=""', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a=""', (err, states, failed) => {

@@ -137,6 +137,6 @@ expect(err).to.not.exist();

it('parses cookie (semicolon single)', function (done) {
it('parses cookie (semicolon single)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a=;', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a=;', (err, states, failed) => {

@@ -150,6 +150,6 @@ expect(err).to.not.exist();

it('parses cookie (number)', function (done) {
it('parses cookie (number)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a=23', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a=23', (err, states, failed) => {

@@ -163,6 +163,6 @@ expect(err).to.not.exist();

it('parses cookie (array)', function (done) {
it('parses cookie (array)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a=1; a=2', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a=1; a=2', (err, states, failed) => {

@@ -176,6 +176,6 @@ expect(err).to.not.exist();

it('parses cookie (mixed style array)', function (done) {
it('parses cookie (mixed style array)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a=1; b="2"; c=3', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a=1; b="2"; c=3', (err, states, failed) => {

@@ -189,6 +189,6 @@ expect(err).to.not.exist();

it('parses cookie (mixed style array quoted first)', function (done) {
it('parses cookie (mixed style array quoted first)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a="1"; b="2"; c=3', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a="1"; b="2"; c=3', (err, states, failed) => {

@@ -202,6 +202,6 @@ expect(err).to.not.exist();

it('parses cookie (white space)', function (done) {
it('parses cookie (white space)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('A = b; b = c', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('A = b; b = c', (err, states, failed) => {

@@ -215,6 +215,6 @@ expect(err).to.not.exist();

it('parses cookie (raw form)', function (done) {
it('parses cookie (raw form)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a="b=123456789&c=something"', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a="b=123456789&c=something"', (err, states, failed) => {

@@ -228,6 +228,6 @@ expect(err).to.not.exist();

it('parses cookie (raw percent)', function (done) {
it('parses cookie (raw percent)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a=%1;b=x', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a=%1;b=x', (err, states, failed) => {

@@ -241,6 +241,6 @@ expect(err).to.not.exist();

it('parses cookie (raw encoded)', function (done) {
it('parses cookie (raw encoded)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('z=%20%22%2c%3b%2f', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('z=%20%22%2c%3b%2f', (err, states, failed) => {

@@ -254,7 +254,7 @@ expect(err).to.not.exist();

it('parses cookie (form single)', function (done) {
it('parses cookie (form single)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('a', { encoding: 'form' });
definitions.parse('a="b=%p123456789"', function (err, states, failed) {
definitions.parse('a="b=%p123456789"', (err, states, failed) => {

@@ -268,7 +268,7 @@ expect(err).to.not.exist();

it('parses cookie (form multiple)', function (done) {
it('parses cookie (form multiple)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('a', { encoding: 'form' });
definitions.parse('a="b=123456789&c=something%20else"', function (err, states, failed) {
definitions.parse('a="b=123456789&c=something%20else"', (err, states, failed) => {

@@ -282,7 +282,7 @@ expect(err).to.not.exist();

it('parses cookie (base64 array 2)', function (done) {
it('parses cookie (base64 array 2)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('a', { encoding: 'base64' });
definitions.parse('a=dGVzdA; a=dGVzdA', function (err, states, failed) {
definitions.parse('a=dGVzdA; a=dGVzdA', (err, states, failed) => {

@@ -296,7 +296,7 @@ expect(err).to.not.exist();

it('parses cookie (base64 array 3)', function (done) {
it('parses cookie (base64 array 3)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('a', { encoding: 'base64' });
definitions.parse('a=dGVzdA; a=dGVzdA; a=dGVzdA', function (err, states, failed) {
definitions.parse('a=dGVzdA; a=dGVzdA; a=dGVzdA', (err, states, failed) => {

@@ -310,7 +310,7 @@ expect(err).to.not.exist();

it('parses cookie (base64 padding)', function (done) {
it('parses cookie (base64 padding)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('key', { encoding: 'base64' });
definitions.parse('key=dGVzdA==', function (err, states, failed) {
definitions.parse('key=dGVzdA==', (err, states, failed) => {

@@ -324,7 +324,7 @@ expect(err).to.not.exist();

it('parses cookie (base64)', function (done) {
it('parses cookie (base64)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('key', { encoding: 'base64' });
definitions.parse('key=dGVzdA', function (err, states, failed) {
definitions.parse('key=dGVzdA', (err, states, failed) => {

@@ -338,7 +338,7 @@ expect(err).to.not.exist();

it('parses cookie (none encoding)', function (done) {
it('parses cookie (none encoding)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('key', { encoding: 'none' });
definitions.parse('key=dGVzdA', function (err, states, failed) {
definitions.parse('key=dGVzdA', (err, states, failed) => {

@@ -352,7 +352,7 @@ expect(err).to.not.exist();

it('parses cookie (base64json)', function (done) {
it('parses cookie (base64json)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('key', { encoding: 'base64json' });
definitions.parse('key=eyJ0ZXN0aW5nIjoianNvbiJ9', function (err, states, failed) {
definitions.parse('key=eyJ0ZXN0aW5nIjoianNvbiJ9', (err, states, failed) => {

@@ -366,7 +366,7 @@ expect(err).to.not.exist();

it('parses cookie (iron)', function (done) {
it('parses cookie (iron)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('key', { encoding: 'iron', password: 'password' });
definitions.parse('key=Fe26.2**f3fc42242467f7a97c042be866a32c1e7645045c2cc085124eadc66d25fc8395*URXpH8k-R0d4O5bnY23fRQ*uq9rd8ZzdjZqUrq9P2Ci0yZ-EEUikGzxTLn6QTcJ0bc**3880c0ac8bab054f529afec8660ebbbbc8050e192e39e5d622e7ac312b9860d0*r_g7N9kJYqXDrFlvOnuKpfpEWwrJLOKMXEI43LAGeFg', function (err, states, failed) {
definitions.parse('key=Fe26.2**f3fc42242467f7a97c042be866a32c1e7645045c2cc085124eadc66d25fc8395*URXpH8k-R0d4O5bnY23fRQ*uq9rd8ZzdjZqUrq9P2Ci0yZ-EEUikGzxTLn6QTcJ0bc**3880c0ac8bab054f529afec8660ebbbbc8050e192e39e5d622e7ac312b9860d0*r_g7N9kJYqXDrFlvOnuKpfpEWwrJLOKMXEI43LAGeFg', (err, states, failed) => {

@@ -380,7 +380,7 @@ expect(err).to.not.exist();

it('parses cookie (iron settings)', function (done) {
it('parses cookie (iron settings)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('key', { encoding: 'iron', password: 'password', iron: Iron.defaults });
definitions.parse('key=Fe26.2**f3fc42242467f7a97c042be866a32c1e7645045c2cc085124eadc66d25fc8395*URXpH8k-R0d4O5bnY23fRQ*uq9rd8ZzdjZqUrq9P2Ci0yZ-EEUikGzxTLn6QTcJ0bc**3880c0ac8bab054f529afec8660ebbbbc8050e192e39e5d622e7ac312b9860d0*r_g7N9kJYqXDrFlvOnuKpfpEWwrJLOKMXEI43LAGeFg', function (err, states, failed) {
definitions.parse('key=Fe26.2**f3fc42242467f7a97c042be866a32c1e7645045c2cc085124eadc66d25fc8395*URXpH8k-R0d4O5bnY23fRQ*uq9rd8ZzdjZqUrq9P2Ci0yZ-EEUikGzxTLn6QTcJ0bc**3880c0ac8bab054f529afec8660ebbbbc8050e192e39e5d622e7ac312b9860d0*r_g7N9kJYqXDrFlvOnuKpfpEWwrJLOKMXEI43LAGeFg', (err, states, failed) => {

@@ -394,7 +394,7 @@ expect(err).to.not.exist();

it('parses cookie (signed form)', function (done) {
it('parses cookie (signed form)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'form', sign: { password: 'password' } });
definitions.parse('sid=a=1&b=2&c=3%20x.2d75635d74c1a987f84f3ee7f3113b9a2ff71f89d6692b1089f19d5d11d140f8*xGhc6WvkE55V-TzucCl0NVFmbijeCwgs5Hf5tAVbSUo', function (err, states, failed) {
definitions.parse('sid=a=1&b=2&c=3%20x.2d75635d74c1a987f84f3ee7f3113b9a2ff71f89d6692b1089f19d5d11d140f8*xGhc6WvkE55V-TzucCl0NVFmbijeCwgs5Hf5tAVbSUo', (err, states, failed) => {

@@ -408,7 +408,7 @@ expect(err).to.not.exist();

it('parses cookie (signed form integrity settings)', function (done) {
it('parses cookie (signed form integrity settings)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'form', sign: { password: 'password', integrity: Iron.defaults.integrity } });
definitions.parse('sid=a=1&b=2&c=3%20x.2d75635d74c1a987f84f3ee7f3113b9a2ff71f89d6692b1089f19d5d11d140f8*xGhc6WvkE55V-TzucCl0NVFmbijeCwgs5Hf5tAVbSUo', function (err, states, failed) {
definitions.parse('sid=a=1&b=2&c=3%20x.2d75635d74c1a987f84f3ee7f3113b9a2ff71f89d6692b1089f19d5d11d140f8*xGhc6WvkE55V-TzucCl0NVFmbijeCwgs5Hf5tAVbSUo', (err, states, failed) => {

@@ -422,7 +422,7 @@ expect(err).to.not.exist();

it('parses cookie (cookie level strict override)', function (done) {
it('parses cookie (cookie level strict override)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('a', { strictHeader: false });
definitions.parse('a="1', function (err, states, failed) {
definitions.parse('a="1', (err, states, failed) => {

@@ -436,6 +436,6 @@ expect(err).to.not.exist();

it('fails parsing cookie (mismatching quotes)', function (done) {
it('fails parsing cookie (mismatching quotes)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a="1; b="2"; c=3', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a="1; b="2"; c=3', (err, states, failed) => {

@@ -467,6 +467,6 @@ expect(err).to.exist();

it('ignores failed parsing cookie (mismatching quotes)', function (done) {
it('ignores failed parsing cookie (mismatching quotes)', (done) => {
var definitions = new Statehood.Definitions({ ignoreErrors: true });
definitions.parse('a="1; b="2"; c=3', function (err, states, failed) {
const definitions = new Statehood.Definitions({ ignoreErrors: true });
definitions.parse('a="1; b="2"; c=3', (err, states, failed) => {

@@ -495,7 +495,7 @@ expect(err).to.not.exist();

it('ignores failed parsing cookie (cookie settings)', function (done) {
it('ignores failed parsing cookie (cookie settings)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('a', { ignoreErrors: true });
definitions.parse('a="1', function (err, states, failed) {
definitions.parse('a="1', (err, states, failed) => {

@@ -507,6 +507,6 @@ expect(err).to.not.exist();

it('fails parsing cookie (name)', function (done) {
it('fails parsing cookie (name)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a@="1"; b="2"; c=3', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a@="1"; b="2"; c=3', (err, states, failed) => {

@@ -535,6 +535,6 @@ expect(err).to.exist();

it('fails parsing cookie (multiple)', function (done) {
it('fails parsing cookie (multiple)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a@="1"; b@="2"; c=3', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a@="1"; b@="2"; c=3', (err, states, failed) => {

@@ -578,6 +578,6 @@ expect(err).to.exist();

it('ignores failed parsing cookie (name)', function (done) {
it('ignores failed parsing cookie (name)', (done) => {
var definitions = new Statehood.Definitions({ ignoreErrors: true });
definitions.parse('a@="1"; b="2"; c=3', function (err, states, failed) {
const definitions = new Statehood.Definitions({ ignoreErrors: true });
definitions.parse('a@="1"; b="2"; c=3', (err, states, failed) => {

@@ -589,6 +589,6 @@ expect(err).to.not.exist();

it('fails parsing cookie (empty pair)', function (done) {
it('fails parsing cookie (empty pair)', (done) => {
var definitions = new Statehood.Definitions();
definitions.parse('a=1; b=2; c=3;;', function (err, states, failed) {
const definitions = new Statehood.Definitions();
definitions.parse('a=1; b=2; c=3;;', (err, states, failed) => {

@@ -601,7 +601,7 @@ expect(err).to.exist();

it('fails parsing cookie (base64json)', function (done) {
it('fails parsing cookie (base64json)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('x', { encoding: 'base64json' });
definitions.parse('x=XeyJ0ZXN0aW5nIjoianNvbiJ9', function (err, states, failed) {
definitions.parse('x=XeyJ0ZXN0aW5nIjoianNvbiJ9', (err, states, failed) => {

@@ -632,7 +632,7 @@ expect(err).to.exist();

it('ignores failed parsing cookie (base64json)', function (done) {
it('ignores failed parsing cookie (base64json)', (done) => {
var definitions = new Statehood.Definitions({ ignoreErrors: true });
const definitions = new Statehood.Definitions({ ignoreErrors: true });
definitions.add('x', { encoding: 'base64json' });
definitions.parse('x=XeyJ0ZXN0aW5nIjoianNvbiJ9', function (err, states, failed) {
definitions.parse('x=XeyJ0ZXN0aW5nIjoianNvbiJ9', (err, states, failed) => {

@@ -644,7 +644,7 @@ expect(err).to.not.exist();

it('fails parsing cookie (double base64json)', function (done) {
it('fails parsing cookie (double base64json)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('x', { encoding: 'base64json' });
definitions.parse('x=XeyJ0ZXN0aW5nIjoianNvbiJ9; x=XeyJ0ZXN0aW5dnIjoianNvbiJ9', function (err, states, failed) {
definitions.parse('x=XeyJ0ZXN0aW5nIjoianNvbiJ9; x=XeyJ0ZXN0aW5dnIjoianNvbiJ9', (err, states, failed) => {

@@ -657,7 +657,7 @@ expect(err).to.exist();

it('ignores failed parsing cookie (double base64json)', function (done) {
it('ignores failed parsing cookie (double base64json)', (done) => {
var definitions = new Statehood.Definitions({ ignoreErrors: true });
const definitions = new Statehood.Definitions({ ignoreErrors: true });
definitions.add('x', { encoding: 'base64json' });
definitions.parse('x=XeyJ0ZXN0aW5nIjoianNvbiJ9; x=XeyJ0ZXN0aW5dnIjoianNvbiJ9', function (err, states, failed) {
definitions.parse('x=XeyJ0ZXN0aW5nIjoianNvbiJ9; x=XeyJ0ZXN0aW5dnIjoianNvbiJ9', (err, states, failed) => {

@@ -669,7 +669,7 @@ expect(err).to.not.exist();

it('fails parsing cookie (iron)', function (done) {
it('fails parsing cookie (iron)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('key', { encoding: 'iron', password: 'password' });
definitions.parse('key=Fe26.1**f3fc42242467f7a97c042be866a32c1e7645045c2cc085124eadc66d25fc8395*URXpH8k-R0d4O5bnY23fRQ*uq9rd8ZzdjZqUrq9P2Ci0yZ-EEUikGzxTLn6QTcJ0bc**3880c0ac8bab054f529afec8660ebbbbc8050e192e39e5d622e7ac312b9860d0*r_g7N9kJYqXDrFlvOnuKpfpEWwrJLOKMXEI43LAGeFg', function (err, states, failed) {
definitions.parse('key=Fe26.1**f3fc42242467f7a97c042be866a32c1e7645045c2cc085124eadc66d25fc8395*URXpH8k-R0d4O5bnY23fRQ*uq9rd8ZzdjZqUrq9P2Ci0yZ-EEUikGzxTLn6QTcJ0bc**3880c0ac8bab054f529afec8660ebbbbc8050e192e39e5d622e7ac312b9860d0*r_g7N9kJYqXDrFlvOnuKpfpEWwrJLOKMXEI43LAGeFg', (err, states, failed) => {

@@ -682,7 +682,7 @@ expect(err).to.exist();

it('fails parsing cookie (iron password)', function (done) {
it('fails parsing cookie (iron password)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('key', { encoding: 'iron', password: 'passwordx' });
definitions.parse('key=Fe26.2**f3fc42242467f7a97c042be866a32c1e7645045c2cc085124eadc66d25fc8395*URXpH8k-R0d4O5bnY23fRQ*uq9rd8ZzdjZqUrq9P2Ci0yZ-EEUikGzxTLn6QTcJ0bc**3880c0ac8bab054f529afec8660ebbbbc8050e192e39e5d622e7ac312b9860d0*r_g7N9kJYqXDrFlvOnuKpfpEWwrJLOKMXEI43LAGeFg', function (err, states, failed) {
definitions.parse('key=Fe26.2**f3fc42242467f7a97c042be866a32c1e7645045c2cc085124eadc66d25fc8395*URXpH8k-R0d4O5bnY23fRQ*uq9rd8ZzdjZqUrq9P2Ci0yZ-EEUikGzxTLn6QTcJ0bc**3880c0ac8bab054f529afec8660ebbbbc8050e192e39e5d622e7ac312b9860d0*r_g7N9kJYqXDrFlvOnuKpfpEWwrJLOKMXEI43LAGeFg', (err, states, failed) => {

@@ -695,7 +695,7 @@ expect(err).to.exist();

it('fails parsing cookie (signed form missing options)', function (done) {
it('fails parsing cookie (signed form missing options)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'form', sign: {} });
definitions.parse('sid=a=1&b=2&c=3%20x.2d75635d74c1a987f84f3ee7f3113b9a2ff71f89d6692b1089f19d5d11d140f8*khsb8lmkNJS-iljqDKZDMmd__2PcHBz7Ksrc-48gZ-0', function (err, states, failed) {
definitions.parse('sid=a=1&b=2&c=3%20x.2d75635d74c1a987f84f3ee7f3113b9a2ff71f89d6692b1089f19d5d11d140f8*khsb8lmkNJS-iljqDKZDMmd__2PcHBz7Ksrc-48gZ-0', (err, states, failed) => {

@@ -708,7 +708,7 @@ expect(err).to.exist();

it('fails parsing cookie (signed form missing signature)', function (done) {
it('fails parsing cookie (signed form missing signature)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'form', sign: { password: 'password' } });
definitions.parse('sid=a=1&b=2&c=3%20x', function (err, states, failed) {
definitions.parse('sid=a=1&b=2&c=3%20x', (err, states, failed) => {

@@ -721,7 +721,7 @@ expect(err).to.exist();

it('ignores failed parsing cookie (signed form missing signature)', function (done) {
it('ignores failed parsing cookie (signed form missing signature)', (done) => {
var definitions = new Statehood.Definitions({ ignoreErrors: true });
const definitions = new Statehood.Definitions({ ignoreErrors: true });
definitions.add('sid', { encoding: 'form', sign: { password: 'password' } });
definitions.parse('sid=a=1&b=2&c=3%20x', function (err, states, failed) {
definitions.parse('sid=a=1&b=2&c=3%20x', (err, states, failed) => {

@@ -733,7 +733,7 @@ expect(err).to.not.exist();

it('fails parsing cookie (signed form missing signature double)', function (done) {
it('fails parsing cookie (signed form missing signature double)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'form', sign: { password: 'password' } });
definitions.parse('sid=a=1&b=2&c=3%20x; sid=a=1&b=2&c=3%20x', function (err, states, failed) {
definitions.parse('sid=a=1&b=2&c=3%20x; sid=a=1&b=2&c=3%20x', (err, states, failed) => {

@@ -746,7 +746,7 @@ expect(err).to.exist();

it('ignores failed parsing cookie (signed form missing signature double)', function (done) {
it('ignores failed parsing cookie (signed form missing signature double)', (done) => {
var definitions = new Statehood.Definitions({ ignoreErrors: true });
const definitions = new Statehood.Definitions({ ignoreErrors: true });
definitions.add('sid', { encoding: 'form', sign: { password: 'password' } });
definitions.parse('sid=a=1&b=2&c=3%20x; sid=a=1&b=2&c=3%20x', function (err, states, failed) {
definitions.parse('sid=a=1&b=2&c=3%20x; sid=a=1&b=2&c=3%20x', (err, states, failed) => {

@@ -758,7 +758,7 @@ expect(err).to.not.exist();

it('fails parsing cookie (signed form missing signature with sep)', function (done) {
it('fails parsing cookie (signed form missing signature with sep)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'form', sign: { password: 'password' } });
definitions.parse('sid=a=1&b=2&c=3%20x.', function (err, states, failed) {
definitions.parse('sid=a=1&b=2&c=3%20x.', (err, states, failed) => {

@@ -771,7 +771,7 @@ expect(err).to.exist();

it('fails parsing cookie (signed form invalid signature)', function (done) {
it('fails parsing cookie (signed form invalid signature)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'form', sign: { password: 'password' } });
definitions.parse('sid=a=1&b=2&c=3%20x.2d75635d74c1a987f84f3ee7f3113b9a2ff71f89d6692b1089f19d5d11d140f8', function (err, states, failed) {
definitions.parse('sid=a=1&b=2&c=3%20x.2d75635d74c1a987f84f3ee7f3113b9a2ff71f89d6692b1089f19d5d11d140f8', (err, states, failed) => {

@@ -784,7 +784,7 @@ expect(err).to.exist();

it('fails parsing cookie (signed form wrong signature)', function (done) {
it('fails parsing cookie (signed form wrong signature)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'form', sign: { password: 'password' } });
definitions.parse('sid=a=1&b=2&c=3%20x.2d75635d74c1a987f84f3ee7f3113b9a2ff71f89d6692b1089f19d5d11d140f8*-Ghc6WvkE55V-TzucCl0NVFmbijeCwgs5Hf5tAVbSUo', function (err, states, failed) {
definitions.parse('sid=a=1&b=2&c=3%20x.2d75635d74c1a987f84f3ee7f3113b9a2ff71f89d6692b1089f19d5d11d140f8*-Ghc6WvkE55V-TzucCl0NVFmbijeCwgs5Hf5tAVbSUo', (err, states, failed) => {

@@ -798,8 +798,8 @@ expect(err).to.exist();

describe('format()', function () {
describe('format()', () => {
it('skips an empty header', function (done) {
it('skips an empty header', (done) => {
var definitions = new Statehood.Definitions();
definitions.format(null, function (err, header) {
const definitions = new Statehood.Definitions();
definitions.format(null, (err, header) => {

@@ -812,6 +812,6 @@ expect(err).to.not.exist();

it('skips an empty array', function (done) {
it('skips an empty array', (done) => {
var definitions = new Statehood.Definitions();
definitions.format([], function (err, header) {
const definitions = new Statehood.Definitions();
definitions.format([], (err, header) => {

@@ -824,8 +824,8 @@ expect(err).to.not.exist();

it('formats a header', function (done) {
it('formats a header', (done) => {
var definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { ttl: 3600, isSecure: true, isHttpOnly: true, path: '/', domain: 'example.com' } }, function (err, header) {
const definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { ttl: 3600, isSecure: true, isHttpOnly: true, path: '/', domain: 'example.com' } }, (err, header) => {
var expires = new Date(Date.now() + 3600);
const expires = new Date(Date.now() + 3600);
expect(err).to.not.exist();

@@ -837,6 +837,6 @@ expect(header[0]).to.equal('sid=fihfieuhr9384hf; Max-Age=3; Expires=' + expires.toUTCString() + '; Secure; HttpOnly; Domain=example.com; Path=/');

it('formats a header (with null ttl)', function (done) {
it('formats a header (with null ttl)', (done) => {
var definitions = new Statehood.Definitions({ ttl: 3600 });
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { ttl: null, isSecure: true, isHttpOnly: true, path: '/', domain: 'example.com' } }, function (err, header) {
const definitions = new Statehood.Definitions({ ttl: 3600 });
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { ttl: null, isSecure: true, isHttpOnly: true, path: '/', domain: 'example.com' } }, (err, header) => {

@@ -849,6 +849,6 @@ expect(err).to.not.exist();

it('formats a header (with zero ttl)', function (done) {
it('formats a header (with zero ttl)', (done) => {
var definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { ttl: 0, isSecure: true, isHttpOnly: true, path: '/', domain: 'example.com' } }, function (err, header) {
const definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { ttl: 0, isSecure: true, isHttpOnly: true, path: '/', domain: 'example.com' } }, (err, header) => {

@@ -861,8 +861,8 @@ expect(err).to.not.exist();

it('formats a header with null value', function (done) {
it('formats a header with null value', (done) => {
var definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', options: { ttl: 3600, isSecure: true, isHttpOnly: true, path: '/', domain: 'example.com' } }, function (err, header) {
const definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', options: { ttl: 3600, isSecure: true, isHttpOnly: true, path: '/', domain: 'example.com' } }, (err, header) => {
var expires = new Date(Date.now() + 3600);
const expires = new Date(Date.now() + 3600);
expect(err).to.not.exist();

@@ -874,9 +874,9 @@ expect(header[0]).to.equal('sid=; Max-Age=3; Expires=' + expires.toUTCString() + '; Secure; HttpOnly; Domain=example.com; Path=/');

it('formats a header with server definition', function (done) {
it('formats a header with server definition', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { ttl: 3600, isSecure: true, isHttpOnly: true, path: '/', domain: 'example.com' });
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf' }, function (err, header) {
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf' }, (err, header) => {
var expires = new Date(Date.now() + 3600);
const expires = new Date(Date.now() + 3600);
expect(err).to.not.exist();

@@ -888,7 +888,7 @@ expect(header[0]).to.equal('sid=fihfieuhr9384hf; Max-Age=3; Expires=' + expires.toUTCString() + '; Secure; HttpOnly; Domain=example.com; Path=/');

it('formats a header with server definition (base64)', function (done) {
it('formats a header with server definition (base64)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'base64' });
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf' }, function (err, header) {
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf' }, (err, header) => {

@@ -901,7 +901,7 @@ expect(err).to.not.exist();

it('formats a header with server definition (base64json)', function (done) {
it('formats a header with server definition (base64json)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'base64json' });
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: 3 } }, function (err, header) {
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: 3 } }, (err, header) => {

@@ -914,11 +914,11 @@ expect(err).to.not.exist();

it('fails on a header with server definition and bad value (base64json)', function (done) {
it('fails on a header with server definition and bad value (base64json)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'base64json' });
var bad = { a: {} };
const bad = { a: {} };
bad.b = bad.a;
bad.a.x = bad.b;
definitions.format({ name: 'sid', value: bad }, function (err, header) {
definitions.format({ name: 'sid', value: bad }, (err, header) => {

@@ -930,7 +930,7 @@ expect(err).to.exist();

it('formats a header with server definition (form)', function (done) {
it('formats a header with server definition (form)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'form' });
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: '3 x' } }, function (err, header) {
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: '3 x' } }, (err, header) => {

@@ -943,5 +943,5 @@ expect(err).to.not.exist();

it('formats a header with server definition (form+sign)', function (done) {
it('formats a header with server definition (form+sign)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', {

@@ -959,3 +959,3 @@ encoding: 'form',

});
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: '3 x' } }, function (err, header) {
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: '3 x' } }, (err, header) => {

@@ -968,6 +968,6 @@ expect(err).to.not.exist();

it('formats a header with server definition (form+sign, buffer password)', function (done) {
it('formats a header with server definition (form+sign, buffer password)', (done) => {
var buffer = new Buffer('fa4321e8c21b44a49d382fa7709226855f40eb23a32b2f642c3fd797c958718e', 'base64');
var definitions = new Statehood.Definitions();
const buffer = new Buffer('fa4321e8c21b44a49d382fa7709226855f40eb23a32b2f642c3fd797c958718e', 'base64');
const definitions = new Statehood.Definitions();
definitions.add('sid', {

@@ -985,3 +985,3 @@ encoding: 'form',

});
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: '3 x' } }, function (err, header) {
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: '3 x' } }, (err, header) => {

@@ -994,5 +994,5 @@ expect(err).to.not.exist();

it('fails a header with bad server definition (form+sign)', function (done) {
it('fails a header with bad server definition (form+sign)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', {

@@ -1002,3 +1002,3 @@ encoding: 'form',

});
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: '3 x' } }, function (err, header) {
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: '3 x' } }, (err, header) => {

@@ -1011,7 +1011,7 @@ expect(err).to.exist();

it('formats a header with server definition (iron)', function (done) {
it('formats a header with server definition (iron)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'iron', password: 'password' });
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: 3 } }, function (err, header) {
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: 3 } }, (err, header) => {

@@ -1024,7 +1024,7 @@ expect(err).to.not.exist();

it('formats a header with server definition (iron + options)', function (done) {
it('formats a header with server definition (iron + options)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'iron', password: 'password', iron: Iron.defaults });
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: 3 } }, function (err, header) {
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: 3 } }, (err, header) => {

@@ -1037,7 +1037,7 @@ expect(err).to.not.exist();

it('formats a header with server definition (iron + options, buffer password)', function (done) {
it('formats a header with server definition (iron + options, buffer password)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'iron', password: Cryptiles.randomBits(256), iron: Iron.defaults });
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: 3 } }, function (err, header) {
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: 3 } }, (err, header) => {

@@ -1050,7 +1050,7 @@ expect(err).to.not.exist();

it('fails a header with bad server definition (iron)', function (done) {
it('fails a header with bad server definition (iron)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('sid', { encoding: 'iron' });
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: 3 } }, function (err, header) {
definitions.format({ name: 'sid', value: { a: 1, b: 2, c: 3 } }, (err, header) => {

@@ -1063,11 +1063,11 @@ expect(err).to.exist();

it('formats a header with multiple cookies', function (done) {
it('formats a header with multiple cookies', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.format([
{ name: 'sid', value: 'fihfieuhr9384hf', options: { ttl: 3600, isSecure: true, isHttpOnly: true, path: '/', domain: 'example.com' } },
{ name: 'pid', value: 'xyz' }
], function (err, header) {
], (err, header) => {
var expires = new Date(Date.now() + 3600);
const expires = new Date(Date.now() + 3600);
expect(err).to.not.exist();

@@ -1080,6 +1080,6 @@ expect(header[0]).to.equal('sid=fihfieuhr9384hf; Max-Age=3; Expires=' + expires.toUTCString() + '; Secure; HttpOnly; Domain=example.com; Path=/');

it('fails on bad cookie name', function (done) {
it('fails on bad cookie name', (done) => {
var definitions = new Statehood.Definitions();
definitions.format({ name: 's;id', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: 'example.com' } }, function (err, header) {
const definitions = new Statehood.Definitions();
definitions.format({ name: 's;id', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: 'example.com' } }, (err, header) => {

@@ -1092,6 +1092,6 @@ expect(err).to.exist();

it('allows bad cookie name in loose mode', function (done) {
it('allows bad cookie name in loose mode', (done) => {
var definitions = new Statehood.Definitions({ strictHeader: false });
definitions.format({ name: 's;id', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: 'example.com' } }, function (err, header) {
const definitions = new Statehood.Definitions({ strictHeader: false });
definitions.format({ name: 's;id', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: 'example.com' } }, (err, header) => {

@@ -1104,7 +1104,7 @@ expect(err).to.not.exist();

it('allows bad cookie name in loose mode (cookie level)', function (done) {
it('allows bad cookie name in loose mode (cookie level)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('s;id', { strictHeader: false });
definitions.format({ name: 's;id', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: 'example.com' } }, function (err, header) {
definitions.format({ name: 's;id', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: 'example.com' } }, (err, header) => {

@@ -1117,6 +1117,6 @@ expect(err).to.not.exist();

it('fails on bad cookie value', function (done) {
it('fails on bad cookie value', (done) => {
var definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fi"hfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: 'example.com' } }, function (err, header) {
const definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fi"hfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: 'example.com' } }, (err, header) => {

@@ -1129,6 +1129,6 @@ expect(err).to.exist();

it('fails on bad cookie value (non string)', function (done) {
it('fails on bad cookie value (non string)', (done) => {
var definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: {}, options: { isSecure: true, isHttpOnly: false, path: '/', domain: 'example.com' } }, function (err, header) {
const definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: {}, options: { isSecure: true, isHttpOnly: false, path: '/', domain: 'example.com' } }, (err, header) => {

@@ -1141,6 +1141,6 @@ expect(err).to.exist();

it('allows bad cookie value in loose mode', function (done) {
it('allows bad cookie value in loose mode', (done) => {
var definitions = new Statehood.Definitions({ strictHeader: false });
definitions.format({ name: 'sid', value: 'fi"hfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: 'example.com' } }, function (err, header) {
const definitions = new Statehood.Definitions({ strictHeader: false });
definitions.format({ name: 'sid', value: 'fi"hfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: 'example.com' } }, (err, header) => {

@@ -1153,6 +1153,6 @@ expect(err).to.not.exist();

it('fails on bad cookie domain', function (done) {
it('fails on bad cookie domain', (done) => {
var definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: '-example.com' } }, function (err, header) {
const definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: '-example.com' } }, (err, header) => {

@@ -1165,6 +1165,6 @@ expect(err).to.exist();

it('fails on too long cookie domain', function (done) {
it('fails on too long cookie domain', (done) => {
var definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: '1234567890123456789012345678901234567890123456789012345678901234567890.example.com' } }, function (err, header) {
const definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: '1234567890123456789012345678901234567890123456789012345678901234567890.example.com' } }, (err, header) => {

@@ -1177,6 +1177,6 @@ expect(err).to.exist();

it('formats a header with cookie domain with . prefix', function (done) {
it('formats a header with cookie domain with . prefix', (done) => {
var definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: '.12345678901234567890.example.com' } }, function (err, header) {
const definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: '/', domain: '.12345678901234567890.example.com' } }, (err, header) => {

@@ -1188,6 +1188,6 @@ expect(err).to.not.exist();

it('fails on bad cookie path', function (done) {
it('fails on bad cookie path', (done) => {
var definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: 'd', domain: 'example.com' } }, function (err, header) {
const definitions = new Statehood.Definitions();
definitions.format({ name: 'sid', value: 'fihfieuhr9384hf', options: { isSecure: true, isHttpOnly: false, path: 'd', domain: 'example.com' } }, (err, header) => {

@@ -1201,9 +1201,9 @@ expect(err).to.exist();

describe('passThrough()', function () {
describe('passThrough()', () => {
it('returns header unchanged', function (done) {
it('returns header unchanged', (done) => {
var definitions = new Statehood.Definitions();
var header = 'a=4;b=5;c=6';
var result = definitions.passThrough(header);
const definitions = new Statehood.Definitions();
const header = 'a=4;b=5;c=6';
const result = definitions.passThrough(header);
expect(result).to.equal(header);

@@ -1213,8 +1213,8 @@ done();

it('returns header excluding local', function (done) {
it('returns header excluding local', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('b');
var header = 'a=4;b=5;c=6';
var result = definitions.passThrough(header);
const header = 'a=4;b=5;c=6';
const result = definitions.passThrough(header);
expect(result).to.equal('a=4;c=6');

@@ -1224,8 +1224,8 @@ done();

it('returns header including local (fallback)', function (done) {
it('returns header including local (fallback)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('b');
var header = 'a=4;b=5;c=6';
var result = definitions.passThrough(header, true);
const header = 'a=4;b=5;c=6';
const result = definitions.passThrough(header, true);
expect(result).to.equal('a=4;b=5;c=6');

@@ -1235,8 +1235,8 @@ done();

it('returns header including local (state option)', function (done) {
it('returns header including local (state option)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('b', { passThrough: true });
var header = 'a=4;b=5;c=6';
var result = definitions.passThrough(header);
const header = 'a=4;b=5;c=6';
const result = definitions.passThrough(header);
expect(result).to.equal('a=4;b=5;c=6');

@@ -1246,8 +1246,8 @@ done();

it('returns header including local (state option with fallback)', function (done) {
it('returns header including local (state option with fallback)', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('b', { passThrough: false });
var header = 'a=4;b=5;c=6';
var result = definitions.passThrough(header, true);
const header = 'a=4;b=5;c=6';
const result = definitions.passThrough(header, true);
expect(result).to.equal('a=4;c=6');

@@ -1257,8 +1257,8 @@ done();

it('errors on invalid header', function (done) {
it('errors on invalid header', (done) => {
var definitions = new Statehood.Definitions();
const definitions = new Statehood.Definitions();
definitions.add('b');
var header = 'a=4;b=5;c=6;;';
var result = definitions.passThrough(header);
const header = 'a=4;b=5;c=6;;';
const result = definitions.passThrough(header);
expect(result.message).to.equal('Invalid cookie header');

@@ -1270,7 +1270,7 @@ done();

describe('prepareValue()', function () {
describe('prepareValue()', () => {
it('throws when missing options', function (done) {
it('throws when missing options', (done) => {
expect(function () {
expect(() => {

@@ -1283,8 +1283,8 @@ Statehood.prepareValue('name', 'value');

describe('exclude()', function () {
describe('exclude()', () => {
it('returns all keys', function (done) {
it('returns all keys', (done) => {
var header = 'a=4;b=5;c=6';
var result = Statehood.exclude(header, []);
const header = 'a=4;b=5;c=6';
const result = Statehood.exclude(header, []);
expect(result).to.equal(header);

@@ -1294,6 +1294,6 @@ done();

it('returns keys without excluded', function (done) {
it('returns keys without excluded', (done) => {
var header = 'a=4;b=5;c=6';
var result = Statehood.exclude(header, ['b']);
const header = 'a=4;b=5;c=6';
const result = Statehood.exclude(header, ['b']);
expect(result).to.equal('a=4;c=6');

@@ -1303,6 +1303,6 @@ done();

it('returns error on invalid header', function (done) {
it('returns error on invalid header', (done) => {
var header = 'a';
var result = Statehood.exclude(header, ['b']);
const header = 'a';
const result = Statehood.exclude(header, ['b']);
expect(result.message).to.equal('Invalid cookie header');

@@ -1309,0 +1309,0 @@ done();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc