Skip to content

Commit

Permalink
Revert "Add some tests for session duration behaviour"
Browse files Browse the repository at this point in the history
This reverts commit e3ce510.
  • Loading branch information
adamjmcgrath committed Jul 14, 2020
1 parent e3ce510 commit efd072a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 143 deletions.
113 changes: 8 additions & 105 deletions test/appSession.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ const request = require('request-promise-native').defaults({
const sinon = require('sinon');

const appSession = require('../lib/appSession');
const { encrypted } = require('./fixture/sessionEncryption');
const { makeIdToken } = require('./fixture/cert');
const sessionEncryption = require('./fixture/sessionEncryption');
const { get: getConfig } = require('../lib/config');
const { create: createServer } = require('./fixture/server');

Expand All @@ -18,25 +17,10 @@ const defaultConfig = {
issuerBaseURL: 'https://op.example.com',
baseURL: 'https://example.org',
secret: '__test_secret__',
errorOnRequiredAuth: true,
};

const login = async (claims) => {
const jar = request.jar();
await request.post('/session', {
baseUrl,
jar,
json: {
id_token: makeIdToken(claims),
},
});
return jar;
};

const baseUrl = 'http://localhost:3000';

const HR_MS = 60 * 60 * 1000;

describe('appSession', () => {
let server;

Expand Down Expand Up @@ -78,7 +62,7 @@ describe('appSession', () => {
baseUrl,
json: true,
headers: {
cookie: `appSession=${encrypted}`,
cookie: `appSession=${sessionEncryption.encrypted}`,
},
});
assert.equal(res.statusCode, 200);
Expand All @@ -91,7 +75,7 @@ describe('appSession', () => {
baseUrl,
json: true,
headers: {
cookie: `appSession=${encrypted}`,
cookie: `appSession=${sessionEncryption.encrypted}`,
},
});
assert.equal(res.statusCode, 200);
Expand Down Expand Up @@ -174,7 +158,7 @@ describe('appSession', () => {
json: true,
jar,
headers: {
cookie: `appSession=${encrypted}`,
cookie: `appSession=${sessionEncryption.encrypted}`,
},
});
const [cookie] = jar.getCookies(baseUrl);
Expand Down Expand Up @@ -210,7 +194,7 @@ describe('appSession', () => {
json: true,
jar,
headers: {
cookie: `appSession=${encrypted}`,
cookie: `appSession=${sessionEncryption.encrypted}`,
},
});
const [cookie] = jar.getCookies(baseUrl);
Expand All @@ -236,7 +220,7 @@ describe('appSession', () => {
json: true,
jar,
headers: {
cookie: `customName=${encrypted}`,
cookie: `customName=${sessionEncryption.encrypted}`,
},
});
const [cookie] = jar.getCookies(baseUrl);
Expand All @@ -259,7 +243,7 @@ describe('appSession', () => {
json: true,
jar,
headers: {
cookie: `appSession=${encrypted}`,
cookie: `appSession=${sessionEncryption.encrypted}`,
},
});
const [cookie] = jar.getCookies(baseUrl);
Expand All @@ -281,7 +265,7 @@ describe('appSession', () => {
json: true,
jar,
headers: {
cookie: `appSession=${encrypted}`,
cookie: `appSession=${sessionEncryption.encrypted}`,
},
});
assert.equal(res.statusCode, 200);
Expand Down Expand Up @@ -324,85 +308,4 @@ describe('appSession', () => {
const res = await request.get('/session', { baseUrl, json: true });
assert.equal(res.statusCode, 200);
});

it('should expire after 24hrs of inactivity by default', async () => {
const clock = sinon.useFakeTimers({ toFake: ['Date'] });
server = await createServer(appSession(getConfig(defaultConfig)));
const jar = await login({ sub: '__test_sub__' });
let res = await request.get('/session', { baseUrl, jar, json: true });
assert.isNotEmpty(res.body);
clock.tick(23 * HR_MS);
res = await request.get('/session', { baseUrl, jar, json: true });
assert.isNotEmpty(res.body);
clock.tick(25 * HR_MS);
res = await request.get('/session', { baseUrl, jar, json: true });
assert.isEmpty(res.body);
clock.restore();
});

it('should expire after 7days regardless of activity by default', async () => {
const clock = sinon.useFakeTimers({ toFake: ['Date'] });
server = await createServer(appSession(getConfig(defaultConfig)));
const jar = await login({ sub: '__test_sub__' });
let days = 7;
while (days--) {
clock.tick(23 * HR_MS);
let res = await request.get('/session', { baseUrl, jar, json: true });
assert.isNotEmpty(res.body);
}
clock.tick(8 * HR_MS);
let res = await request.get('/session', { baseUrl, jar, json: true });
assert.isEmpty(res.body);
clock.restore();
});

it('should expire only after defined absoluteDuration', async () => {
const clock = sinon.useFakeTimers({ toFake: ['Date'] });
server = await createServer(
appSession(
getConfig({
...defaultConfig,
session: {
rolling: false,
absoluteDuration: 10 * 60 * 60,
},
})
)
);
const jar = await login({ sub: '__test_sub__' });
clock.tick(9 * HR_MS);
let res = await request.get('/session', { baseUrl, jar, json: true });
assert.isNotEmpty(res.body);
clock.tick(2 * HR_MS);
res = await request.get('/session', { baseUrl, jar, json: true });
assert.isEmpty(res.body);
clock.restore();
});

it('should expire only after defined rollingDuration period of inactivty', async () => {
const clock = sinon.useFakeTimers({ toFake: ['Date'] });
server = await createServer(
appSession(
getConfig({
...defaultConfig,
session: {
rolling: true,
rollingDuration: 24 * 60 * 60,
absoluteDuration: false,
},
})
)
);
const jar = await login({ sub: '__test_sub__' });
let days = 30;
while (days--) {
clock.tick(23 * HR_MS);
let res = await request.get('/session', { baseUrl, jar, json: true });
assert.isNotEmpty(res.body);
}
clock.tick(25 * HR_MS);
let res = await request.get('/session', { baseUrl, jar, json: true });
assert.isEmpty(res.body);
clock.restore();
});
});
File renamed without changes.
38 changes: 2 additions & 36 deletions test/config.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,49 +217,14 @@ describe('get config', () => {
assert.throws(() => {
getConfig({
...defaultConfig,
secret: '__test_session_secret__',
session: {
rollingDuration: 3.14159,
},
});
}, '"session.rollingDuration" must be an integer');
});

it('should fail when rollingDuration is defined and rolling is false', function () {
assert.throws(() => {
getConfig({
...defaultConfig,
session: {
rolling: false,
rollingDuration: 100,
},
});
}, '"session.rollingDuration" must be false when "session.rolling" is disabled');
});

it('should fail when rollingDuration is not defined and rolling is true', function () {
assert.throws(() => {
getConfig({
...defaultConfig,
session: {
rolling: true,
rollingDuration: false,
},
});
}, '"session.rollingDuration" must be provided an integer value when "session.rolling" is true');
});

it('should fail when absoluteDuration is not defined and rolling is false', function () {
assert.throws(() => {
getConfig({
...defaultConfig,
session: {
rolling: false,
absoluteDuration: false,
},
});
}, '"session.absoluteDuration" must be provided an integer value when "session.rolling" is false');
});

it('should fail when app session secret is invalid', function () {
assert.throws(() => {
getConfig({
Expand All @@ -273,6 +238,7 @@ describe('get config', () => {
assert.throws(() => {
getConfig({
...defaultConfig,
secret: '__test_session_secret__',
session: {
cookie: {
httpOnly: '__invalid_httponly__',
Expand Down
4 changes: 2 additions & 2 deletions test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const nock = require('nock');
const wellKnown = require('./fixture/well-known.json');
const certs = require('./fixture/cert');

beforeEach(function () {
before(function () {
nock('https://op.example.com', { allowUnmocked: true })
.persist()
.get('/.well-known/openid-configuration')
Expand All @@ -24,6 +24,6 @@ beforeEach(function () {
.reply(200, certs.jwks);
});

afterEach(function () {
after(function () {
nock.cleanAll();
});

0 comments on commit efd072a

Please sign in to comment.