open-vault/ui/tests/acceptance/ssh-test.js

136 lines
5.4 KiB
JavaScript
Raw Normal View History

import { click, fillIn, findAll, currentURL, find, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import authPage from 'vault/tests/pages/auth';
import enablePage from 'vault/tests/pages/settings/mount-secret-backend';
2018-04-03 14:16:57 +00:00
module('Acceptance | ssh secret backend', function(hooks) {
setupApplicationTest(hooks);
2018-04-03 14:16:57 +00:00
hooks.beforeEach(function() {
return authPage.login();
});
const PUB_KEY = `ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCn9p5dHNr4aU4R2W7ln+efzO5N2Cdv/SXk6zbCcvhWcblWMjkXf802B0PbKvf6cJIzM/Xalb3qz1cK+UUjCSEAQWefk6YmfzbOikfc5EHaSKUqDdE+HlsGPvl42rjCr28qYfuYh031YfwEQGEAIEypo7OyAj+38NLbHAQxDxuaReee1YCOV5rqWGtEgl2VtP5kG+QEBza4ZfeglS85f/GGTvZC4Jq1GX+wgmFxIPnd6/mUXa4ecoR0QMfOAzzvPm4ajcNCQORfHLQKAcmiBYMiyQJoU+fYpi9CJGT1jWTmR99yBkrSg6yitI2qqXyrpwAbhNGrM0Fw0WpWxh66N9Xp meirish@Macintosh-3.local`;
const ROLES = [
{
type: 'ca',
name: 'carole',
async fillInCreate() {
await click('[data-test-input="allowUserCertificates"]');
},
async fillInGenerate() {
await fillIn('[data-test-input="publicKey"]', PUB_KEY);
},
assertAfterGenerate(assert, sshPath) {
assert.equal(currentURL(), `/vault/secrets/${sshPath}/sign/${this.name}`, 'ca sign url is correct');
assert.dom('[data-test-row-label="Signed key"]').exists({ count: 1 }, 'renders the signed key');
assert
.dom('[data-test-row-value="Signed key"]')
.exists({ count: 1 }, "renders the signed key's value");
assert.dom('[data-test-row-label="Serial number"]').exists({ count: 1 }, 'renders the serial');
assert.dom('[data-test-row-value="Serial number"]').exists({ count: 1 }, 'renders the serial value');
},
2018-04-03 14:16:57 +00:00
},
{
type: 'otp',
name: 'otprole',
async fillInCreate() {
await fillIn('[data-test-input="defaultUser"]', 'admin');
await click('[data-test-toggle-more]');
await fillIn('[data-test-input="cidrList"]', '1.2.3.4/32');
},
async fillInGenerate() {
await fillIn('[data-test-input="username"]', 'admin');
await fillIn('[data-test-input="ip"]', '1.2.3.4');
},
assertAfterGenerate(assert, sshPath) {
assert.equal(
currentURL(),
`/vault/secrets/${sshPath}/credentials/${this.name}`,
'otp credential url is correct'
);
assert.dom('[data-test-row-label="Key"]').exists({ count: 1 }, 'renders the key');
assert.dom('[data-test-row-value="Key"]').exists({ count: 1 }, "renders the key's value");
assert.dom('[data-test-row-label="Port"]').exists({ count: 1 }, 'renders the port');
assert.dom('[data-test-row-value="Port"]').exists({ count: 1 }, "renders the port's value");
},
2018-04-03 14:16:57 +00:00
},
];
test('ssh backend', async function(assert) {
const now = new Date().getTime();
const sshPath = `ssh-${now}`;
await enablePage.enable('ssh', sshPath);
await click('[data-test-secret-backend-configure]');
2018-04-03 14:16:57 +00:00
assert.equal(currentURL(), `/vault/settings/secrets/configure/${sshPath}`);
assert.ok(findAll('[data-test-ssh-configure-form]').length, 'renders the empty configuration form');
2018-04-03 14:16:57 +00:00
// default has generate CA checked so we just submit the form
await click('[data-test-ssh-input="configure-submit"]');
assert.ok(findAll('[data-test-ssh-input="public-key"]').length, 'a public key is fetched');
await click('[data-test-backend-view-link]');
2018-04-03 14:16:57 +00:00
assert.equal(currentURL(), `/vault/secrets/${sshPath}/list`, `redirects to ssh index`);
for (let role of ROLES) {
// create a role
await click('[ data-test-secret-create]');
2018-04-03 14:16:57 +00:00
assert.ok(
find('[data-test-secret-header]').textContent.includes('SSH Role'),
2018-04-03 14:16:57 +00:00
`${role.type}: renders the create page`
);
await fillIn('[data-test-input="name"]', role.name);
await fillIn('[data-test-input="keyType"]', role.type);
await role.fillInCreate();
2018-04-03 14:16:57 +00:00
// save the role
await click('[data-test-role-ssh-create]');
2018-04-03 14:16:57 +00:00
assert.equal(
currentURL(),
`/vault/secrets/${sshPath}/show/${role.name}`,
`${role.type}: navigates to the show page on creation`
);
// sign a key with this role
await click('[data-test-backend-credentials]');
await role.fillInGenerate();
2018-04-03 14:16:57 +00:00
// generate creds
await click('[data-test-secret-generate]');
2018-04-03 14:16:57 +00:00
role.assertAfterGenerate(assert, sshPath);
// click the "Back" button
await click('[data-test-secret-generate-back]');
2018-04-03 14:16:57 +00:00
assert.ok(
findAll('[data-test-secret-generate-form]').length,
2018-04-03 14:16:57 +00:00
`${role.type}: back takes you back to the form`
);
await click('[data-test-secret-generate-cancel]');
2018-04-03 14:16:57 +00:00
assert.equal(
currentURL(),
`/vault/secrets/${sshPath}/list`,
`${role.type}: cancel takes you to ssh index`
);
assert.ok(
findAll(`[data-test-secret-link="${role.name}"]`).length,
2018-04-03 14:16:57 +00:00
`${role.type}: role shows in the list`
);
//and delete
await click(`[data-test-secret-link="${role.name}"] [data-test-popup-menu-trigger]`);
await click(`[data-test-ssh-role-delete="${role.name}"] button`);
await click(`[data-test-confirm-button]`);
2018-04-03 14:16:57 +00:00
await settled();
assert
.dom(`[data-test-secret-link="${role.name}"]`)
.doesNotExist(`${role.type}: role is no longer in the list`);
}
2018-04-03 14:16:57 +00:00
});
});