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

@hmcts/one-per-page

Package Overview
Dependencies
Maintainers
18
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hmcts/one-per-page - npm Package Compare versions

Comparing version 3.4.3 to 3.5.1

19

examples/test-app/app.js

@@ -52,3 +52,2 @@ const config = require('config');

journey(app, {
baseUrl,
steps: [

@@ -75,3 +74,19 @@ Start,

redis: { url: config.redisUrl },
cookie: { secure: false }
cookie: {
// default req.hostname
domain: 'localhost',
// default: false
expires: false,
// default: req.secure
secure: false
},
// default: undefined
secret: config.secret,
// Optional, default: undefined
// return key to encryption session at rest ( redis )
sessionEncryption: (/* req */) => config.encryptionAtRestKey
},

@@ -78,0 +93,0 @@ apiUrl: `${baseUrl}/api/submit`

2

package.json

@@ -5,3 +5,3 @@ {

"homepage": "https://github.com/hmcts/one-per-page#readme",
"version": "3.4.3",
"version": "3.5.1",
"main": "./src/main.js",

@@ -8,0 +8,0 @@ "repository": {

const session = require('../session');
const { i18nMiddleware } = require('../i18n/i18Next');
const errorPages = require('../errors/errorPages');
const urlParse = require('url-parse');
const defaultIfUndefined = require('../util/defaultIfUndefined');

@@ -11,9 +10,2 @@ const { defined } = require('../util/checks');

const parseUrl = baseUrl => {
if (typeof baseUrl === 'undefined') {
throw new Error('Must provide a baseUrl');
}
return urlParse(baseUrl);
};
const constructorFrom = step => {

@@ -34,7 +26,3 @@ if (defined(step.prototype)) {

} else {
const cookie = Object.assign(
{ domain: parseUrl(userOpts.baseUrl).hostname },
userOpts.session.cookie || {}
);
const sessionOpts = Object.assign({}, userOpts.session, { cookie });
const sessionOpts = Object.assign({ cookie: {} }, userOpts.session);
sessionProvider = session(sessionOpts);

@@ -46,3 +34,2 @@ }

return Object.assign({}, userOpts, {
baseUrl: userOpts.baseUrl,
steps,

@@ -49,0 +36,0 @@ session: sessionProvider,

@@ -20,4 +20,5 @@ const expressSession = require('express-session');

const cookie = Object.assign({}, {
secure: defaultIfUndefined(userCookie.secure, !isTest),
expires: defaultIfUndefined(userCookie.expires, false)
secure: defaultIfUndefined(userCookie.secure, req.secure),
expires: defaultIfUndefined(userCookie.expires, false),
domain: defaultIfUndefined(userCookie.hostname, req.hostname)
}, userCookie);

@@ -24,0 +25,0 @@

@@ -13,4 +13,3 @@ const { expect } = require('../util/chai');

const defaultOptions = {
session: { secret: 'foo' },
baseUrl: 'http://localhost'
session: { secret: 'foo' }
};

@@ -17,0 +16,0 @@ const options = (...overrides) => {

@@ -10,6 +10,3 @@ const proxyquire = require('proxyquire');

class TestPage extends Page {}
const defaultOptions = {
session: { secret: 'foo' },
baseUrl: 'http://localhost'
};
const defaultOptions = { session: { secret: 'foo' } };
const options = (...overrides) => {

@@ -81,36 +78,2 @@ const foo = Object.assign(

describe('baseUrl option', () => {
let spy = null;
let stubbedJourney = null;
beforeEach(() => {
spy = sinon.spy(session);
stubbedJourney = proxyquire(
'../../src/flow/journey',
{ '../session': spy }
);
});
const test = domain => () => {
const baseUrl = `http://${domain}:1231/foo/bar`;
stubbedJourney(testApp(), { baseUrl, session: { secret: 'foo' } });
return expect(spy).calledWith(sinon.match({ cookie: { domain } }));
};
it('used as default for cookie.domain (localhost)', test('localhost'));
it('used as default for cookie.domain (127.0.0.1)', test('127.0.0.1'));
it('used as default for cookie.domain (example.com)', test('example.com'));
it('used as default for cookie.domain (new tld)', test('allen.digital'));
it('wont override an explicit cookie.domain', () => {
const domain = 'explicit.override.com';
const baseUrl = 'http://base.url.com';
stubbedJourney(testApp(), {
baseUrl,
session: { secret: 'foo', cookie: { domain } }
});
return expect(spy).calledWith(sinon.match({ cookie: { domain } }));
});
});
describe('session option', () => {

@@ -130,6 +93,2 @@ describe('as a function', () => {

describe('as an object', () => {
it('requires a baseUrl to be provided', () => {
expect(() => journey(testApp(), {})).to.throw('Must provide a baseUrl');
});
it('configures the session middleware', () => {

@@ -141,9 +100,18 @@ const spy = sinon.spy(session);

);
const domain = '127.0.0.1';
const baseUrl = `http://${domain}`;
const secret = 'keyboard cat';
stubbedJourney(testApp(), { baseUrl, session: { secret } });
stubbedJourney(testApp(), { session: { secret } });
expect(spy).calledWith(sinon.match({ secret }));
expect(spy).calledWith(sinon.match({ cookie: { domain } }));
expect(spy).calledWith(sinon.match({ cookie: {} }));
});
it('accepts custom cookie options', () => {
const spy = sinon.spy(session);
const stubbedJourney = proxyquire(
'../../src/flow/journey',
{ '../session': spy }
);
const cookie = { customOption: true };
stubbedJourney(testApp(), { session: { cookie } });
expect(spy).calledWith(sinon.match({ cookie }));
});
});

@@ -178,3 +146,2 @@ });

{
baseUrl: 'http://localhost',
session: { secret: 'foo' },

@@ -181,0 +148,0 @@ errorPages: errorPagesConfig

@@ -45,3 +45,3 @@ const express = require('express');

app.use(session({ baseUrl: '127.0.0.1', secret: 'keyboard cat' }));
app.use(session({ secret: 'keyboard cat' }));
app.use(cookieParser());

@@ -48,0 +48,0 @@ app.use(i18nMiddleware);

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