From 66c307d5b08ea7ea51c8437f5ffa1d42e53d9253 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Mon, 8 Jan 2024 10:45:02 -0800 Subject: [PATCH 1/3] relationships, failing tests --- ui/app/models/control-group.js | 4 ++-- ui/app/models/identity/entity-alias.js | 2 +- ui/app/models/identity/entity.js | 2 +- ui/app/models/identity/group.js | 2 +- ui/app/models/kmip/ca.js | 2 +- ui/app/models/kmip/config.js | 2 +- ui/app/models/mfa-login-enforcement.js | 6 +++--- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ui/app/models/control-group.js b/ui/app/models/control-group.js index be420d5dff25..b84974feed33 100644 --- a/ui/app/models/control-group.js +++ b/ui/app/models/control-group.js @@ -10,8 +10,8 @@ import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities'; export default Model.extend({ approved: attr('boolean'), requestPath: attr('string'), - requestEntity: belongsTo('identity/entity', { async: false }), - authorizations: hasMany('identity/entity', { async: false }), + requestEntity: belongsTo('identity/entity', { async: false, inverse: null }), + authorizations: hasMany('identity/entity', { async: false, inverse: null }), authorizePath: lazyCapabilities(apiPath`sys/control-group/authorize`), canAuthorize: alias('authorizePath.canUpdate'), diff --git a/ui/app/models/identity/entity-alias.js b/ui/app/models/identity/entity-alias.js index a29f16084658..d6042175a723 100644 --- a/ui/app/models/identity/entity-alias.js +++ b/ui/app/models/identity/entity-alias.js @@ -14,7 +14,7 @@ export default IdentityModel.extend({ formFields: computed(function () { return ['name', 'mountAccessor']; }), - entity: belongsTo('identity/entity', { readOnly: true, async: false }), + entity: belongsTo('identity/entity', { readOnly: true, async: false, inverse: 'aliases' }), name: attr('string'), canonicalId: attr('string'), diff --git a/ui/app/models/identity/entity.js b/ui/app/models/identity/entity.js index 5622ea5a65cd..bb53324d8120 100644 --- a/ui/app/models/identity/entity.js +++ b/ui/app/models/identity/entity.js @@ -34,7 +34,7 @@ export default IdentityModel.extend({ lastUpdateTime: attr('string', { readOnly: true, }), - aliases: hasMany('identity/entity-alias', { async: false, readOnly: true }), + aliases: hasMany('identity/entity-alias', { async: false, readOnly: true, inverse: 'entity' }), groupIds: attr({ readOnly: true, }), diff --git a/ui/app/models/identity/group.js b/ui/app/models/identity/group.js index 14a8c8c30da0..d2be312b31c5 100644 --- a/ui/app/models/identity/group.js +++ b/ui/app/models/identity/group.js @@ -77,7 +77,7 @@ export default IdentityModel.extend({ ), policyPath: lazyCapabilities(apiPath`sys/policies`), canCreatePolicies: alias('policyPath.canCreate'), - alias: belongsTo('identity/group-alias', { async: false, readOnly: true }), + alias: belongsTo('identity/group-alias', { async: false, readOnly: true, inverse: 'group' }), updatePath: identityCapabilities(), canDelete: alias('updatePath.canDelete'), canEdit: alias('updatePath.canUpdate'), diff --git a/ui/app/models/kmip/ca.js b/ui/app/models/kmip/ca.js index aea85b4cf937..c468530c634d 100644 --- a/ui/app/models/kmip/ca.js +++ b/ui/app/models/kmip/ca.js @@ -6,7 +6,7 @@ import Model, { belongsTo, attr } from '@ember-data/model'; export default Model.extend({ - config: belongsTo('kmip/config', { async: false }), + config: belongsTo('kmip/config', { async: false, inverse: 'ca' }), caPem: attr('string', { label: 'CA PEM', }), diff --git a/ui/app/models/kmip/config.js b/ui/app/models/kmip/config.js index 336cc3db7cfc..8a9fedbb2d5b 100644 --- a/ui/app/models/kmip/config.js +++ b/ui/app/models/kmip/config.js @@ -10,7 +10,7 @@ import fieldToAttrs from 'vault/utils/field-to-attrs'; export default Model.extend({ useOpenAPI: true, - ca: belongsTo('kmip/ca', { async: false }), + ca: belongsTo('kmip/ca', { async: false, inverse: 'config' }), getHelpUrl(path) { return `/v1/${path}/config?help=1`; }, diff --git a/ui/app/models/mfa-login-enforcement.js b/ui/app/models/mfa-login-enforcement.js index 69f307ea676e..ac1791b7f75e 100644 --- a/ui/app/models/mfa-login-enforcement.js +++ b/ui/app/models/mfa-login-enforcement.js @@ -37,12 +37,12 @@ const validations = { export default class MfaLoginEnforcementModel extends Model { @service store; @attr('string') name; - @hasMany('mfa-method') mfa_methods; + @hasMany('mfa-method', { async: true, inverse: null }) mfa_methods; @attr('string') namespace_id; @attr('array', { defaultValue: () => [] }) auth_method_accessors; // ["auth_approle_17a552c6"] @attr('array', { defaultValue: () => [] }) auth_method_types; // ["userpass"] - @hasMany('identity/entity') identity_entities; - @hasMany('identity/group') identity_groups; + @hasMany('identity/entity', { async: true, inverse: null }) identity_entities; + @hasMany('identity/group', { async: true, inverse: null }) identity_groups; get targets() { return ArrayProxy.extend(PromiseProxyMixin).create({ From c2c099dccf7945234117701f22bf4387043f4fc2 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Mon, 8 Jan 2024 11:38:32 -0800 Subject: [PATCH 2/3] remove old policies test to get tests passing --- ui/tests/acceptance/policies-acl-old-test.js | 91 -------------------- 1 file changed, 91 deletions(-) delete mode 100644 ui/tests/acceptance/policies-acl-old-test.js diff --git a/ui/tests/acceptance/policies-acl-old-test.js b/ui/tests/acceptance/policies-acl-old-test.js deleted file mode 100644 index 35eccecf4bc6..000000000000 --- a/ui/tests/acceptance/policies-acl-old-test.js +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright (c) HashiCorp, Inc. - * SPDX-License-Identifier: BUSL-1.1 - */ - -import { click, fillIn, find, currentURL, waitUntil } from '@ember/test-helpers'; -import { module, test } from 'qunit'; -import { setupApplicationTest } from 'ember-qunit'; -import { v4 as uuidv4 } from 'uuid'; - -import page from 'vault/tests/pages/policies/index'; -import authPage from 'vault/tests/pages/auth'; - -module('Acceptance | policies (old)', function (hooks) { - setupApplicationTest(hooks); - - hooks.beforeEach(function () { - this.uid = uuidv4(); - return authPage.login(); - }); - - test('policies', async function (assert) { - const policyString = 'path "*" { capabilities = ["update"]}'; - const policyName = `Policy test ${this.uid}`; - const policyLower = policyName.toLowerCase(); - - await page.visit({ type: 'acl' }); - // new policy creation - await click('[data-test-policy-create-link]'); - - await fillIn('[data-test-policy-input="name"]', policyName); - await click('[data-test-policy-save]'); - assert - .dom('[data-test-message-error]') - .hasText(`Error 'policy' parameter not supplied or empty`, 'renders error message on save'); - find('.CodeMirror').CodeMirror.setValue(policyString); - await click('[data-test-policy-save]'); - - await waitUntil(() => currentURL() === `/vault/policy/acl/${encodeURIComponent(policyLower)}`); - assert.strictEqual( - currentURL(), - `/vault/policy/acl/${encodeURIComponent(policyLower)}`, - 'navigates to policy show on successful save' - ); - assert.dom('[data-test-policy-name]').hasText(policyLower, 'displays the policy name on the show page'); - assert.dom('[data-test-flash-message].is-info').doesNotExist('no flash message is displayed on save'); - await click('[data-test-policy-list-link] a'); - await fillIn('[data-test-component="navigate-input"]', policyLower); - assert - .dom(`[data-test-policy-link="${policyLower}"]`) - .exists({ count: 1 }, 'new policy shown in the list'); - - // policy deletion - await click(`[data-test-policy-link="${policyLower}"]`); - - await click('[data-test-policy-edit-toggle]'); - - await click('[data-test-confirm-action-trigger]'); - - await click('[data-test-confirm-button]'); - await waitUntil(() => currentURL() === `/vault/policies/acl`); - assert.strictEqual( - currentURL(), - `/vault/policies/acl`, - 'navigates to policy list on successful deletion' - ); - await fillIn('[data-test-component="navigate-input"]', policyLower); - assert - .dom(`[data-test-policy-item="${policyLower}"]`) - .doesNotExist('deleted policy is not shown in the list'); - }); - - // https://github.com/hashicorp/vault/issues/4395 - test('it properly fetches policies when the name ends in a ,', async function (assert) { - const policyString = 'path "*" { capabilities = ["update"]}'; - const policyName = `${this.uid}-policy-symbol,.`; - - await page.visit({ type: 'acl' }); - // new policy creation - await click('[data-test-policy-create-link]'); - - await fillIn('[data-test-policy-input="name"]', policyName); - find('.CodeMirror').CodeMirror.setValue(policyString); - await click('[data-test-policy-save]'); - assert.ok( - await waitUntil(() => currentURL() === `/vault/policy/acl/${policyName}`), - 'navigates to policy show on successful save' - ); - assert.dom('[data-test-policy-edit-toggle]').exists({ count: 1 }, 'shows the edit toggle'); - }); -}); From e06fe0531047f230f6489fcf7c3900b600735507 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Mon, 8 Jan 2024 12:58:49 -0800 Subject: [PATCH 3/3] try adding back in --- ui/tests/acceptance/policies-acl-old-test.js | 91 ++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 ui/tests/acceptance/policies-acl-old-test.js diff --git a/ui/tests/acceptance/policies-acl-old-test.js b/ui/tests/acceptance/policies-acl-old-test.js new file mode 100644 index 000000000000..35eccecf4bc6 --- /dev/null +++ b/ui/tests/acceptance/policies-acl-old-test.js @@ -0,0 +1,91 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: BUSL-1.1 + */ + +import { click, fillIn, find, currentURL, waitUntil } from '@ember/test-helpers'; +import { module, test } from 'qunit'; +import { setupApplicationTest } from 'ember-qunit'; +import { v4 as uuidv4 } from 'uuid'; + +import page from 'vault/tests/pages/policies/index'; +import authPage from 'vault/tests/pages/auth'; + +module('Acceptance | policies (old)', function (hooks) { + setupApplicationTest(hooks); + + hooks.beforeEach(function () { + this.uid = uuidv4(); + return authPage.login(); + }); + + test('policies', async function (assert) { + const policyString = 'path "*" { capabilities = ["update"]}'; + const policyName = `Policy test ${this.uid}`; + const policyLower = policyName.toLowerCase(); + + await page.visit({ type: 'acl' }); + // new policy creation + await click('[data-test-policy-create-link]'); + + await fillIn('[data-test-policy-input="name"]', policyName); + await click('[data-test-policy-save]'); + assert + .dom('[data-test-message-error]') + .hasText(`Error 'policy' parameter not supplied or empty`, 'renders error message on save'); + find('.CodeMirror').CodeMirror.setValue(policyString); + await click('[data-test-policy-save]'); + + await waitUntil(() => currentURL() === `/vault/policy/acl/${encodeURIComponent(policyLower)}`); + assert.strictEqual( + currentURL(), + `/vault/policy/acl/${encodeURIComponent(policyLower)}`, + 'navigates to policy show on successful save' + ); + assert.dom('[data-test-policy-name]').hasText(policyLower, 'displays the policy name on the show page'); + assert.dom('[data-test-flash-message].is-info').doesNotExist('no flash message is displayed on save'); + await click('[data-test-policy-list-link] a'); + await fillIn('[data-test-component="navigate-input"]', policyLower); + assert + .dom(`[data-test-policy-link="${policyLower}"]`) + .exists({ count: 1 }, 'new policy shown in the list'); + + // policy deletion + await click(`[data-test-policy-link="${policyLower}"]`); + + await click('[data-test-policy-edit-toggle]'); + + await click('[data-test-confirm-action-trigger]'); + + await click('[data-test-confirm-button]'); + await waitUntil(() => currentURL() === `/vault/policies/acl`); + assert.strictEqual( + currentURL(), + `/vault/policies/acl`, + 'navigates to policy list on successful deletion' + ); + await fillIn('[data-test-component="navigate-input"]', policyLower); + assert + .dom(`[data-test-policy-item="${policyLower}"]`) + .doesNotExist('deleted policy is not shown in the list'); + }); + + // https://github.com/hashicorp/vault/issues/4395 + test('it properly fetches policies when the name ends in a ,', async function (assert) { + const policyString = 'path "*" { capabilities = ["update"]}'; + const policyName = `${this.uid}-policy-symbol,.`; + + await page.visit({ type: 'acl' }); + // new policy creation + await click('[data-test-policy-create-link]'); + + await fillIn('[data-test-policy-input="name"]', policyName); + find('.CodeMirror').CodeMirror.setValue(policyString); + await click('[data-test-policy-save]'); + assert.ok( + await waitUntil(() => currentURL() === `/vault/policy/acl/${policyName}`), + 'navigates to policy show on successful save' + ); + assert.dom('[data-test-policy-edit-toggle]').exists({ count: 1 }, 'shows the edit toggle'); + }); +});