open-nomad/ui/tests/acceptance/proxy-test.js

56 lines
1.8 KiB
JavaScript
Raw Normal View History

/* eslint-disable ember-a11y-testing/a11y-audit-called */ // Tests for non-UI behaviour.
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import Jobs from 'nomad-ui/tests/pages/jobs/list';
let managementToken;
2021-12-28 14:45:20 +00:00
module('Acceptance | reverse proxy', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
2021-12-28 14:45:20 +00:00
hooks.beforeEach(function () {
window.localStorage.clear();
window.sessionStorage.clear();
server.create('agent');
managementToken = server.create('token');
// Simulate a reverse proxy injecting X-Nomad-Token header for all requests
this._originalXMLHttpRequestSend = XMLHttpRequest.prototype.send;
2021-12-28 14:45:20 +00:00
(function (send) {
XMLHttpRequest.prototype.send = function (data) {
this.setRequestHeader('X-Nomad-Token', managementToken.secretId);
send.call(this, data);
};
})(this._originalXMLHttpRequestSend);
});
2021-12-28 14:45:20 +00:00
hooks.afterEach(function () {
XMLHttpRequest.prototype.send = this._originalXMLHttpRequestSend;
});
2021-12-28 14:45:20 +00:00
test('when token is inserted by a reverse proxy, the UI is adjusted', async function (assert) {
// when token is inserted by reserve proxy, the token is reverse proxy
const { secretId } = managementToken;
await Jobs.visit();
2021-12-28 16:08:12 +00:00
assert.equal(
window.localStorage.nomadTokenSecret,
null,
'No token secret set'
);
// Make sure that server received the header
assert.ok(
server.pretender.handledRequests
.mapBy('requestHeaders')
2021-12-28 14:45:20 +00:00
.every((headers) => headers['X-Nomad-Token'] === secretId),
'The token header is always present'
);
assert.notOk(Jobs.runJobButton.isDisabled, 'Run job button is enabled');
});
});