From f7e8a3f51216bbaa1b157494f3ac6a5b5f48877c Mon Sep 17 00:00:00 2001 From: Chelsea Shaw Date: Thu, 4 Apr 2024 15:32:34 -0500 Subject: [PATCH] Rename OpenAPI helpers for clarity --- .../acceptance/open-api-path-help-test.js | 52 ++++++++++++++++- ...l-attributes.js => expected-auth-attrs.js} | 4 ++ ...attributes.js => expected-secret-attrs.js} | 0 ui/tests/helpers/openapi/test-helpers.js | 56 ------------------- 4 files changed, 55 insertions(+), 57 deletions(-) rename ui/tests/helpers/openapi/{auth-model-attributes.js => expected-auth-attrs.js} (99%) rename ui/tests/helpers/openapi/{secret-model-attributes.js => expected-secret-attrs.js} (100%) delete mode 100644 ui/tests/helpers/openapi/test-helpers.js diff --git a/ui/tests/acceptance/open-api-path-help-test.js b/ui/tests/acceptance/open-api-path-help-test.js index c2fdcf36ebca..b4de27b520c0 100644 --- a/ui/tests/acceptance/open-api-path-help-test.js +++ b/ui/tests/acceptance/open-api-path-help-test.js @@ -7,7 +7,8 @@ import { module, test } from 'qunit'; import { setupApplicationTest } from 'vault/tests/helpers'; import authPage from 'vault/tests/pages/auth'; import { deleteAuthCmd, deleteEngineCmd, mountAuthCmd, mountEngineCmd, runCmd } from '../helpers/commands'; -import { authEngineHelper, secretEngineHelper } from '../helpers/openapi/test-helpers'; +import expectedSecretAttrs from 'vault/tests/helpers/openapi/expected-secret-attrs'; +import expectedAuthAttrs from 'vault/tests/helpers/openapi/expected-auth-attrs'; /** * This set of tests is for ensuring that backend changes to the OpenAPI spec @@ -56,3 +57,52 @@ module('Acceptance | OpenAPI provides expected attributes enterprise', function } ); }); + +function secretEngineHelper(test, secretEngine) { + const engineData = expectedSecretAttrs[secretEngine]; + if (!engineData) + throw new Error(`No engine attributes found in secret-model-attributes for ${secretEngine}`); + + const modelNames = Object.keys(engineData); + // A given secret engine might have multiple models that are openApi driven + modelNames.forEach((modelName) => { + test(`${modelName} model getProps returns correct attributes`, async function (assert) { + const model = this.store.createRecord(modelName, {}); + const helpUrl = model.getHelpUrl(this.backend); + const result = await this.pathHelp.getProps(helpUrl, this.backend); + const expected = engineData[modelName]; + assert.deepEqual(result, expected, `getProps returns expected attributes for ${modelName}`); + }); + }); +} + +const authEngineHelper = (test, authBackend) => { + const authData = expectedAuthAttrs[authBackend]; + if (!authData) throw new Error(`No auth attributes found in auth-model-attributes for ${authBackend}`); + + const itemNames = Object.keys(authData); + itemNames.forEach((itemName) => { + if (itemName.startsWith('auth-config/')) { + // Config test doesn't need to instantiate a new model + test(`${itemName} model`, async function (assert) { + const model = this.store.createRecord(itemName, {}); + const helpUrl = model.getHelpUrl(this.mount); + const result = await this.pathHelp.getProps(helpUrl, this.mount); + const expected = authData[itemName]; + assert.deepEqual(result, expected, `getProps returns expected attributes for ${itemName}`); + }); + } else { + test.skip(`generated-${itemName}-${authBackend} model`, async function (assert) { + const modelName = `generated-${itemName}-${authBackend}`; + // Generated items need to instantiate the model first via getNewModel + await this.pathHelp.getNewModel(modelName, this.mount, `auth/${this.mount}/`, itemName); + const model = this.store.createRecord(modelName, {}); + // Generated items don't have this method -- helpUrl is calculated in path-help.js line 101 + const helpUrl = model.getHelpUrl(this.mount); + const result = await this.pathHelp.getProps(helpUrl, this.mount); + const expected = authData[modelName]; + assert.deepEqual(result, expected, `getProps returns expected attributes for ${modelName}`); + }); + } + }); +}; diff --git a/ui/tests/helpers/openapi/auth-model-attributes.js b/ui/tests/helpers/openapi/expected-auth-attrs.js similarity index 99% rename from ui/tests/helpers/openapi/auth-model-attributes.js rename to ui/tests/helpers/openapi/expected-auth-attrs.js index d4ca32c3ee3f..69317a166d09 100644 --- a/ui/tests/helpers/openapi/auth-model-attributes.js +++ b/ui/tests/helpers/openapi/expected-auth-attrs.js @@ -3,6 +3,10 @@ * SPDX-License-Identifier: BUSL-1.1 */ +// The constants within this file represent the expected model attributes as parsed from OpenAPI +// if changes are made to the OpenAPI spec, that may result in changes that must be reflected +// here AND ensured to not cause breaking changes within the UI. + const userpass = { user: { username: { diff --git a/ui/tests/helpers/openapi/secret-model-attributes.js b/ui/tests/helpers/openapi/expected-secret-attrs.js similarity index 100% rename from ui/tests/helpers/openapi/secret-model-attributes.js rename to ui/tests/helpers/openapi/expected-secret-attrs.js diff --git a/ui/tests/helpers/openapi/test-helpers.js b/ui/tests/helpers/openapi/test-helpers.js deleted file mode 100644 index 04307aea4f52..000000000000 --- a/ui/tests/helpers/openapi/test-helpers.js +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (c) HashiCorp, Inc. - * SPDX-License-Identifier: BUSL-1.1 - */ - -import authModelAttributes from './auth-model-attributes'; -import secretModelAttributes from './secret-model-attributes'; - -export const secretEngineHelper = (test, secretEngine) => { - const engineData = secretModelAttributes[secretEngine]; - if (!engineData) - throw new Error(`No engine attributes found in secret-model-attributes for ${secretEngine}`); - - const modelNames = Object.keys(engineData); - // A given secret engine might have multiple models that are openApi driven - modelNames.forEach((modelName) => { - test(`${modelName} model getProps returns correct attributes`, async function (assert) { - const model = this.store.createRecord(modelName, {}); - const helpUrl = model.getHelpUrl(this.backend); - const result = await this.pathHelp.getProps(helpUrl, this.backend); - const expected = engineData[modelName]; - assert.deepEqual(result, expected, `getProps returns expected attributes for ${modelName}`); - }); - }); -}; - -export const authEngineHelper = (test, authBackend) => { - const authData = authModelAttributes[authBackend]; - if (!authData) throw new Error(`No auth attributes found in auth-model-attributes for ${authBackend}`); - - const itemNames = Object.keys(authData); - itemNames.forEach((itemName) => { - if (itemName.startsWith('auth-config/')) { - // Config test doesn't need to instantiate a new model - test(`${itemName} model`, async function (assert) { - const model = this.store.createRecord(itemName, {}); - const helpUrl = model.getHelpUrl(this.mount); - const result = await this.pathHelp.getProps(helpUrl, this.mount); - const expected = authData[itemName]; - assert.deepEqual(result, expected, `getProps returns expected attributes for ${itemName}`); - }); - } else { - test.skip(`generated-${itemName}-${authBackend} model`, async function (assert) { - const modelName = `generated-${itemName}-${authBackend}`; - // Generated items need to instantiate the model first via getNewModel - await this.pathHelp.getNewModel(modelName, this.mount, `auth/${this.mount}/`, itemName); - const model = this.store.createRecord(modelName, {}); - // Generated items don't have this method -- helpUrl is calculated in path-help.js line 101 - const helpUrl = model.getHelpUrl(this.mount); - const result = await this.pathHelp.getProps(helpUrl, this.mount); - const expected = authData[modelName]; - assert.deepEqual(result, expected, `getProps returns expected attributes for ${modelName}`); - }); - } - }); -};