2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2020-06-16 05:47:05 +00:00
|
|
|
import { currentURL } from '@ember/test-helpers';
|
|
|
|
import { run } from '@ember/runloop';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
|
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
2020-07-28 17:59:14 +00:00
|
|
|
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
|
2020-06-16 05:47:05 +00:00
|
|
|
import ServerMonitor from 'nomad-ui/tests/pages/servers/monitor';
|
2020-12-10 17:51:22 +00:00
|
|
|
import Layout from 'nomad-ui/tests/pages/layout';
|
2020-06-16 05:47:05 +00:00
|
|
|
|
|
|
|
let agent;
|
|
|
|
let managementToken;
|
|
|
|
let clientToken;
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Acceptance | server monitor', function (hooks) {
|
2020-06-16 05:47:05 +00:00
|
|
|
setupApplicationTest(hooks);
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2020-06-16 05:47:05 +00:00
|
|
|
agent = server.create('agent');
|
|
|
|
|
|
|
|
managementToken = server.create('token');
|
|
|
|
clientToken = server.create('token');
|
|
|
|
|
|
|
|
window.localStorage.nomadTokenSecret = managementToken.secretId;
|
|
|
|
|
|
|
|
run.later(run, run.cancelTimers, 500);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it passes an accessibility audit', async function (assert) {
|
2021-12-28 19:30:38 +00:00
|
|
|
assert.expect(1);
|
|
|
|
|
2020-07-28 17:59:14 +00:00
|
|
|
await ServerMonitor.visit({ name: agent.name });
|
2020-08-25 15:56:02 +00:00
|
|
|
await a11yAudit(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('/servers/:id/monitor should have a breadcrumb trail linking back to servers', async function (assert) {
|
2020-06-16 05:47:05 +00:00
|
|
|
await ServerMonitor.visit({ name: agent.name });
|
2021-12-15 16:56:26 +00:00
|
|
|
assert.equal(
|
|
|
|
Layout.breadcrumbFor('servers.index').text,
|
|
|
|
'Servers',
|
|
|
|
'The page should read the breadcrumb Servers'
|
|
|
|
);
|
2022-01-20 15:39:02 +00:00
|
|
|
assert.equal(
|
|
|
|
Layout.breadcrumbFor('servers.server').text,
|
|
|
|
`Server ${agent.name}`
|
|
|
|
);
|
2020-06-16 05:47:05 +00:00
|
|
|
|
2020-12-10 17:51:22 +00:00
|
|
|
await Layout.breadcrumbFor('servers.index').visit();
|
2020-06-16 05:47:05 +00:00
|
|
|
assert.equal(currentURL(), '/servers');
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the monitor page immediately streams agent monitor output at the info level', async function (assert) {
|
2020-06-16 05:47:05 +00:00
|
|
|
await ServerMonitor.visit({ name: agent.name });
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
const logRequest = server.pretender.handledRequests.find((req) =>
|
2020-06-16 05:47:05 +00:00
|
|
|
req.url.startsWith('/v1/agent/monitor')
|
|
|
|
);
|
|
|
|
assert.ok(ServerMonitor.logsArePresent);
|
|
|
|
assert.ok(logRequest);
|
|
|
|
assert.ok(logRequest.url.includes('log_level=info'));
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('switching the log level persists the new log level as a query param', async function (assert) {
|
2020-06-16 05:47:05 +00:00
|
|
|
await ServerMonitor.visit({ name: agent.name });
|
|
|
|
await ServerMonitor.selectLogLevel('Debug');
|
|
|
|
assert.equal(currentURL(), `/servers/${agent.name}/monitor?level=debug`);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when the current access token does not include the agent:read rule, a descriptive error message is shown', async function (assert) {
|
2020-06-16 05:47:05 +00:00
|
|
|
window.localStorage.nomadTokenSecret = clientToken.secretId;
|
|
|
|
|
|
|
|
await ServerMonitor.visit({ name: agent.name });
|
|
|
|
assert.notOk(ServerMonitor.logsArePresent);
|
|
|
|
assert.ok(ServerMonitor.error.isShown);
|
|
|
|
assert.equal(ServerMonitor.error.title, 'Not Authorized');
|
|
|
|
assert.ok(ServerMonitor.error.message.includes('agent:read'));
|
|
|
|
|
|
|
|
await ServerMonitor.error.seekHelp();
|
|
|
|
assert.equal(currentURL(), '/settings/tokens');
|
|
|
|
});
|
|
|
|
});
|