fix tests that require session authentication

This commit is contained in:
Matteo Pagliazzi
2016-02-20 21:02:46 +01:00
parent 2ed2fb5d06
commit 62ebde3186
6 changed files with 27 additions and 5 deletions

View File

@@ -10,10 +10,14 @@ import nconf from 'nconf';
import morgan from 'morgan';
import responseHandler from './response';
import setupBody from './setupBody';
import cookieSession from 'cookie-session';
const IS_PROD = nconf.get('IS_PROD');
const DISABLE_LOGGING = nconf.get('DISABLE_REQUEST_LOGGING');
const SESSION_SECRET = nconf.get('SESSION_SECRET');
const TWO_WEEKS = 1000 * 60 * 60 * 24 * 14;
export default function attachMiddlewares (app) {
if (!IS_PROD && !DISABLE_LOGGING) app.use(morgan('dev'));
@@ -22,6 +26,12 @@ export default function attachMiddlewares (app) {
extended: true, // Uses 'qs' library as old connect middleware
}));
app.use(bodyParser.json());
app.use(cookieSession({
name: 'connect:sess', // Used to keep backward compatibility with Express 3 cookies
secret: SESSION_SECRET,
httpOnly: false, // TODO this should be true for security, what about https only?
maxAge: TWO_WEEKS,
}));
app.use(expressValidator());
app.use(analytics);
app.use(setupBody);