Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport: 1.8.x fix delete menu on KV with permissions #12552

Merged
merged 1 commit into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/12550.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Fix bug where capabilities check on secret-delete-menu was encoding the forward slashes.
```
8 changes: 4 additions & 4 deletions ui/app/components/secret-delete-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class SecretDeleteMenu extends Component {
if (!context.args || !context.args.modelForData || !context.args.modelForData.id) return;
let [backend, id] = JSON.parse(context.args.modelForData.id);
return {
id: `${encodeURIComponent(backend)}/delete/${encodeURIComponent(id)}`,
id: `${backend}/delete/${id}`,
};
},
'model.id'
Expand All @@ -61,7 +61,7 @@ export default class SecretDeleteMenu extends Component {
if (!context.args || !context.args.modelForData || !context.args.modelForData.id) return;
let [backend, id] = JSON.parse(context.args.modelForData.id);
return {
id: `${encodeURIComponent(backend)}/undelete/${encodeURIComponent(id)}`,
id: `${backend}/undelete/${id}`,
};
},
'model.id'
Expand All @@ -75,7 +75,7 @@ export default class SecretDeleteMenu extends Component {
if (!context.args || !context.args.modelForData || !context.args.modelForData.id) return;
let [backend, id] = JSON.parse(context.args.modelForData.id);
return {
id: `${encodeURIComponent(backend)}/destroy/${encodeURIComponent(id)}`,
id: `${backend}/destroy/${id}`,
};
},
'model.id'
Expand All @@ -90,7 +90,7 @@ export default class SecretDeleteMenu extends Component {
let backend = context.args.model.engine.id;
let id = context.args.model.id;
return {
id: `${encodeURIComponent(backend)}/metadata/${encodeURIComponent(id)}`,
id: `${backend}/metadata/${id}`,
};
},
'model',
Expand Down
56 changes: 56 additions & 0 deletions ui/tests/acceptance/secrets/backend/kv/secret-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,62 @@ module('Acceptance | secrets/secret/create', function(hooks) {
assert.dom('[data-test-secret-undelete]').exists('undelete button shows');
});

test('version 2 with path forward slash will show delete button', async function(assert) {
let backend = 'kv-v2';
const V2_POLICY = `
path "kv-v2/delete/forward/slash" {
capabilities = ["update"]
}
path "kv-v2/metadata/*" {
capabilities = ["list","read","create","update"]
}
path "kv-v2/data/forward/slash" {
capabilities = ["create", "read"]
}
`;
await consoleComponent.runCommands([
`write sys/mounts/${backend} type=kv options=version=2`,
`write sys/policies/acl/kv-v2-degrade policy=${btoa(V2_POLICY)}`,
// delete any kv previously written here so that tests can be re-run
'delete kv-v2/metadata/forward/slash',
'write -field=client_token auth/token/create policies=kv-v2-degrade',
]);

let userToken = consoleComponent.lastLogOutput;
await logout.visit();
await authPage.login(userToken);
await writeSecret(backend, 'forward/slash', 'foo', 'bar');
assert.dom('[data-test-secret-v2-delete="true"]').exists('drop down delete shows');
});

test('version 2 with engine with forward slash will show delete button', async function(assert) {
let backend = 'forward/slash';
const V2_POLICY = `
path "forward/slash/delete/secret" {
capabilities = ["update"]
}
path "forward/slash/metadata/*" {
capabilities = ["list","read","create","update"]
}
path "forward/slash/data/*" {
capabilities = ["create", "read"]
}
`;
await consoleComponent.runCommands([
`write sys/mounts/${backend} type=kv options=version=2`,
`write sys/policies/acl/kv-v2-degrade policy=${btoa(V2_POLICY)}`,
// delete any kv previously written here so that tests can be re-run
'delete forward/slash/metadata/secret',
'write -field=client_token auth/token/create policies=kv-v2-degrade',
]);

let userToken = consoleComponent.lastLogOutput;
await logout.visit();
await authPage.login(userToken);
await writeSecret(backend, 'secret', 'foo', 'bar');
assert.dom('[data-test-secret-v2-delete="true"]').exists('drop down delete shows');
});

test('paths are properly encoded', async function(assert) {
let backend = 'kv';
let paths = [
Expand Down