Add basic authentication related tests.

pull/330/head
Clement Michaud 2019-02-12 23:57:09 +01:00
parent 595ee97182
commit 7c2fd91271
3 changed files with 37 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import EnforceInternalRedirectionsOnly from "./scenarii/EnforceInternalRedirecti
import AccessControl from "./scenarii/AccessControl";
import CustomHeadersForwarded from "./scenarii/CustomHeadersForwarded";
import SingleFactorAuthentication from "./scenarii/SingleFactorAuthentication";
import BasicAuthentication from "./scenarii/BasicAuthentication";
AutheliaSuite('Complete configuration', __dirname + '/config.yml', function() {
this.timeout(10000);
@ -14,4 +15,5 @@ AutheliaSuite('Complete configuration', __dirname + '/config.yml', function() {
describe('Mongo broken connection recovery', MongoConnectionRecovery);
describe('Enforce internal redirections only', EnforceInternalRedirectionsOnly);
describe('Single factor authentication', SingleFactorAuthentication);
describe('Basic authentication', BasicAuthentication);
});

View File

@ -0,0 +1,34 @@
import Request from 'request-promise';
async function GetSecret(username: string, password: string) {
return await Request('https://single_factor.example.com:8080/secret.html', {
auth: {
username,
password
},
rejectUnauthorized: false,
});
}
export default function() {
it("should retrieve secret when Authorization header is provided", async function() {
const res = await GetSecret('john', 'password');
if (res.indexOf('This is a very important secret!') < 0) {
throw new Error('Cannot access secret.');
}
});
it("should not retrieve secret when providing bad password", async function() {
const res = await GetSecret('john', 'bad-password');
if (res.indexOf('This is a very important secret!') >= 0) {
throw new Error('Cannot access secret.');
}
});
it("should not retrieve secret when authenticating with unexisting user", async function() {
const res = await GetSecret('dontexist', 'password');
if (res.indexOf('This is a very important secret!') >= 0) {
throw new Error('Cannot access secret.');
}
});
}

View File

@ -30,5 +30,5 @@ export default function() {
// And the user should end up on the second factor page.
await VerifyIsSecondFactorStage(this.driver);
})
});
}