|
| 1 | +/** |
| 2 | + * Copyright (c) HashiCorp, Inc. |
| 3 | + * SPDX-License-Identifier: BUSL-1.1 |
| 4 | + */ |
| 5 | + |
| 6 | +import { settled, click, fillIn, visit, currentRouteName } from '@ember/test-helpers'; |
| 7 | +import { module, test } from 'qunit'; |
| 8 | +import { setupApplicationTest } from 'ember-qunit'; |
| 9 | + |
| 10 | +import mountSecrets from 'vault/tests/pages/settings/mount-secret-backend'; |
| 11 | +import { login } from 'vault/tests/helpers/auth/auth-helpers'; |
| 12 | +import { mountBackend } from 'vault/tests/helpers/components/mount-backend-form-helpers'; |
| 13 | +import { GENERAL } from 'vault/tests/helpers/general-selectors'; |
| 14 | +import { SELECTORS } from 'vault/tests/helpers/secret-engine/general-settings-selectors'; |
| 15 | +import { create } from 'ember-cli-page-object'; |
| 16 | +import consoleClass from 'vault/tests/pages/components/console/ui-panel'; |
| 17 | + |
| 18 | +const consoleComponent = create(consoleClass); |
| 19 | + |
| 20 | +module('Acceptance | Enterprise | keymgmt-configuration-workflow', function (hooks) { |
| 21 | + setupApplicationTest(hooks); |
| 22 | + |
| 23 | + hooks.beforeEach(function () { |
| 24 | + return login(); |
| 25 | + }); |
| 26 | + |
| 27 | + test('it should display keymgmt configuration and tune keymgmt in the general settings form', async function (assert) { |
| 28 | + await consoleComponent.runCommands([ |
| 29 | + // delete any previous mount with same name |
| 30 | + 'delete sys/mounts/keymgmt', |
| 31 | + ]); |
| 32 | + const keymgmtType = 'keymgmt'; |
| 33 | + await mountSecrets.visit(); |
| 34 | + await settled(); |
| 35 | + await mountBackend(keymgmtType, keymgmtType); |
| 36 | + await click(SELECTORS.manageDropdown); |
| 37 | + await click(SELECTORS.manageDropdownItem('Configure')); |
| 38 | + assert |
| 39 | + .dom(GENERAL.hdsPageHeaderTitle) |
| 40 | + .hasText(`${keymgmtType} configuration`, 'displays configuration title'); |
| 41 | + assert.dom(GENERAL.tab('general-settings')).hasText(`General settings`); |
| 42 | + assert.dom(GENERAL.cardContainer('version')).exists('version card exists'); |
| 43 | + assert.dom(SELECTORS.versionCard.engineType).hasText(keymgmtType, 'shows keymgmt engine type'); |
| 44 | + assert.dom(GENERAL.cardContainer('metadata')).exists('metadata card exists'); |
| 45 | + assert.dom(GENERAL.inputByAttr('path')).hasValue(`${keymgmtType}/`, 'show path value'); |
| 46 | + assert.dom(GENERAL.cardContainer('lease-duration')).exists('lease-duration card exists'); |
| 47 | + assert.dom(GENERAL.cardContainer('security')).exists('security card exists'); |
| 48 | + |
| 49 | + // fill in values to tune |
| 50 | + await fillIn(GENERAL.inputByAttr('default_lease_ttl'), 10); |
| 51 | + await fillIn(GENERAL.selectByAttr('default_lease_ttl'), 'm'); |
| 52 | + await fillIn(GENERAL.inputByAttr('max_lease_ttl'), 15); |
| 53 | + await fillIn(GENERAL.selectByAttr('max_lease_ttl'), 'd'); |
| 54 | + await fillIn(GENERAL.textareaByAttr('description'), 'Some awesome description.'); |
| 55 | + await click(GENERAL.submitButton); |
| 56 | + |
| 57 | + // after submitting go to list and back to configuration |
| 58 | + await visit(`/vault/secrets/${keymgmtType}/list`); |
| 59 | + await visit(`/vault/secrets/${keymgmtType}/configuration`); |
| 60 | + |
| 61 | + // confirm that submitted values were saved and prepopulated with those saved values |
| 62 | + assert |
| 63 | + .dom(GENERAL.textareaByAttr('description')) |
| 64 | + .hasValue('Some awesome description.', 'description was tuned'); |
| 65 | + assert.dom(GENERAL.inputByAttr('default_lease_ttl')).hasValue('10', 'default ttl value was tuned'); |
| 66 | + assert |
| 67 | + .dom(GENERAL.selectByAttr('default_lease_ttl')) |
| 68 | + .hasValue('m', 'default ttl value was tuned and shows correct unit'); |
| 69 | + assert.dom(GENERAL.inputByAttr('max_lease_ttl')).hasValue('15', 'max ttl value was tuned'); |
| 70 | + assert |
| 71 | + .dom(GENERAL.selectByAttr('max_lease_ttl')) |
| 72 | + .hasValue('d', 'max ttl value was tuned and shows correct unit'); |
| 73 | + |
| 74 | + // navigate back to keymgmt list view to delete the engine from the manage dropdown |
| 75 | + await visit(`/vault/secrets/${keymgmtType}/list`); |
| 76 | + await click(SELECTORS.manageDropdown); |
| 77 | + await click(SELECTORS.manageDropdownItem('Delete')); |
| 78 | + await click(GENERAL.confirmButton); |
| 79 | + assert.strictEqual(currentRouteName(), 'vault.cluster.secrets.backends'); |
| 80 | + await consoleComponent.runCommands([ |
| 81 | + // cleanup after |
| 82 | + 'delete sys/mounts/keymgmt', |
| 83 | + ]); |
| 84 | + }); |
| 85 | +}); |
0 commit comments