mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
parent
609142f47e
commit
333601eaea
@ -26,6 +26,7 @@ class UserController extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Depcreated, use "/logout" instead. Will be removed in later release.
|
||||||
logout(req, res) {
|
logout(req, res) {
|
||||||
if (req.session) {
|
if (req.session) {
|
||||||
req.session = null;
|
req.session = null;
|
||||||
@ -33,7 +34,7 @@ class UserController extends Controller {
|
|||||||
if (req.logout) {
|
if (req.logout) {
|
||||||
req.logout();
|
req.logout();
|
||||||
}
|
}
|
||||||
res.redirect('/');
|
res.redirect(`${this.config.baseUriPath}/`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,5 +55,5 @@ test('should logout and redirect', t => {
|
|||||||
return request
|
return request
|
||||||
.get(`${base}/api/admin/user/logout`)
|
.get(`${base}/api/admin/user/logout`)
|
||||||
.expect(302)
|
.expect(302)
|
||||||
.expect('Location', '/');
|
.expect('Location', `${base}/`);
|
||||||
});
|
});
|
||||||
|
@ -7,6 +7,7 @@ const FeatureController = require('./client-api/feature.js');
|
|||||||
const Controller = require('./controller');
|
const Controller = require('./controller');
|
||||||
const HealthCheckController = require('./health-check');
|
const HealthCheckController = require('./health-check');
|
||||||
const BackstageCTR = require('./backstage.js');
|
const BackstageCTR = require('./backstage.js');
|
||||||
|
const LogoutController = require('./logout');
|
||||||
const api = require('./api-def');
|
const api = require('./api-def');
|
||||||
|
|
||||||
class IndexRouter extends Controller {
|
class IndexRouter extends Controller {
|
||||||
@ -14,6 +15,7 @@ class IndexRouter extends Controller {
|
|||||||
super();
|
super();
|
||||||
this.use('/health', new HealthCheckController(config).router);
|
this.use('/health', new HealthCheckController(config).router);
|
||||||
this.use('/internal-backstage', new BackstageCTR(config).router);
|
this.use('/internal-backstage', new BackstageCTR(config).router);
|
||||||
|
this.use('/logout', new LogoutController(config).router);
|
||||||
this.get(api.uri, this.index);
|
this.get(api.uri, this.index);
|
||||||
this.use(api.links.admin.uri, new AdminApi(config).router);
|
this.use(api.links.admin.uri, new AdminApi(config).router);
|
||||||
this.use(api.links.client.uri, new ClientApi(config).router);
|
this.use(api.links.client.uri, new ClientApi(config).router);
|
||||||
|
22
lib/routes/logout.js
Normal file
22
lib/routes/logout.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Controller = require('./controller');
|
||||||
|
|
||||||
|
class HealthCheckController extends Controller {
|
||||||
|
constructor(config) {
|
||||||
|
super(config);
|
||||||
|
this.get('/', this.logout);
|
||||||
|
}
|
||||||
|
|
||||||
|
logout(req, res) {
|
||||||
|
if (req.session) {
|
||||||
|
req.session = null;
|
||||||
|
}
|
||||||
|
if (req.logout) {
|
||||||
|
req.logout();
|
||||||
|
}
|
||||||
|
res.redirect(`${this.config.baseUriPath}/`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = HealthCheckController;
|
46
lib/routes/logout.test.js
Normal file
46
lib/routes/logout.test.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const test = require('ava');
|
||||||
|
const supertest = require('supertest');
|
||||||
|
const store = require('./../../test/fixtures/store');
|
||||||
|
const getLogger = require('../../test/fixtures/no-logger');
|
||||||
|
const getApp = require('../app');
|
||||||
|
const User = require('../user');
|
||||||
|
|
||||||
|
const { EventEmitter } = require('events');
|
||||||
|
const eventBus = new EventEmitter();
|
||||||
|
|
||||||
|
const currentUser = new User({ email: 'test@mail.com' });
|
||||||
|
|
||||||
|
function getSetup() {
|
||||||
|
const base = `/random${Math.round(Math.random() * 1000)}`;
|
||||||
|
const stores = store.createStores();
|
||||||
|
const app = getApp({
|
||||||
|
baseUriPath: base,
|
||||||
|
stores,
|
||||||
|
eventBus,
|
||||||
|
getLogger,
|
||||||
|
preHook: a => {
|
||||||
|
a.use((req, res, next) => {
|
||||||
|
req.user = currentUser;
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
base,
|
||||||
|
strategyStore: stores.strategyStore,
|
||||||
|
request: supertest(app),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
test('should logout and redirect', t => {
|
||||||
|
t.plan(0);
|
||||||
|
const { request, base } = getSetup();
|
||||||
|
|
||||||
|
return request
|
||||||
|
.get(`${base}/logout`)
|
||||||
|
.expect(302)
|
||||||
|
.expect('Location', `${base}/`);
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user