Skip to content

Commit

Permalink
Rename OpenAPI helpers for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
hashishaw committed Apr 5, 2024
1 parent 4e7d5dd commit f7e8a3f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 57 deletions.
52 changes: 51 additions & 1 deletion ui/tests/acceptance/open-api-path-help-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}`);
});
}
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
56 changes: 0 additions & 56 deletions ui/tests/helpers/openapi/test-helpers.js

This file was deleted.

0 comments on commit f7e8a3f

Please sign in to comment.