mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
Fix bad redirection when no default_redirection_url is provided
This commit is contained in:
parent
b37c0293b8
commit
d1f0543ac6
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
41
server/test/routes/secondfactor/redirect.test.ts
Normal file
41
server/test/routes/secondfactor/redirect.test.ts
Normal 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: "/"
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user