if the secret doesn't exist, set cas to 0 (#5823)

This commit is contained in:
Matthew Irish 2018-11-19 15:47:58 -06:00 committed by GitHub
parent 0c6793d774
commit 7320a92963
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View file

@ -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: {

View file

@ -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';