mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
563e2da323
This URL is used when user access the authentication domain without providing the 'redirect' query parameter. In that case, Authelia does not know where to redirect the user. If the parameter is defined, Authelia can redirect the user to a default page when no redirect parameter is provided. When user is already authenticated and tries to access the authentication domain, the "already logged in" page is rendered and it now tells the user he is to be redirected in few seconds and uses this URL to redirect. This parameter is optional. If it is not provided, there is only a notification message at the end of the authentication process, as before, and the user is not redirected when visiting the authentication domain while already authenticated.
94 lines
3.2 KiB
TypeScript
94 lines
3.2 KiB
TypeScript
import sinon = require("sinon");
|
|
import winston = require("winston");
|
|
import assert = require("assert");
|
|
import BluebirdPromise = require("bluebird");
|
|
|
|
import { Identity } from "../../../../../types/Identity";
|
|
import RegistrationHandler from "../../../../../src/lib/routes/secondfactor/u2f/identity/RegistrationHandler";
|
|
import AuthenticationSession = require("../../../../../src/lib/AuthenticationSession");
|
|
|
|
import ExpressMock = require("../../../../mocks/express");
|
|
import { UserDataStoreStub } from "../../../../mocks/storage/UserDataStoreStub";
|
|
import { ServerVariablesMock, ServerVariablesMockBuilder } from "../../../../mocks/ServerVariablesMockBuilder";
|
|
import { ServerVariables } from "../../../../../src/lib/ServerVariables";
|
|
|
|
describe("test register handler", 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();
|
|
req.app = {};
|
|
req.session = {
|
|
auth: {
|
|
userid: "user",
|
|
email: "user@example.com",
|
|
first_factor: true,
|
|
second_factor: false
|
|
}
|
|
};
|
|
req.headers = {};
|
|
req.headers.host = "localhost";
|
|
|
|
const options = {
|
|
inMemoryOnly: true
|
|
};
|
|
|
|
mocks.userDataStore.saveU2FRegistrationStub.returns(BluebirdPromise.resolve({}));
|
|
mocks.userDataStore.retrieveU2FRegistrationStub.returns(BluebirdPromise.resolve({}));
|
|
mocks.userDataStore.produceIdentityValidationTokenStub.returns(BluebirdPromise.resolve({}));
|
|
mocks.userDataStore.consumeIdentityValidationTokenStub.returns(BluebirdPromise.resolve({}));
|
|
|
|
res = ExpressMock.ResponseMock();
|
|
res.send = sinon.spy();
|
|
res.json = sinon.spy();
|
|
res.status = sinon.spy();
|
|
});
|
|
|
|
describe("test u2f registration check", test_registration_check);
|
|
|
|
function test_registration_check() {
|
|
it("should fail if first_factor has not been passed", function () {
|
|
req.session.auth.first_factor = false;
|
|
return new RegistrationHandler(vars.logger).preValidationInit(req as any)
|
|
.then(function () { return BluebirdPromise.reject(new Error("It should fail")); })
|
|
.catch(function (err: Error) {
|
|
return BluebirdPromise.resolve();
|
|
});
|
|
});
|
|
|
|
it("should fail if userid is missing", function (done) {
|
|
req.session.auth.first_factor = false;
|
|
req.session.auth.userid = undefined;
|
|
|
|
new RegistrationHandler(vars.logger).preValidationInit(req as any)
|
|
.catch(function (err: Error) {
|
|
done();
|
|
});
|
|
});
|
|
|
|
it("should fail if email is missing", function (done) {
|
|
req.session.auth.first_factor = false;
|
|
req.session.auth.email = undefined;
|
|
|
|
new RegistrationHandler(vars.logger).preValidationInit(req as any)
|
|
.catch(function (err: Error) {
|
|
done();
|
|
});
|
|
});
|
|
|
|
it("should succeed if first factor passed, userid and email are provided", function (done) {
|
|
new RegistrationHandler(vars.logger).preValidationInit(req as any)
|
|
.then(function (identity: Identity) {
|
|
done();
|
|
});
|
|
});
|
|
}
|
|
});
|