2017-07-19 19:06:12 +00:00
|
|
|
import Sinon = require("sinon");
|
|
|
|
import Express = require("express");
|
|
|
|
import Assert = require("assert");
|
2017-10-06 22:09:42 +00:00
|
|
|
import Get401 from "../../../../src/lib/routes/error/401/get";
|
2017-11-01 13:24:18 +00:00
|
|
|
import { ServerVariables } from "../../../../src/lib/ServerVariables";
|
|
|
|
import { ServerVariablesMockBuilder, ServerVariablesMock }
|
|
|
|
from "../../../mocks/ServerVariablesMockBuilder";
|
2017-07-19 19:06:12 +00:00
|
|
|
|
|
|
|
describe("Server error 401", function () {
|
2017-11-01 13:24:18 +00:00
|
|
|
let vars: ServerVariables;
|
|
|
|
let mocks: ServerVariablesMock;
|
|
|
|
let req: any;
|
|
|
|
let res: any;
|
|
|
|
let renderSpy: Sinon.SinonSpy;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
const s = ServerVariablesMockBuilder.build();
|
|
|
|
vars = s.variables;
|
|
|
|
mocks = s.mocks;
|
|
|
|
|
|
|
|
renderSpy = Sinon.spy();
|
|
|
|
req = {
|
|
|
|
headers: {}
|
|
|
|
};
|
|
|
|
res = {
|
|
|
|
render: renderSpy
|
2017-07-19 19:06:12 +00:00
|
|
|
};
|
2017-11-01 13:24:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should set redirection url to the default redirection url", function () {
|
|
|
|
vars.config.default_redirection_url = "http://default-redirection";
|
|
|
|
return Get401(vars)(req, res as any)
|
|
|
|
.then(function () {
|
|
|
|
Assert(renderSpy.calledOnce);
|
|
|
|
Assert(renderSpy.calledWithExactly("errors/401", {
|
|
|
|
redirection_url: "http://default-redirection"
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should set redirection url to the referer", function () {
|
|
|
|
req.headers["referer"] = "http://redirection";
|
|
|
|
return Get401(vars)(req, res as any)
|
|
|
|
.then(function () {
|
|
|
|
Assert(renderSpy.calledOnce);
|
|
|
|
Assert(renderSpy.calledWithExactly("errors/401", {
|
|
|
|
redirection_url: "http://redirection"
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2017-07-19 19:06:12 +00:00
|
|
|
|
2017-11-01 13:24:18 +00:00
|
|
|
it("should render without redirecting the user", function () {
|
|
|
|
return Get401(vars)(req, res as any)
|
2017-07-19 19:06:12 +00:00
|
|
|
.then(function () {
|
2017-11-01 13:24:18 +00:00
|
|
|
Assert(renderSpy.calledOnce);
|
|
|
|
Assert(renderSpy.calledWithExactly("errors/401", {
|
|
|
|
redirection_url: undefined
|
|
|
|
}));
|
2017-07-19 19:06:12 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|