From 7c2fd91271346c78b003e8c93313a31e88382444 Mon Sep 17 00:00:00 2001 From: Clement Michaud Date: Tue, 12 Feb 2019 23:57:09 +0100 Subject: [PATCH] Add basic authentication related tests. --- test/suites/complete/index.ts | 2 ++ .../complete/scenarii/BasicAuthentication.ts | 34 +++++++++++++++++++ .../scenarii/SingleFactorAuthentication.ts | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/suites/complete/scenarii/BasicAuthentication.ts diff --git a/test/suites/complete/index.ts b/test/suites/complete/index.ts index 6e0126b1e..46a97e070 100644 --- a/test/suites/complete/index.ts +++ b/test/suites/complete/index.ts @@ -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); }); \ No newline at end of file diff --git a/test/suites/complete/scenarii/BasicAuthentication.ts b/test/suites/complete/scenarii/BasicAuthentication.ts new file mode 100644 index 000000000..941abfa69 --- /dev/null +++ b/test/suites/complete/scenarii/BasicAuthentication.ts @@ -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.'); + } + }); +} \ No newline at end of file diff --git a/test/suites/complete/scenarii/SingleFactorAuthentication.ts b/test/suites/complete/scenarii/SingleFactorAuthentication.ts index 92d4807cc..463bea0bc 100644 --- a/test/suites/complete/scenarii/SingleFactorAuthentication.ts +++ b/test/suites/complete/scenarii/SingleFactorAuthentication.ts @@ -30,5 +30,5 @@ export default function() { // And the user should end up on the second factor page. await VerifyIsSecondFactorStage(this.driver); - }) + }); } \ No newline at end of file