1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00

fix: none authentication should have a mock user (#449)

This also fix the bug introduces where authentication mode triggers readOnly mode in the UI.
This commit is contained in:
Ivar Conradi Østhus 2019-06-08 12:50:59 +02:00
parent ecc81c0a18
commit 62b97ca828
4 changed files with 48 additions and 1 deletions

View File

@ -11,6 +11,7 @@ const unleashSession = require('./middleware/session');
const responseTime = require('./middleware/response-time'); const responseTime = require('./middleware/response-time');
const requestLogger = require('./middleware/request-logger'); const requestLogger = require('./middleware/request-logger');
const simpleAuthentication = require('./middleware/simple-authentication'); const simpleAuthentication = require('./middleware/simple-authentication');
const noAuthentication = require('./middleware/no-authentication');
module.exports = function(config) { module.exports = function(config) {
const app = express(); const app = express();
@ -42,6 +43,10 @@ module.exports = function(config) {
simpleAuthentication(baseUriPath, app); simpleAuthentication(baseUriPath, app);
} }
if (config.adminAuthentication === 'none') {
noAuthentication(baseUriPath, app);
}
if (typeof config.preRouterHook === 'function') { if (typeof config.preRouterHook === 'function') {
config.preRouterHook(app); config.preRouterHook(app);
} }

View File

@ -0,0 +1,12 @@
'use strict';
const User = require('../user');
function noneAuthentication(basePath = '', app) {
app.use(`${basePath}/api/admin/`, (req, res, next) => {
req.user = new User({ email: 'none@unknown.com' });
next();
});
}
module.exports = noneAuthentication;

View File

@ -0,0 +1,30 @@
'use strict';
const test = require('ava');
const supertest = require('supertest');
const express = require('express');
const noAuthentication = require('./no-authentication');
test('should add dummy user object to all requests', t => {
t.plan(1);
const app = express();
noAuthentication('', app);
app.get('/api/admin/test', (req, res) => {
const user = Object.assign({}, req.user);
return res
.status(200)
.json(user)
.end();
});
const request = supertest(app);
return request
.get('/api/admin/test')
.expect(200)
.expect(res => {
console.log(res.body);
t.true(res.body.email === 'none@unknown.com');
});
});

View File

@ -91,7 +91,7 @@ test.serial('creates new feature toggle with createdBy unknown', async t => {
await request await request
.get('/api/admin/events') .get('/api/admin/events')
.expect(res => { .expect(res => {
t.true(res.body.events[0].createdBy === 'unknown'); t.true(res.body.events[0].createdBy === 'none@unknown.com');
}) })
.then(destroy); .then(destroy);
}); });