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.
118 lines
4.4 KiB
TypeScript
118 lines
4.4 KiB
TypeScript
|
|
import U2FValidator = require("../../src/lib/secondfactor/U2FValidator");
|
|
import { INotifier } from "../../src/lib/INotifier";
|
|
import JQueryMock = require("../mocks/jquery");
|
|
import U2FApiMock = require("../mocks/u2f-api");
|
|
import { SignMessage } from "../../../shared/SignMessage";
|
|
import BluebirdPromise = require("bluebird");
|
|
import Assert = require("assert");
|
|
import { NotifierStub } from "../mocks/NotifierStub";
|
|
|
|
describe("test U2F validation", function () {
|
|
let notifier: INotifier;
|
|
|
|
beforeEach(function() {
|
|
notifier = new NotifierStub();
|
|
});
|
|
|
|
it("should validate the U2F device", () => {
|
|
const signatureRequest: SignMessage = {
|
|
keyHandle: "keyhandle",
|
|
request: {
|
|
version: "U2F_V2",
|
|
appId: "https://example.com",
|
|
challenge: "challenge"
|
|
}
|
|
};
|
|
const u2fClient = U2FApiMock.U2FApiMock();
|
|
u2fClient.sign.returns(BluebirdPromise.resolve());
|
|
|
|
const getPromise = JQueryMock.JQueryDeferredMock();
|
|
getPromise.done.yields(signatureRequest);
|
|
getPromise.done.returns(getPromise);
|
|
|
|
const postPromise = JQueryMock.JQueryDeferredMock();
|
|
postPromise.done.yields({ redirect: "https://home.test.url" });
|
|
postPromise.done.returns(postPromise);
|
|
|
|
const jqueryMock = JQueryMock.JQueryMock();
|
|
jqueryMock.jquery.get.returns(getPromise);
|
|
jqueryMock.jquery.ajax.returns(postPromise);
|
|
|
|
return U2FValidator.validate(jqueryMock.jquery as any, notifier, u2fClient as any);
|
|
});
|
|
|
|
it("should fail during initial authentication request", () => {
|
|
const u2fClient = U2FApiMock.U2FApiMock();
|
|
|
|
const getPromise = JQueryMock.JQueryDeferredMock();
|
|
getPromise.done.returns(getPromise);
|
|
getPromise.fail.yields(undefined, "Error while issuing authentication request");
|
|
|
|
const jqueryMock = JQueryMock.JQueryMock();
|
|
jqueryMock.jquery.get.returns(getPromise);
|
|
|
|
return U2FValidator.validate(jqueryMock.jquery as any, notifier, u2fClient as any)
|
|
.catch(function(err: Error) {
|
|
Assert.equal("Error while issuing authentication request", err.message);
|
|
return BluebirdPromise.resolve();
|
|
});
|
|
});
|
|
|
|
it("should fail during device signature", () => {
|
|
const signatureRequest: SignMessage = {
|
|
keyHandle: "keyhandle",
|
|
request: {
|
|
version: "U2F_V2",
|
|
appId: "https://example.com",
|
|
challenge: "challenge"
|
|
}
|
|
};
|
|
const u2fClient = U2FApiMock.U2FApiMock();
|
|
u2fClient.sign.returns(BluebirdPromise.reject(new Error("Device unable to sign")));
|
|
|
|
const getPromise = JQueryMock.JQueryDeferredMock();
|
|
getPromise.done.yields(signatureRequest);
|
|
getPromise.done.returns(getPromise);
|
|
|
|
const jqueryMock = JQueryMock.JQueryMock();
|
|
jqueryMock.jquery.get.returns(getPromise);
|
|
|
|
return U2FValidator.validate(jqueryMock.jquery as any, notifier, u2fClient as any)
|
|
.catch(function(err: Error) {
|
|
Assert.equal("Device unable to sign", err.message);
|
|
return BluebirdPromise.resolve();
|
|
});
|
|
});
|
|
|
|
it("should fail at the end of the authentication request", () => {
|
|
const signatureRequest: SignMessage = {
|
|
keyHandle: "keyhandle",
|
|
request: {
|
|
version: "U2F_V2",
|
|
appId: "https://example.com",
|
|
challenge: "challenge"
|
|
}
|
|
};
|
|
const u2fClient = U2FApiMock.U2FApiMock();
|
|
u2fClient.sign.returns(BluebirdPromise.resolve());
|
|
|
|
const getPromise = JQueryMock.JQueryDeferredMock();
|
|
getPromise.done.yields(signatureRequest);
|
|
getPromise.done.returns(getPromise);
|
|
|
|
const postPromise = JQueryMock.JQueryDeferredMock();
|
|
postPromise.fail.yields(undefined, "Error while finishing authentication");
|
|
postPromise.done.returns(postPromise);
|
|
|
|
const jqueryMock = JQueryMock.JQueryMock();
|
|
jqueryMock.jquery.get.returns(getPromise);
|
|
jqueryMock.jquery.ajax.returns(postPromise);
|
|
|
|
return U2FValidator.validate(jqueryMock.jquery as any, notifier, u2fClient as any)
|
|
.catch(function(err: Error) {
|
|
Assert.equal("Error while finishing authentication", err.message);
|
|
return BluebirdPromise.resolve();
|
|
});
|
|
});
|
|
}); |