2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-01 09:39:41 -06:00
|
|
|
*/
|
|
|
|
|
|
2021-09-01 19:38:48 -07:00
|
|
|
import { module, test } from 'qunit';
|
2024-12-16 16:31:07 -06:00
|
|
|
import { visit } from '@ember/test-helpers';
|
2024-12-02 12:51:24 -06:00
|
|
|
import { setupApplicationTest } from 'admin/tests/helpers';
|
2021-09-01 19:38:48 -07:00
|
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
2024-11-22 11:27:53 -08:00
|
|
|
import { authenticateSession } from 'ember-simple-auth/test-support';
|
2024-12-16 16:31:07 -06:00
|
|
|
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
2021-09-01 19:38:48 -07:00
|
|
|
|
|
|
|
|
module('Acceptance | credential-libraries | list', function (hooks) {
|
|
|
|
|
setupApplicationTest(hooks);
|
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
|
|
|
|
|
const instances = {
|
|
|
|
|
scopes: {
|
|
|
|
|
global: null,
|
|
|
|
|
org: null,
|
|
|
|
|
project: null,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const urls = {
|
|
|
|
|
credentialStores: null,
|
|
|
|
|
credentialStore: null,
|
|
|
|
|
credentialLibrary: null,
|
|
|
|
|
credentialLibraries: null,
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-03 10:27:27 -08:00
|
|
|
hooks.beforeEach(async function () {
|
2021-09-01 19:38:48 -07:00
|
|
|
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
|
|
|
|
instances.scopes.org = this.server.create('scope', {
|
|
|
|
|
type: 'org',
|
|
|
|
|
scope: { id: 'global', type: 'global' },
|
|
|
|
|
});
|
|
|
|
|
instances.scopes.project = this.server.create('scope', {
|
|
|
|
|
type: 'project',
|
|
|
|
|
scope: { id: instances.scopes.org.id, type: 'org' },
|
|
|
|
|
});
|
|
|
|
|
instances.credentialStore = this.server.create('credential-store', {
|
|
|
|
|
scope: instances.scopes.project,
|
|
|
|
|
});
|
|
|
|
|
instances.credentialLibrary = this.server.create('credential-library', {
|
|
|
|
|
scope: instances.scopes.project,
|
|
|
|
|
credentialStore: instances.credentialStore,
|
|
|
|
|
});
|
|
|
|
|
// Generate route URLs for resources
|
2024-12-16 16:31:07 -06:00
|
|
|
urls.credentialStores = `/scopes/${instances.scopes.project.id}/credential-stores`;
|
2021-09-01 19:38:48 -07:00
|
|
|
urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`;
|
|
|
|
|
urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`;
|
2024-12-03 10:27:27 -08:00
|
|
|
await authenticateSession({});
|
2021-09-01 19:38:48 -07:00
|
|
|
});
|
|
|
|
|
|
2021-09-03 11:09:33 -07:00
|
|
|
test('Users can navigate to credential libraries with proper authorization', async function (assert) {
|
2021-09-01 19:38:48 -07:00
|
|
|
await visit(urls.credentialStore);
|
2024-12-16 16:31:07 -06:00
|
|
|
|
2021-09-01 19:38:48 -07:00
|
|
|
assert.ok(
|
|
|
|
|
instances.credentialStore.authorized_collection_actions[
|
|
|
|
|
'credential-libraries'
|
2023-11-22 14:07:41 -05:00
|
|
|
].includes('list'),
|
2021-09-01 19:38:48 -07:00
|
|
|
);
|
2024-12-16 16:31:07 -06:00
|
|
|
assert.dom(commonSelectors.HREF(urls.credentialLibraries)).isVisible();
|
2021-09-01 19:38:48 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Users cannot navigate to index without either list or create actions', async function (assert) {
|
|
|
|
|
instances.credentialStore.authorized_collection_actions[
|
|
|
|
|
'credential-libraries'
|
|
|
|
|
] = [];
|
2024-12-16 16:31:07 -06:00
|
|
|
|
2021-09-01 19:38:48 -07:00
|
|
|
await visit(urls.credentialStore);
|
2024-12-16 16:31:07 -06:00
|
|
|
|
2021-09-01 19:38:48 -07:00
|
|
|
assert.notOk(
|
|
|
|
|
instances.credentialStore.authorized_collection_actions[
|
|
|
|
|
'credential-libraries'
|
2023-11-22 14:07:41 -05:00
|
|
|
].includes('list'),
|
2021-09-01 19:38:48 -07:00
|
|
|
);
|
2024-12-16 16:31:07 -06:00
|
|
|
assert.dom(commonSelectors.HREF(urls.credentialLibraries)).doesNotExist();
|
2021-09-01 19:38:48 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Users can navigate to index with only create action', async function (assert) {
|
|
|
|
|
instances.credentialStore.authorized_collection_actions[
|
|
|
|
|
'credential-libraries'
|
|
|
|
|
] = ['create'];
|
2024-12-16 16:31:07 -06:00
|
|
|
|
2021-09-01 19:38:48 -07:00
|
|
|
await visit(urls.credentialStore);
|
2024-12-16 16:31:07 -06:00
|
|
|
|
|
|
|
|
assert.dom(commonSelectors.HREF(urls.credentialLibraries)).isVisible();
|
2021-09-01 19:38:48 -07:00
|
|
|
});
|
|
|
|
|
});
|