Fix integration and unit tests.

This commit is contained in:
Clement Michaud 2019-02-23 23:02:03 +01:00
parent 92c83869f0
commit b3d381bfa7
12 changed files with 20 additions and 20 deletions

View File

@ -12,6 +12,7 @@ program
.command('test', '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('build-docker', 'Build Docker image containing production version of Authelia.')
.command('publish-docker', 'Publish Docker image containing production version of Authelia to Dockerhub.')

View File

@ -114,7 +114,7 @@ describe("routes/firstfactor/post", function () {
Assert.equal(res.status.getCall(0).args[0], 200);
Assert.equal(mocks.regulator.markStub.getCall(0).args[0], "username");
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 () {
Assert.equal(res.status.getCall(0).args[0], 200);
Assert.deepEqual(res.send.getCall(0).args[0], {
error: "Operation failed."
error: "Authentication failed. Please check your credentials."
});
});
});

View File

@ -96,8 +96,8 @@ export default function (vars: ServerVariables) {
})
.catch(AuthenticationError, function (err: Error) {
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));
};
}

View File

@ -67,7 +67,7 @@ describe("routes/secondfactor/totp/sign/post", function () {
Assert.notEqual(authSession.authentication_level, Level.TWO_FACTOR);
Assert.equal(res.status.getCall(0).args[0], 200);
Assert.deepEqual(res.send.getCall(0).args[0], {
error: "Operation failed."
error: "Authentication failed. Have you already registered your secret?"
});
return BluebirdPromise.resolve();
});

View File

@ -34,7 +34,7 @@ export default function (vars: ServerVariables) {
return Bluebird.resolve();
})
.catch(ErrorReplies.replyWithError200(req, res, vars.logger,
UserMessages.OPERATION_FAILED));
UserMessages.AUTHENTICATION_TOTP_FAILED));
}
return handler;
}

View File

@ -7,7 +7,6 @@ export default async function(driver: WebDriver, header: string, expectedValue:
const text = await el.getText();
const expectedLine = Util.format("\"%s\": \"%s\"", header, expectedValue);
if (text.indexOf(expectedLine) < 0) {
throw new Error("Header not found.");
}

View File

@ -1,6 +1,7 @@
import { WebDriver } from "selenium-webdriver";
import LoginAndRegisterTotp from "../LoginAndRegisterTotp";
import FullLogin from "../FullLogin";
import VerifyUrlIs from "../assertions/VerifyUrlIs";
export default async function(
driver: WebDriver,
@ -11,5 +12,6 @@ export default async function(
const secret = await LoginAndRegisterTotp(driver, username, password, email);
await FullLogin(driver, username, secret, targetUrl);
await VerifyUrlIs(driver, targetUrl);
return secret;
};

View File

@ -1,7 +1,4 @@
import WithAutheliaRunning from "./WithAutheliaRunning";
import WithDriver from "./WithDriver";
let running = false;
interface AutheliaSuiteType {
(description: string, configPath: string, cb: (this: Mocha.ISuiteCallbackContext) => void): Mocha.ISuite;
@ -11,13 +8,11 @@ interface AutheliaSuiteType {
function AutheliaSuiteBase(description: string, configPath: string,
cb: (this: Mocha.ISuiteCallbackContext) => void,
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) {
if (process.env['WITH_SERVER'] == 'y') {
WithAutheliaRunning(configPath);
}
cb.call(this);
});
}

View File

@ -4,6 +4,8 @@ import ChildProcess from 'child_process';
export default function WithAutheliaRunning(configPath: string, waitTimeout: number = 3000) {
before(function() {
this.timeout(5000);
console.log('Spawning Authelia server with configuration %s.', configPath);
const authelia = ChildProcess.spawn(
'./scripts/authelia-scripts',
['serve', '--no-watch', '--config', configPath],
@ -21,6 +23,7 @@ export default function WithAutheliaRunning(configPath: string, waitTimeout: num
after(function() {
this.timeout(1000);
console.log('Killing Authelia server.');
// Kill the group of processes.
process.kill(-this.authelia.pid);
});

View File

@ -32,8 +32,7 @@ export default function() {
await GET_Expect502('https://login.example.com:8080/api/state');
await this.driver.sleep(1000);
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 VerifySecretObserved(this.driver);
@ -63,7 +62,7 @@ export default function() {
await GET_Expect502('https://login.example.com:8080/api/state');
await this.driver.sleep(1000);
ChildProcess.execSync('rm .authelia-interrupt');
await this.driver.sleep(1000);
await this.driver.sleep(4000);
// The user can re-authenticate with the secret.
await FullLogin(this.driver, 'john', this.secret, 'https://admin.example.com:8080/secret.html')

View File

@ -3,9 +3,10 @@ import { StartDriver, StopDriver } from "../../../helpers/context/WithDriver";
import RegisterAndLoginWith2FA from "../../../helpers/behaviors/RegisterAndLoginTwoFactor";
import VerifyForwardedHeaderIs from "../../../helpers/assertions/VerifyForwardedHeaderIs";
import LoginOneFactor from "../../../helpers/behaviors/LoginOneFactor";
import VerifyUrlIs from "../../../helpers/assertions/VerifyUrlIs";
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);
describe("With single factor", function() {