Skip to content

Commit

Permalink
if the secret doesn't exist, set cas to 0 (#5823)
Browse files Browse the repository at this point in the history
  • Loading branch information
meirish authored Nov 19, 2018
1 parent 7ab4cc5 commit cd1eaf3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 1 addition & 4 deletions ui/app/serializers/secret-v2-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
19 changes: 19 additions & 0 deletions ui/tests/acceptance/secrets/backend/kv/secret-test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand All @@ -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';
Expand Down

0 comments on commit cd1eaf3

Please sign in to comment.