diff --git a/integration-tests/configs/trustedHeader/config.yaml b/integration-tests/configs/trustedHeader/config.yaml new file mode 100644 index 0000000..27280ae --- /dev/null +++ b/integration-tests/configs/trustedHeader/config.yaml @@ -0,0 +1,3 @@ +logLevel: DEBUG + +authHttpHeaderUsername: "X-User" diff --git a/integration-tests/runner.mjs b/integration-tests/runner.mjs index d1de479..c379b4d 100644 --- a/integration-tests/runner.mjs +++ b/integration-tests/runner.mjs @@ -78,8 +78,14 @@ class OliveTinTestRunnerStartLocalProcess extends OliveTinTestRunner { } async stop () { - await this.ot.kill() - console.log(" OliveTin local process killed") + if ((await this.ot.exitCode) != null) { + console.log(" OliveTin local process tried stop(), but it already exited with code", this.ot.exitCode) + } else { + await this.ot.kill() + console.log(" OliveTin local process killed") + } + + await new Promise((res) => setTimeout(res, 100)) } } diff --git a/integration-tests/test/general.mjs b/integration-tests/test/general.mjs index 46093c3..b547e60 100644 --- a/integration-tests/test/general.mjs +++ b/integration-tests/test/general.mjs @@ -2,7 +2,7 @@ import { describe, it, before, after } from 'mocha' import { expect } from 'chai' import { By, until, Condition } from 'selenium-webdriver' //import * as waitOn from 'wait-on' -import { getRootAndWait } from '../lib/elements.js' +import { getRootAndWait, getActionButtons } from '../lib/elements.js' describe('config: general', function () { before(async function () { @@ -39,7 +39,7 @@ describe('config: general', function () { it('Default buttons are rendered', async function() { await getRootAndWait() - const buttons = await webdriver.findElement(By.id('root-group')).findElements(By.tagName('button')) + const buttons = await getActionButtons(webdriver) expect(buttons).to.have.length(8) }) @@ -69,7 +69,7 @@ describe('config: general', function () { }) it('Start date action (passive)', async function() { - await webdriver.get(runner.baseUrl()) + await getRootAndWait() const buttons = await webdriver.findElements(By.css('[title="date-passive"]')) diff --git a/integration-tests/test/trustedHeader.js b/integration-tests/test/trustedHeader.js new file mode 100644 index 0000000..e6d529c --- /dev/null +++ b/integration-tests/test/trustedHeader.js @@ -0,0 +1,32 @@ +import { expect } from 'chai' + +describe('config: trustedHeader', function () { + before(async function () { + await runner.start('trustedHeader') + }) + + after(async () => { + await runner.stop() + }) + + it('req with X-User', async () => { + const req = await fetch(runner.baseUrl() + '/api/WhoAmI', { + headers: { + "X-User": "fred", + } + }) + + if (!req.ok) { + console.log(req) + } + + expect(req.ok, 'WhoAmI Request is ' + req.status).to.be.true + + const json = await req.json() + + expect(json).to.not.be.null + expect(json).to.have.own.property('authenticatedUser') + + expect(json['authenticatedUser']).to.be.equal('fred') + }) +})