From 7320a929637b0fd1fc3f85b1de4af213e682e8cb Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Mon, 19 Nov 2018 15:47:58 -0600 Subject: [PATCH] if the secret doesn't exist, set cas to 0 (#5823) --- ui/app/serializers/secret-v2-version.js | 5 +---- .../secrets/backend/kv/secret-test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ui/app/serializers/secret-v2-version.js b/ui/app/serializers/secret-v2-version.js index d8c77703d..61a001821 100644 --- a/ui/app/serializers/secret-v2-version.js +++ b/ui/app/serializers/secret-v2-version.js @@ -16,11 +16,8 @@ export default ApplicationSerializer.extend({ return payload; }, serialize(snapshot) { - let version = 0; let secret = snapshot.belongsTo('secret'); - if (secret) { - version = secret.attr('currentVersion'); - } + let version = secret.attr('currentVersion') || 0; return { data: snapshot.attr('secretData'), options: { diff --git a/ui/tests/acceptance/secrets/backend/kv/secret-test.js b/ui/tests/acceptance/secrets/backend/kv/secret-test.js index 84fd277d2..88f2cd91f 100644 --- a/ui/tests/acceptance/secrets/backend/kv/secret-test.js +++ b/ui/tests/acceptance/secrets/backend/kv/secret-test.js @@ -1,4 +1,5 @@ import { currentURL, currentRouteName } from '@ember/test-helpers'; +import { create } from 'ember-cli-page-object'; import { module, test } from 'qunit'; import { setupApplicationTest } from 'ember-qunit'; import editPage from 'vault/tests/pages/secrets/backend/kv/edit-secret'; @@ -9,6 +10,9 @@ import mountSecrets from 'vault/tests/pages/settings/mount-secret-backend'; import apiStub from 'vault/tests/helpers/noop-all-api-requests'; import authPage from 'vault/tests/pages/auth'; import withFlash from 'vault/tests/helpers/with-flash'; +import consoleClass from 'vault/tests/pages/components/console/ui-panel'; + +const consoleComponent = create(consoleClass); module('Acceptance | secrets/secret/create', function(hooks) { setupApplicationTest(hooks); @@ -34,6 +38,21 @@ module('Acceptance | secrets/secret/create', function(hooks) { assert.ok(showPage.editIsPresent, 'shows the edit button'); }); + test('it can create a secret when check-and-set is required', async function(assert) { + let enginePath = `kv-${new Date().getTime()}`; + let secretPath = 'foo/bar'; + await mountSecrets.visit(); + await mountSecrets.enable('kv', enginePath); + await consoleComponent.runCommands(`write ${enginePath}/config cas_required=true`); + + await listPage.visitRoot({ backend: enginePath }); + await listPage.create(); + await editPage.createSecret(secretPath, 'foo', 'bar'); + + assert.equal(currentRouteName(), 'vault.cluster.secrets.backend.show', 'redirects to the show page'); + assert.ok(showPage.editIsPresent, 'shows the edit button'); + }); + test('version 1 performs the correct capabilities lookup', async function(assert) { let enginePath = `kv-${new Date().getTime()}`; let secretPath = 'foo/bar';