* refactor: 💡 auth-method, account, & managed abilities & routes * refactor: 💡 credential store resources abilities & routes * refactor: 💡 group abilities & routes * refactor: 💡 host-catalog resources abilities & routes * refactor: 💡 role abilities & routes * test: 💍 fix route-info-test * test: 💍 fix host serializer tests * test: 💍 fix create-test for host-sets * refactor: 💡 session recording resources abilities & routes * refactor: 💡 storage bucket abilities & routes * refactor: 💡 target abilities & routes * refactor: 💡 user abilities & routes * refactor: 💡 worker abilities & routes * refactor: 💡 remove ability changes and add comments * Update ui/admin/app/utils/route-info.js Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * test: 💍 add test cases and rename util file * refactor: 💡 remove dup file and update imports ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-11282 * docs: ✏️ update comments & remove console.log ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-11282 * Update ui/admin/app/routes/scopes/scope/auth-methods/auth-method.js Co-authored-by: Dharini Jeeva <dharini@hashicorp.com> --------- Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>
172 lines
5.5 KiB
JavaScript
172 lines
5.5 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import {
|
|
visit,
|
|
fillIn,
|
|
click,
|
|
find,
|
|
findAll,
|
|
currentURL,
|
|
} from '@ember/test-helpers';
|
|
import { setupApplicationTest } from 'ember-qunit';
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
|
import { Response } from 'miragejs';
|
|
import {
|
|
authenticateSession,
|
|
// These are left here intentionally for future reference.
|
|
//currentSession,
|
|
//invalidateSession,
|
|
} from 'ember-simple-auth/test-support';
|
|
|
|
module('Acceptance | workers | create', function (hooks) {
|
|
setupApplicationTest(hooks);
|
|
setupMirage(hooks);
|
|
|
|
let globalScope;
|
|
let workersURL;
|
|
let newWorkerURL;
|
|
let getWorkersCount;
|
|
|
|
hooks.beforeEach(function () {
|
|
globalScope = this.server.create('scope', { id: 'global' });
|
|
|
|
workersURL = `/scopes/global/workers`;
|
|
newWorkerURL = `${workersURL}/new`;
|
|
getWorkersCount = () => this.server.schema.workers.all().length;
|
|
|
|
authenticateSession({});
|
|
});
|
|
|
|
test('can create new workers', async function (assert) {
|
|
assert.expect(1);
|
|
const workersCount = getWorkersCount();
|
|
await visit(newWorkerURL);
|
|
await fillIn('[name="worker_auth_registration_request"]', 'token');
|
|
await click('[type="submit"]');
|
|
assert.strictEqual(getWorkersCount(), workersCount + 1);
|
|
});
|
|
|
|
test('cluster id input field is visible for `hcp` binary', async function (assert) {
|
|
assert.expect(2);
|
|
const featuresService = this.owner.lookup('service:features');
|
|
featuresService.enable('byow-pki-hcp-cluster-id');
|
|
await visit(newWorkerURL);
|
|
const labels = findAll('label.rose-form-label');
|
|
assert.dom(labels[0]).hasText('Boundary Cluster ID');
|
|
assert.dom(labels[2]).doesNotIncludeText('Initial Upstreams');
|
|
});
|
|
|
|
test('initial upstreams input field is visible for `oss` binary', async function (assert) {
|
|
assert.expect(3);
|
|
const featuresService = this.owner.lookup('service:features');
|
|
await visit(newWorkerURL);
|
|
const labels = findAll('label.rose-form-label');
|
|
assert.false(featuresService.isEnabled('byow-pki-hcp-cluster-id'));
|
|
assert.dom(labels[0]).doesNotIncludeText('Boundary Cluster ID');
|
|
assert.dom(labels[2]).hasText('Initial Upstreams');
|
|
});
|
|
|
|
test('download and install step shows correct oss instructions', async function (assert) {
|
|
assert.expect(3);
|
|
const featuresService = this.owner.lookup('service:features');
|
|
await visit(newWorkerURL);
|
|
const createSection = findAll('.worker-create-section');
|
|
assert.false(featuresService.isEnabled('byow-pki-hcp-cluster-id'));
|
|
assert
|
|
.dom(createSection[1])
|
|
.includesText(
|
|
'curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - ;'
|
|
);
|
|
assert
|
|
.dom(createSection[1])
|
|
.doesNotIncludeText(
|
|
'wget -q "$(curl -fsSL "https://api.releases.hashicorp.com/v1/releases/boundary/latest?license_class=enterprise"'
|
|
);
|
|
});
|
|
|
|
test('download and install step shows correct hcp instructions', async function (assert) {
|
|
assert.expect(2);
|
|
const featuresService = this.owner.lookup('service:features');
|
|
featuresService.enable('byow-pki-hcp-cluster-id');
|
|
await visit(newWorkerURL);
|
|
const createSection = findAll('.worker-create-section');
|
|
assert
|
|
.dom(createSection[1])
|
|
.includesText(
|
|
'wget -q "$(curl -fsSL "https://api.releases.hashicorp.com/v1/releases/boundary/latest?license_class=enterprise"'
|
|
);
|
|
assert
|
|
.dom(createSection[1])
|
|
.doesNotIncludeText(
|
|
'curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - ;'
|
|
);
|
|
});
|
|
|
|
test('Users can navigate to new workers route with proper authorization', async function (assert) {
|
|
assert.expect(2);
|
|
await visit(workersURL);
|
|
assert.ok(
|
|
globalScope.authorized_collection_actions.workers.includes(
|
|
'create:worker-led'
|
|
)
|
|
);
|
|
assert.dom(`[href="${newWorkerURL}"]`).isVisible();
|
|
});
|
|
|
|
test('Users cannot navigate to new workers route without proper authorization', async function (assert) {
|
|
assert.expect(2);
|
|
globalScope.authorized_collection_actions.workers = [];
|
|
await visit(workersURL);
|
|
assert.notOk(
|
|
globalScope.authorized_collection_actions.users.includes(
|
|
'create:worker-led'
|
|
)
|
|
);
|
|
assert.dom(`[href="${newWorkerURL}"]`).isNotVisible();
|
|
});
|
|
|
|
test('saving a new user with invalid fields displays error messages', async function (assert) {
|
|
assert.expect(1);
|
|
this.server.post('/workers:create:worker-led', () => {
|
|
return new Response(
|
|
500,
|
|
{},
|
|
{
|
|
status: 500,
|
|
code: 'api_error',
|
|
message: 'rpc error: code = Unknown',
|
|
}
|
|
);
|
|
});
|
|
await visit(newWorkerURL);
|
|
await fillIn('[name="worker_auth_registration_request"]', 'token');
|
|
await click('[type="submit"]');
|
|
assert.strictEqual(
|
|
find('.rose-notification-body').textContent.trim(),
|
|
'rpc error: code = Unknown',
|
|
'Displays primary error message.'
|
|
);
|
|
});
|
|
|
|
test('users cannot directly navigate to new worker route without proper authorization', async function (assert) {
|
|
assert.expect(2);
|
|
globalScope.authorized_collection_actions.workers =
|
|
globalScope.authorized_collection_actions.workers.filter(
|
|
(item) => item !== 'create:worker-led'
|
|
);
|
|
|
|
await visit(newWorkerURL);
|
|
|
|
assert.false(
|
|
globalScope.authorized_collection_actions.workers.includes(
|
|
'create:worker-led'
|
|
)
|
|
);
|
|
assert.strictEqual(currentURL(), workersURL);
|
|
});
|
|
});
|