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.
77 lines
2.4 KiB
TypeScript
77 lines
2.4 KiB
TypeScript
|
|
import sinon = require("sinon");
|
|
import BluebirdPromise = require("bluebird");
|
|
import assert = require("assert");
|
|
import U2FSignRequestGet = require("../../../../../src/lib/routes/secondfactor/u2f/sign_request/get");
|
|
import AuthenticationSessionHandler = require("../../../../../src/lib/AuthenticationSession");
|
|
import { AuthenticationSession } from "../../../../../types/AuthenticationSession";
|
|
import ExpressMock = require("../../../../mocks/express");
|
|
import { UserDataStoreStub } from "../../../../mocks/storage/UserDataStoreStub";
|
|
import U2FMock = require("../../../../mocks/u2f");
|
|
import U2f = require("u2f");
|
|
import { ServerVariablesMock, ServerVariablesMockBuilder } from "../../../../mocks/ServerVariablesMockBuilder";
|
|
import { ServerVariables } from "../../../../../src/lib/ServerVariables";
|
|
|
|
import { SignMessage } from "../../../../../../shared/SignMessage";
|
|
|
|
describe("test u2f routes: sign_request", function () {
|
|
let req: ExpressMock.RequestMock;
|
|
let res: ExpressMock.ResponseMock;
|
|
let mocks: ServerVariablesMock;
|
|
let vars: ServerVariables;
|
|
|
|
beforeEach(function () {
|
|
req = ExpressMock.RequestMock();
|
|
req.app = {};
|
|
req.session = {
|
|
auth: {
|
|
userid: "user",
|
|
first_factor: true,
|
|
second_factor: false,
|
|
identity_check: {
|
|
challenge: "u2f-register",
|
|
userid: "user"
|
|
}
|
|
}
|
|
};
|
|
req.headers = {};
|
|
req.headers.host = "localhost";
|
|
|
|
const s = ServerVariablesMockBuilder.build();
|
|
mocks = s.mocks;
|
|
vars = s.variables;
|
|
|
|
const options = {
|
|
inMemoryOnly: true
|
|
};
|
|
|
|
res = ExpressMock.ResponseMock();
|
|
res.send = sinon.spy();
|
|
res.json = sinon.spy();
|
|
res.status = sinon.spy();
|
|
});
|
|
|
|
it("should send back the sign request and save it in the session", function () {
|
|
const expectedRequest: U2f.RegistrationResult = {
|
|
keyHandle: "keyHandle",
|
|
publicKey: "publicKey",
|
|
certificate: "Certificate",
|
|
successful: true
|
|
};
|
|
mocks.u2f.requestStub.returns(expectedRequest);
|
|
mocks.userDataStore.retrieveU2FRegistrationStub.returns(BluebirdPromise.resolve({
|
|
registration: {
|
|
publicKey: "PUBKEY",
|
|
keyHandle: "KeyHandle"
|
|
}
|
|
}));
|
|
|
|
return U2FSignRequestGet.default(vars)(req as any, res as any)
|
|
.then(function () {
|
|
assert.deepEqual(expectedRequest, req.session.auth.sign_request);
|
|
assert.deepEqual(expectedRequest, res.json.getCall(0).args[0].request);
|
|
});
|
|
});
|
|
});
|
|
|