mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
Fix integration and unit tests.
This commit is contained in:
parent
92c83869f0
commit
b3d381bfa7
|
@ -12,6 +12,7 @@ program
|
||||||
.command('test', 'Run Authelia integration tests.')
|
.command('test', 'Run Authelia integration tests.')
|
||||||
.command('unittest', 'Run Authelia integration tests.')
|
.command('unittest', 'Run Authelia integration tests.')
|
||||||
|
|
||||||
|
.command('travis', 'Build and test Authelia on Travis.')
|
||||||
.command('hash-password <password>', 'Hash a password with SSHA512.')
|
.command('hash-password <password>', 'Hash a password with SSHA512.')
|
||||||
.command('build-docker', 'Build Docker image containing production version of Authelia.')
|
.command('build-docker', 'Build Docker image containing production version of Authelia.')
|
||||||
.command('publish-docker', 'Publish Docker image containing production version of Authelia to Dockerhub.')
|
.command('publish-docker', 'Publish Docker image containing production version of Authelia to Dockerhub.')
|
||||||
|
|
|
@ -114,7 +114,7 @@ describe("routes/firstfactor/post", function () {
|
||||||
Assert.equal(res.status.getCall(0).args[0], 200);
|
Assert.equal(res.status.getCall(0).args[0], 200);
|
||||||
Assert.equal(mocks.regulator.markStub.getCall(0).args[0], "username");
|
Assert.equal(mocks.regulator.markStub.getCall(0).args[0], "username");
|
||||||
Assert.deepEqual(res.send.getCall(0).args[0], {
|
Assert.deepEqual(res.send.getCall(0).args[0], {
|
||||||
error: "Operation failed."
|
error: "Authentication failed. Please check your credentials."
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -126,7 +126,7 @@ describe("routes/firstfactor/post", function () {
|
||||||
.then(function () {
|
.then(function () {
|
||||||
Assert.equal(res.status.getCall(0).args[0], 200);
|
Assert.equal(res.status.getCall(0).args[0], 200);
|
||||||
Assert.deepEqual(res.send.getCall(0).args[0], {
|
Assert.deepEqual(res.send.getCall(0).args[0], {
|
||||||
error: "Operation failed."
|
error: "Authentication failed. Please check your credentials."
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -96,8 +96,8 @@ export default function (vars: ServerVariables) {
|
||||||
})
|
})
|
||||||
.catch(AuthenticationError, function (err: Error) {
|
.catch(AuthenticationError, function (err: Error) {
|
||||||
vars.regulator.mark(username, false);
|
vars.regulator.mark(username, false);
|
||||||
return ErrorReplies.replyWithError200(req, res, vars.logger, UserMessages.OPERATION_FAILED)(err);
|
return ErrorReplies.replyWithError200(req, res, vars.logger, UserMessages.AUTHENTICATION_FAILED)(err);
|
||||||
})
|
})
|
||||||
.catch(ErrorReplies.replyWithError200(req, res, vars.logger, UserMessages.OPERATION_FAILED));
|
.catch(ErrorReplies.replyWithError200(req, res, vars.logger, UserMessages.AUTHENTICATION_FAILED));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ describe("routes/secondfactor/totp/sign/post", function () {
|
||||||
Assert.notEqual(authSession.authentication_level, Level.TWO_FACTOR);
|
Assert.notEqual(authSession.authentication_level, Level.TWO_FACTOR);
|
||||||
Assert.equal(res.status.getCall(0).args[0], 200);
|
Assert.equal(res.status.getCall(0).args[0], 200);
|
||||||
Assert.deepEqual(res.send.getCall(0).args[0], {
|
Assert.deepEqual(res.send.getCall(0).args[0], {
|
||||||
error: "Operation failed."
|
error: "Authentication failed. Have you already registered your secret?"
|
||||||
});
|
});
|
||||||
return BluebirdPromise.resolve();
|
return BluebirdPromise.resolve();
|
||||||
});
|
});
|
||||||
|
|
|
@ -34,7 +34,7 @@ export default function (vars: ServerVariables) {
|
||||||
return Bluebird.resolve();
|
return Bluebird.resolve();
|
||||||
})
|
})
|
||||||
.catch(ErrorReplies.replyWithError200(req, res, vars.logger,
|
.catch(ErrorReplies.replyWithError200(req, res, vars.logger,
|
||||||
UserMessages.OPERATION_FAILED));
|
UserMessages.AUTHENTICATION_TOTP_FAILED));
|
||||||
}
|
}
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ export default async function(driver: WebDriver, header: string, expectedValue:
|
||||||
const text = await el.getText();
|
const text = await el.getText();
|
||||||
|
|
||||||
const expectedLine = Util.format("\"%s\": \"%s\"", header, expectedValue);
|
const expectedLine = Util.format("\"%s\": \"%s\"", header, expectedValue);
|
||||||
|
|
||||||
if (text.indexOf(expectedLine) < 0) {
|
if (text.indexOf(expectedLine) < 0) {
|
||||||
throw new Error("Header not found.");
|
throw new Error("Header not found.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { WebDriver } from "selenium-webdriver";
|
import { WebDriver } from "selenium-webdriver";
|
||||||
import LoginAndRegisterTotp from "../LoginAndRegisterTotp";
|
import LoginAndRegisterTotp from "../LoginAndRegisterTotp";
|
||||||
import FullLogin from "../FullLogin";
|
import FullLogin from "../FullLogin";
|
||||||
|
import VerifyUrlIs from "../assertions/VerifyUrlIs";
|
||||||
|
|
||||||
export default async function(
|
export default async function(
|
||||||
driver: WebDriver,
|
driver: WebDriver,
|
||||||
|
@ -11,5 +12,6 @@ export default async function(
|
||||||
|
|
||||||
const secret = await LoginAndRegisterTotp(driver, username, password, email);
|
const secret = await LoginAndRegisterTotp(driver, username, password, email);
|
||||||
await FullLogin(driver, username, secret, targetUrl);
|
await FullLogin(driver, username, secret, targetUrl);
|
||||||
|
await VerifyUrlIs(driver, targetUrl);
|
||||||
return secret;
|
return secret;
|
||||||
};
|
};
|
|
@ -1,7 +1,4 @@
|
||||||
import WithAutheliaRunning from "./WithAutheliaRunning";
|
import WithAutheliaRunning from "./WithAutheliaRunning";
|
||||||
import WithDriver from "./WithDriver";
|
|
||||||
|
|
||||||
let running = false;
|
|
||||||
|
|
||||||
interface AutheliaSuiteType {
|
interface AutheliaSuiteType {
|
||||||
(description: string, configPath: string, cb: (this: Mocha.ISuiteCallbackContext) => void): Mocha.ISuite;
|
(description: string, configPath: string, cb: (this: Mocha.ISuiteCallbackContext) => void): Mocha.ISuite;
|
||||||
|
@ -11,13 +8,11 @@ interface AutheliaSuiteType {
|
||||||
function AutheliaSuiteBase(description: string, configPath: string,
|
function AutheliaSuiteBase(description: string, configPath: string,
|
||||||
cb: (this: Mocha.ISuiteCallbackContext) => void,
|
cb: (this: Mocha.ISuiteCallbackContext) => void,
|
||||||
context: (description: string, ctx: (this: Mocha.ISuiteCallbackContext) => void) => Mocha.ISuite) {
|
context: (description: string, ctx: (this: Mocha.ISuiteCallbackContext) => void) => Mocha.ISuite) {
|
||||||
if (!running && process.env['WITH_SERVER'] == 'y') {
|
|
||||||
console.log('Spawning Authelia server with configuration %s.', configPath);
|
|
||||||
WithAutheliaRunning(configPath);
|
|
||||||
running = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return context('Suite: ' + description, function(this: Mocha.ISuiteCallbackContext) {
|
return context('Suite: ' + description, function(this: Mocha.ISuiteCallbackContext) {
|
||||||
|
if (process.env['WITH_SERVER'] == 'y') {
|
||||||
|
WithAutheliaRunning(configPath);
|
||||||
|
}
|
||||||
|
|
||||||
cb.call(this);
|
cb.call(this);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import ChildProcess from 'child_process';
|
||||||
export default function WithAutheliaRunning(configPath: string, waitTimeout: number = 3000) {
|
export default function WithAutheliaRunning(configPath: string, waitTimeout: number = 3000) {
|
||||||
before(function() {
|
before(function() {
|
||||||
this.timeout(5000);
|
this.timeout(5000);
|
||||||
|
|
||||||
|
console.log('Spawning Authelia server with configuration %s.', configPath);
|
||||||
const authelia = ChildProcess.spawn(
|
const authelia = ChildProcess.spawn(
|
||||||
'./scripts/authelia-scripts',
|
'./scripts/authelia-scripts',
|
||||||
['serve', '--no-watch', '--config', configPath],
|
['serve', '--no-watch', '--config', configPath],
|
||||||
|
@ -21,6 +23,7 @@ export default function WithAutheliaRunning(configPath: string, waitTimeout: num
|
||||||
after(function() {
|
after(function() {
|
||||||
this.timeout(1000);
|
this.timeout(1000);
|
||||||
|
|
||||||
|
console.log('Killing Authelia server.');
|
||||||
// Kill the group of processes.
|
// Kill the group of processes.
|
||||||
process.kill(-this.authelia.pid);
|
process.kill(-this.authelia.pid);
|
||||||
});
|
});
|
||||||
|
|
|
@ -32,8 +32,7 @@ export default function() {
|
||||||
await GET_Expect502('https://login.example.com:8080/api/state');
|
await GET_Expect502('https://login.example.com:8080/api/state');
|
||||||
await this.driver.sleep(1000);
|
await this.driver.sleep(1000);
|
||||||
ChildProcess.execSync('rm .authelia-interrupt');
|
ChildProcess.execSync('rm .authelia-interrupt');
|
||||||
await this.driver.sleep(1000);
|
await this.driver.sleep(4000);
|
||||||
|
|
||||||
|
|
||||||
await VisitPageAndWaitUrlIs(this.driver, 'https://admin.example.com:8080/secret.html');
|
await VisitPageAndWaitUrlIs(this.driver, 'https://admin.example.com:8080/secret.html');
|
||||||
await VerifySecretObserved(this.driver);
|
await VerifySecretObserved(this.driver);
|
||||||
|
@ -63,7 +62,7 @@ export default function() {
|
||||||
await GET_Expect502('https://login.example.com:8080/api/state');
|
await GET_Expect502('https://login.example.com:8080/api/state');
|
||||||
await this.driver.sleep(1000);
|
await this.driver.sleep(1000);
|
||||||
ChildProcess.execSync('rm .authelia-interrupt');
|
ChildProcess.execSync('rm .authelia-interrupt');
|
||||||
await this.driver.sleep(1000);
|
await this.driver.sleep(4000);
|
||||||
|
|
||||||
// The user can re-authenticate with the secret.
|
// The user can re-authenticate with the secret.
|
||||||
await FullLogin(this.driver, 'john', this.secret, 'https://admin.example.com:8080/secret.html')
|
await FullLogin(this.driver, 'john', this.secret, 'https://admin.example.com:8080/secret.html')
|
||||||
|
|
|
@ -3,9 +3,10 @@ import { StartDriver, StopDriver } from "../../../helpers/context/WithDriver";
|
||||||
import RegisterAndLoginWith2FA from "../../../helpers/behaviors/RegisterAndLoginTwoFactor";
|
import RegisterAndLoginWith2FA from "../../../helpers/behaviors/RegisterAndLoginTwoFactor";
|
||||||
import VerifyForwardedHeaderIs from "../../../helpers/assertions/VerifyForwardedHeaderIs";
|
import VerifyForwardedHeaderIs from "../../../helpers/assertions/VerifyForwardedHeaderIs";
|
||||||
import LoginOneFactor from "../../../helpers/behaviors/LoginOneFactor";
|
import LoginOneFactor from "../../../helpers/behaviors/LoginOneFactor";
|
||||||
|
import VerifyUrlIs from "../../../helpers/assertions/VerifyUrlIs";
|
||||||
|
|
||||||
export default function() {
|
export default function() {
|
||||||
describe.only("Custom-Forwarded-User and Custom-Forwarded-Groups are correctly forwarded to protected backend", function() {
|
describe("Custom-Forwarded-User and Custom-Forwarded-Groups are correctly forwarded to protected backend", function() {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
|
|
||||||
describe("With single factor", function() {
|
describe("With single factor", function() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user