mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 17:52:32 +00:00
* UI: Implement overview page for KV v2 (#28162) * build json editor patch form * finish patch component and tests * add tab to each route * and path route * add overview tab to tests * update overview to use updated_time instead of created_time * redirect relevant secret.details to secret.index * compute secretState in component instead of pass as arg * add capabilities service * add error handling to fetchSubkeys adapter request * add overview tabs to test * add subtext to overview card * remaining redirects in secret edit * remove create new version from popup menu * fix breadcrumbs for overview * separate adding capabilities service * add service to kv engine * Revert "separate adding capabilities service" This reverts commit bb70b12ab7dbcde0fbd2d4d81768e5c8b1c420cc. * Revert "add service to kv engine" This reverts commit bfa880535ef7d529d7610936b2c1aae55673d23f. * update navigation test * consistently navigate to secret.index route to be explicit * finish overview navigation tests * add copyright header * update delete tests * fix nav testrs * cleanup secret edit redirects * remove redundant async/awaits * fix create test * edge case tests * secret acceptance tests * final component tests * rename kvSecretDetails external route to kvSecretOverview * add comment * UI: Add patch route and implement Page::Secret::Patch page component (sidebranch) (#28192) * add tab to each route * and path route * add overview tab to tests * update overview to use updated_time instead of created_time * redirect relevant secret.details to secret.index * compute secretState in component instead of pass as arg * add capabilities service * add error handling to fetchSubkeys adapter request * add patch route and put in page component * add patch secret action to subkeys card * fix component name * add patch capability * alphabetize computed capabilities * update links, cleanup selectors * fix more merge conflict stuff * add capabilities test * add models to patch link * add test for patch route * rename external route * add error templates * make notes about enterprise tests, filter one * remove errors, transition (redirect) instead * redirect patch routes * UI: Move fetching secret data to child route (#28198) * remove @secret from metadata details * use metadata model instead of secret in paths page * put delete back into kv/data adapter * grant access in control group test * update metadata route and permissions * remove secret from parent route, only fetch in details route * change more permissions to route perms, add tests * revert overview redirect from list view * wrap model in conditional for perms * remove redundant canReadCustomMetadata check * rename adapter method * handle overview 404 * remove comment * add customMetadata as an arg * update grantAccess in test * make version param easier to follow * VAULT-30494 handle 404 jira * refactor capabilities to return an object * update create tests * add test for default truthy capabilities * remove destroy-all-versions from kv/data adapter * UI: Add enterprise checks (#28215) * add enterprise check for subkey card * add max height and scroll to subkey card * only fetch subkeys if enterprise * remove check in overview * add test * Update ui/tests/integration/components/kv/page/kv-page-overview-test.js * fix test failures (#28222) * add assertion * add optional chaining * create/delete versioned secret in each module * wait for transition * add another waitUntil * UI: Add patch latest version to toolbar (#28223) * add patch latest version action to toolbar * make isPatchAllowed arg all encompassing * no longer need model check * use hash so both promises fire at the same time * add subkeys to policy * Update ui/lib/kv/addon/routes/secret.js * add changelog * small cleanup items! (#28229) * add conditional for enterprise checking tabs * cleanup fetchMultiplePaths method * add test * remove todo comment, ticket created and design wants to hold off * keep transition, update comments * cleanup tests, add index to breadcrumbs * add some test coverage * toggle so value is readable
243 lines
8.4 KiB
JavaScript
243 lines
8.4 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupTest } from 'ember-qunit';
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
|
|
|
module('Unit | Service | capabilities', function (hooks) {
|
|
setupTest(hooks);
|
|
setupMirage(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.capabilities = this.owner.lookup('service:capabilities');
|
|
this.store = this.owner.lookup('service:store');
|
|
this.generateResponse = ({ path, paths, capabilities }) => {
|
|
if (path) {
|
|
// "capabilities" is an array
|
|
return {
|
|
request_id: '6cc7a484-921a-a730-179c-eaf6c6fbe97e',
|
|
data: {
|
|
capabilities,
|
|
[path]: capabilities,
|
|
},
|
|
};
|
|
}
|
|
if (paths) {
|
|
// "capabilities" is an object, paths are keys and values are array of capabilities
|
|
const data = paths.reduce((obj, path) => {
|
|
obj[path] = capabilities[path];
|
|
return obj;
|
|
}, {});
|
|
return {
|
|
request_id: '6cc7a484-921a-a730-179c-eaf6c6fbe97e',
|
|
data,
|
|
};
|
|
}
|
|
};
|
|
});
|
|
|
|
module('general methods', function () {
|
|
test('request: it makes request to capabilities-self with path param', function (assert) {
|
|
const path = '/my/api/path';
|
|
const expectedPayload = { paths: [path] };
|
|
this.server.post('/sys/capabilities-self', (schema, req) => {
|
|
const actual = JSON.parse(req.requestBody);
|
|
assert.true(true, 'request made to capabilities-self');
|
|
assert.propEqual(actual, expectedPayload, `request made with path: ${JSON.stringify(actual)}`);
|
|
return this.generateResponse({ path, capabilities: ['read'] });
|
|
});
|
|
this.capabilities.request({ path });
|
|
});
|
|
|
|
test('request: it makes request to capabilities-self with paths param', function (assert) {
|
|
const paths = ['/my/api/path', 'another/api/path'];
|
|
const expectedPayload = { paths };
|
|
this.server.post('/sys/capabilities-self', (schema, req) => {
|
|
const actual = JSON.parse(req.requestBody);
|
|
assert.true(true, 'request made to capabilities-self');
|
|
assert.propEqual(actual, expectedPayload, `request made with path: ${JSON.stringify(actual)}`);
|
|
return this.generateResponse({
|
|
paths,
|
|
capabilities: { '/my/api/path': ['read'], 'another/api/path': ['read'] },
|
|
});
|
|
});
|
|
this.capabilities.request({ paths });
|
|
});
|
|
});
|
|
|
|
test('fetchPathCapabilities: it makes request to capabilities-self with path param', function (assert) {
|
|
const path = '/my/api/path';
|
|
const expectedPayload = { paths: [path] };
|
|
this.server.post('/sys/capabilities-self', (schema, req) => {
|
|
const actual = JSON.parse(req.requestBody);
|
|
assert.true(true, 'request made to capabilities-self');
|
|
assert.propEqual(actual, expectedPayload, `request made with path: ${JSON.stringify(actual)}`);
|
|
return this.generateResponse({ path, capabilities: ['read'] });
|
|
});
|
|
this.capabilities.fetchPathCapabilities(path);
|
|
});
|
|
|
|
test('fetchMultiplePaths: it makes request to capabilities-self with paths param', async function (assert) {
|
|
const paths = ['/my/api/path', 'another/api/path'];
|
|
const expectedPayload = { paths };
|
|
this.server.post('/sys/capabilities-self', (schema, req) => {
|
|
const actual = JSON.parse(req.requestBody);
|
|
assert.true(true, 'request made to capabilities-self');
|
|
assert.propEqual(actual, expectedPayload, `request made with path: ${JSON.stringify(actual)}`);
|
|
return this.generateResponse({
|
|
paths,
|
|
capabilities: { '/my/api/path': ['read', 'list'], 'another/api/path': ['read', 'delete'] },
|
|
});
|
|
});
|
|
const actual = await this.capabilities.fetchMultiplePaths(paths);
|
|
const expected = {
|
|
'/my/api/path': {
|
|
canCreate: false,
|
|
canDelete: false,
|
|
canList: true,
|
|
canPatch: false,
|
|
canRead: true,
|
|
canSudo: false,
|
|
canUpdate: false,
|
|
},
|
|
'another/api/path': {
|
|
canCreate: false,
|
|
canDelete: true,
|
|
canList: false,
|
|
canPatch: false,
|
|
canRead: true,
|
|
canSudo: false,
|
|
canUpdate: false,
|
|
},
|
|
};
|
|
assert.propEqual(actual, expected, `it returns expected response: ${JSON.stringify(actual)}`);
|
|
});
|
|
|
|
test('fetchMultiplePaths: it defaults to true if the capabilities request fails', async function (assert) {
|
|
// don't stub endpoint which causes request to fail
|
|
const paths = ['/my/api/path', 'another/api/path'];
|
|
const actual = await this.capabilities.fetchMultiplePaths(paths);
|
|
const expected = {
|
|
'/my/api/path': {
|
|
canCreate: true,
|
|
canDelete: true,
|
|
canList: true,
|
|
canPatch: true,
|
|
canRead: true,
|
|
canSudo: true,
|
|
canUpdate: true,
|
|
},
|
|
'another/api/path': {
|
|
canCreate: true,
|
|
canDelete: true,
|
|
canList: true,
|
|
canPatch: true,
|
|
canRead: true,
|
|
canSudo: true,
|
|
canUpdate: true,
|
|
},
|
|
};
|
|
assert.propEqual(actual, expected, `it returns expected response: ${JSON.stringify(actual)}`);
|
|
});
|
|
|
|
test('fetchMultiplePaths: it defaults to true if no model is found', async function (assert) {
|
|
const paths = ['/my/api/path', 'another/api/path'];
|
|
const expectedPayload = { paths };
|
|
this.server.post('/sys/capabilities-self', (schema, req) => {
|
|
const actual = JSON.parse(req.requestBody);
|
|
assert.true(true, 'request made to capabilities-self');
|
|
assert.propEqual(actual, expectedPayload, `request made with path: ${JSON.stringify(actual)}`);
|
|
return this.generateResponse({
|
|
paths: ['/my/api/path'],
|
|
capabilities: { '/my/api/path': ['read', 'list'] },
|
|
});
|
|
});
|
|
const actual = await this.capabilities.fetchMultiplePaths(paths);
|
|
const expected = {
|
|
'/my/api/path': {
|
|
canCreate: false,
|
|
canDelete: false,
|
|
canList: true,
|
|
canPatch: false,
|
|
canRead: true,
|
|
canSudo: false,
|
|
canUpdate: false,
|
|
},
|
|
'another/api/path': {
|
|
canCreate: true,
|
|
canDelete: true,
|
|
canList: true,
|
|
canPatch: true,
|
|
canRead: true,
|
|
canSudo: true,
|
|
canUpdate: true,
|
|
},
|
|
};
|
|
assert.propEqual(actual, expected, `it returns expected response: ${JSON.stringify(actual)}`);
|
|
});
|
|
|
|
module('specific methods', function () {
|
|
const path = '/my/api/path';
|
|
[
|
|
{
|
|
capabilities: ['read'],
|
|
expectedRead: true, // expected computed properties based on response
|
|
expectedUpdate: false,
|
|
expectedPatch: false,
|
|
},
|
|
{
|
|
capabilities: ['update'],
|
|
expectedRead: false,
|
|
expectedUpdate: true,
|
|
expectedPatch: false,
|
|
},
|
|
{
|
|
capabilities: ['patch'],
|
|
expectedRead: false,
|
|
expectedUpdate: false,
|
|
expectedPatch: true,
|
|
},
|
|
{
|
|
capabilities: ['deny'],
|
|
expectedRead: false,
|
|
expectedUpdate: false,
|
|
expectedPatch: false,
|
|
},
|
|
{
|
|
capabilities: ['read', 'update'],
|
|
expectedRead: true,
|
|
expectedUpdate: true,
|
|
expectedPatch: false,
|
|
},
|
|
].forEach(({ capabilities, expectedRead, expectedUpdate, expectedPatch }) => {
|
|
test(`canRead returns expected value for "${capabilities.join(', ')}"`, async function (assert) {
|
|
this.server.post('/sys/capabilities-self', () => {
|
|
return this.generateResponse({ path, capabilities });
|
|
});
|
|
|
|
const response = await this.capabilities.canRead(path);
|
|
assert[expectedRead](response, `canRead returns ${expectedRead}`);
|
|
});
|
|
|
|
test(`canUpdate returns expected value for "${capabilities.join(', ')}"`, async function (assert) {
|
|
this.server.post('/sys/capabilities-self', () => {
|
|
return this.generateResponse({ path, capabilities });
|
|
});
|
|
const response = await this.capabilities.canUpdate(path);
|
|
assert[expectedUpdate](response, `canUpdate returns ${expectedUpdate}`);
|
|
});
|
|
|
|
test(`canPatch returns expected value for "${capabilities.join(', ')}"`, async function (assert) {
|
|
this.server.post('/sys/capabilities-self', () => {
|
|
return this.generateResponse({ path, capabilities });
|
|
});
|
|
const response = await this.capabilities.canPatch(path);
|
|
assert[expectedPatch](response, `canPatch returns ${expectedPatch}`);
|
|
});
|
|
});
|
|
});
|
|
});
|