Fix bad redirection when no default_redirection_url is provided

This commit is contained in:
Clement Michaud 2017-11-01 20:57:46 +01:00
parent b37c0293b8
commit d1f0543ac6
4 changed files with 52 additions and 8 deletions

View File

@ -4,7 +4,6 @@ import objectPath = require("object-path");
import winston = require("winston");
import Endpoints = require("../../../../../shared/api");
import { ServerVariables } from "../../ServerVariables";
import { AuthenticationSessionHandler } from "../../AuthenticationSessionHandler";
import BluebirdPromise = require("bluebird");
import ErrorReplies = require("../../ErrorReplies");
import UserMessages = require("../../../../../shared/UserMessages");
@ -12,11 +11,11 @@ import { RedirectionMessage } from "../../../../../shared/RedirectionMessage";
import Constants = require("../../../../../shared/constants");
export default function (vars: ServerVariables) {
return function (req: express.Request, res: express.Response): BluebirdPromise<void> {
return function (req: express.Request, res: express.Response)
: BluebirdPromise<void> {
return new BluebirdPromise<void>(function (resolve, reject) {
const authSession = AuthenticationSessionHandler.get(req, vars.logger);
let redirectUrl: string;
let redirectUrl: string = "/";
if (vars.config.default_redirection_url) {
redirectUrl = vars.config.default_redirection_url;
}

View File

@ -5,6 +5,10 @@ block form-header
block content
img(class="header-img" src="/img/success.png" alt="success")
p You are already logged in as <b>#{ username }</b>.<br/><br/>
| If you are not redirected in few seconds, click <a href="#{ redirection_url }">here</a>.<br/><br/>
| Otherwise, click <a href="#{ logout_endpoint }">here</a> to log off.
if redirection_url
p You are already logged in as <b>#{ username }</b>.<br/><br/>
| If you are not redirected in few seconds, click <a href="#{ redirection_url }">here</a>.<br/><br/>
| Otherwise, click <a href="#{ logout_endpoint }">here</a> to log off.
else
p You are already logged in as <b>#{ username }</b>.<br/><br/>
| Click <a href="#{ logout_endpoint }">here</a> to log off.

View File

@ -15,7 +15,7 @@ describe("test second factor GET endpoint handler", function () {
let res: ExpressMock.ResponseMock;
beforeEach(function () {
const s = ServerVariablesMockBuilder.build(true);
const s = ServerVariablesMockBuilder.build();
mocks = s.mocks;
vars = s.variables;

View File

@ -0,0 +1,41 @@
import Redirect from "../../../src/lib/routes/secondfactor/redirect";
import ExpressMock = require("../../mocks/express");
import { ServerVariablesMockBuilder, ServerVariablesMock }
from "../../mocks/ServerVariablesMockBuilder";
import { ServerVariables } from "../../../src/lib/ServerVariables";
import Assert = require("assert");
describe("test second factor redirect", function() {
let req: ExpressMock.RequestMock;
let res: ExpressMock.ResponseMock;
let mocks: ServerVariablesMock;
let vars: ServerVariables;
beforeEach(function () {
const s = ServerVariablesMockBuilder.build();
mocks = s.mocks;
vars = s.variables;
req = ExpressMock.RequestMock();
res = ExpressMock.ResponseMock();
});
it("should redirect to default_redirection_url", function() {
vars.config.default_redirection_url = "http://default_redirection_url";
Redirect(vars)(req as any, res as any)
.then(function() {
Assert(res.json.calledWith({
redirect: "http://default_redirection_url"
}));
});
});
it("should redirect to /", function() {
Redirect(vars)(req as any, res as any)
.then(function() {
Assert(res.json.calledWith({
redirect: "/"
}));
});
});
});