2019-01-30 22:47:03 +07:00
|
|
|
|
|
|
|
import ChildProcess from 'child_process';
|
2019-02-24 22:42:29 +07:00
|
|
|
import fs from 'fs';
|
2019-01-30 22:47:03 +07:00
|
|
|
|
2019-02-24 20:01:17 +07:00
|
|
|
export default function WithAutheliaRunning(configPath: string, waitTimeout: number = 5000) {
|
2019-01-30 22:47:03 +07:00
|
|
|
before(function() {
|
2019-02-24 20:01:17 +07:00
|
|
|
this.timeout(10000);
|
2019-02-24 05:02:03 +07:00
|
|
|
|
|
|
|
console.log('Spawning Authelia server with configuration %s.', configPath);
|
2019-01-30 22:47:03 +07:00
|
|
|
const authelia = ChildProcess.spawn(
|
|
|
|
'./scripts/authelia-scripts',
|
2019-01-31 04:44:03 +07:00
|
|
|
['serve', '--no-watch', '--config', configPath],
|
2019-01-30 22:47:03 +07:00
|
|
|
{detached: true});
|
2019-02-05 05:23:59 +07:00
|
|
|
|
2019-02-24 22:42:29 +07:00
|
|
|
authelia.on('exit', function(statusCode) {
|
|
|
|
console.log('Server terminated with status ' + statusCode);
|
|
|
|
if (statusCode != 0) {
|
|
|
|
fs.readFile('/tmp/authelia-server.log', function(err, data) {
|
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log(data.toString('utf-8'));
|
|
|
|
})
|
|
|
|
}
|
2019-02-05 05:23:59 +07:00
|
|
|
});
|
2019-01-30 22:47:03 +07:00
|
|
|
this.authelia = authelia;
|
|
|
|
|
|
|
|
const waitPromise = new Promise((resolve, reject) => setTimeout(() => resolve(), waitTimeout));
|
|
|
|
return waitPromise;
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function() {
|
2019-02-24 20:01:17 +07:00
|
|
|
this.timeout(10000);
|
2019-01-30 22:47:03 +07:00
|
|
|
|
2019-02-24 05:02:03 +07:00
|
|
|
console.log('Killing Authelia server.');
|
2019-01-30 22:47:03 +07:00
|
|
|
// Kill the group of processes.
|
|
|
|
process.kill(-this.authelia.pid);
|
2019-02-24 20:01:17 +07:00
|
|
|
|
|
|
|
// Leave 5 seconds for the process to terminate.
|
|
|
|
const waitPromise = new Promise((resolve, reject) => setTimeout(() => resolve(), 5000));
|
|
|
|
return waitPromise;
|
2019-01-30 22:47:03 +07:00
|
|
|
});
|
|
|
|
}
|