Vault SSH Cert Feature (#1596)

* feat: 🎸 Update models for vault ssh cert feature (#1591)

✅ Closes: ICU-7546

* feat: 🎸 Setup types in cred library forms and use HDS component (#1597)

* feat: 🎸 Setup types in cred library forms and use HDS component

✅ Closes: ICU-7673

* feat: 🎸 Add vault ssh cert type for credential library (#1608)

* feat: 🎸 Add vault ssh cert type for credential library

✅ Closes: ICU-7678

* feat: 🎸 Enable feature flag for vault ssh cert work (#1614)

* fix: 🐛 Change fields to optional as they get default by backend (#1615)

* Chore/cleanup vault ssh cert (#1616)
This commit is contained in:
Zhihe Li authored and GitHub committed 2023-02-01 13:46:23 -05:00
1 parent e3772352ea
commit f0530e1f8f
34 files changed
+1421 -182

No files matched your search

@@ -1,10 +1,18 @@
import { module, test } from 'qunit';
import { visit, click, fillIn, currentURL, find } from '@ember/test-helpers';
import {
visit,
click,
fillIn,
currentURL,
find,
select,
} from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { Response } from 'miragejs';
import { TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE } from 'api/models/credential-library';
module('Acceptance | credential-libraries | create', function (hooks) {
setupApplicationTest(hooks);
@@ -83,6 +91,76 @@ module('Acceptance | credential-libraries | create', function (hooks) {
assert.strictEqual(getCredentialLibraryCount(), count + 1);
});
test('can create a new credential library of type vault ssh cert', async function (assert) {
assert.expect(12);
const count = getCredentialLibraryCount();
await visit(urls.newCredentialLibrary);
await click('[value="vault-ssh-certificate"]');
await fillIn('[name="name"]', 'name');
await fillIn('[name="description"]', 'description');
await fillIn('[name="vault_path"]', 'path');
await fillIn('[name="username"]', 'username');
await select('[name="key_type"]', 'rsa');
await fillIn('[name="key_bits"]', 100);
await fillIn('[name="ttl"]', 'ttl');
await fillIn('[name="key_id"]', 'key_id');
await fillIn(
'[name="critical_options"] tbody td:nth-of-type(1) input',
'co_key'
);
await fillIn(
'[name="critical_options"] tbody td:nth-of-type(2) input',
'co_value'
);
await click('[name="critical_options"] button');
await fillIn(
'[name="extensions"] tbody td:nth-of-type(1) input',
'ext_key'
);
await fillIn(
'[name="extensions"] tbody td:nth-of-type(2) input',
'ext_value'
);
await click('[name="extensions"] button');
await click('[type="submit"]');
assert.strictEqual(getCredentialLibraryCount(), count + 1);
assert.strictEqual(
this.server.schema.credentialLibraries.where({
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
}).length,
1
);
const credentialLibrary = this.server.schema.credentialLibraries.findBy({
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
});
assert.strictEqual(credentialLibrary.name, 'name');
assert.strictEqual(credentialLibrary.description, 'description');
assert.strictEqual(credentialLibrary.attributes.path, 'path');
assert.strictEqual(credentialLibrary.attributes.username, 'username');
assert.strictEqual(credentialLibrary.attributes.key_type, 'rsa');
assert.strictEqual(credentialLibrary.attributes.key_bits, 100);
assert.strictEqual(credentialLibrary.attributes.ttl, 'ttl');
assert.strictEqual(credentialLibrary.attributes.key_id, 'key_id');
assert.deepEqual(credentialLibrary.attributes.critical_options, {
co_key: 'co_value',
});
assert.deepEqual(credentialLibrary.attributes.extensions, {
ext_key: 'ext_value',
});
});
test('ecdsa and rsa key types bring up a key bits field', async function (assert) {
assert.expect(3);
await visit(urls.newCredentialLibrary);
await click('[value="vault-ssh-certificate"]');
await select('[name="key_type"]', 'ed25519');
assert.dom('[name="key_bits"]').doesNotExist();
await select('[name="key_type"]', 'ecdsa');
assert.dom('[name="key_bits"]').isVisible();
await select('[name="key_type"]', 'rsa');
assert.dom('[name="key_bits"]').isVisible();
});
test('Users cannot navigate to new credential library route without proper authorization', async function (assert) {
assert.expect(2);
instances.credentialStore.authorized_collection_actions[
@@ -107,7 +185,7 @@ module('Acceptance | credential-libraries | create', function (hooks) {
assert.strictEqual(getCredentialLibraryCount(), count);
});
test('saving a new credential library with invalid fields displays error messasges', async function (assert) {
test('saving a new credential library with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.post('/credential-libraries', () => {
return new Response(
@@ -135,8 +213,17 @@ module('Acceptance | credential-libraries | create', function (hooks) {
'The request was invalid.'
);
assert.ok(
find('.rose-form-error-message').textContent.trim(),
find('.hds-form-error__message').textContent.trim(),
'Name is required.'
);
});
test('cannot select vault ssh cert when feature is disabled', async function (assert) {
const featuresService = this.owner.lookup('service:features');
featuresService.disable('credential-library-vault-ssh-certificate');
assert.expect(1);
await visit(urls.newCredentialLibrary);
assert.dom('[value="vault-ssh-certificate"]').doesNotExist();
});
});
@@ -4,6 +4,7 @@ import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE } from 'api/models/credential-library';
module('Acceptance | credential-libraries | read', function (hooks) {
setupApplicationTest(hooks);
@@ -78,6 +79,23 @@ module('Acceptance | credential-libraries | read', function (hooks) {
assert.notOk(find('main tbody .rose-table-header-cell a'));
});
test('cannot navigate to vault ssh cert form when feature is not enabled', async function (assert) {
assert.expect(1);
instances.credentialLibrary = this.server.create('credential-library', {
scope: instances.scopes.project,
credentialStore: instances.credentialStore,
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
});
await visit(
`${urls.credentialLibraries}/${instances.credentialLibrary.id}`
);
const featuresService = this.owner.lookup('service:features');
featuresService.disable('credential-library-vault-ssh-certificate');
await visit(urls.credentialLibraries);
assert.dom('.rose-table-body tr:nth-of-type(2) a').doesNotExist();
});
test('visiting an unknown credential library displays 404 message', async function (assert) {
assert.expect(1);
await visit(urls.unknownCredentialLibrary);
@@ -1,9 +1,17 @@
import { module, test } from 'qunit';
import { visit, click, fillIn, currentURL, find } from '@ember/test-helpers';
import {
visit,
click,
fillIn,
currentURL,
find,
select,
} from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { Response } from 'miragejs';
import { TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE } from 'api/models/credential-library';
module('Acceptance | credential-libraries | update', function (hooks) {
setupApplicationTest(hooks);
@@ -130,7 +138,7 @@ module('Acceptance | credential-libraries | update', function (hooks) {
'The request was invalid.'
);
assert.ok(
find('.rose-form-error-message').textContent.trim(),
find('.hds-form-error__message').textContent.trim(),
'Name is required.'
);
});
@@ -181,4 +189,61 @@ module('Acceptance | credential-libraries | update', function (hooks) {
);
}
});
test('can update a vault ssh cert credential library and save changes', async function (assert) {
assert.expect(10);
instances.credentialLibrary = this.server.create('credential-library', {
scope: instances.scopes.project,
credentialStore: instances.credentialStore,
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
});
await visit(
`${urls.credentialLibraries}/${instances.credentialLibrary.id}`
);
await click('form [type="button"]:not(:disabled)', 'Activate edit mode');
await fillIn('[name="name"]', 'name');
await fillIn('[name="description"]', 'description');
await fillIn('[name="vault_path"]', 'path');
await fillIn('[name="username"]', 'username');
await select('[name="key_type"]', 'rsa');
await fillIn('[name="key_bits"]', 100);
await fillIn('[name="ttl"]', 'ttl');
await fillIn('[name="key_id"]', 'key_id');
await fillIn(
'[name="critical_options"] tbody td:nth-of-type(1) input',
'co_key'
);
await fillIn(
'[name="critical_options"] tbody td:nth-of-type(2) input',
'co_value'
);
await click('[name="critical_options"] button');
await fillIn(
'[name="extensions"] tbody td:nth-of-type(1) input',
'ext_key'
);
await fillIn(
'[name="extensions"] tbody td:nth-of-type(2) input',
'ext_value'
);
await click('[name="extensions"] button');
await click('[type="submit"]');
const credentialLibrary = this.server.schema.credentialLibraries.findBy({
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
});
assert.strictEqual(credentialLibrary.name, 'name');
assert.strictEqual(credentialLibrary.description, 'description');
assert.strictEqual(credentialLibrary.attributes.path, 'path');
assert.strictEqual(credentialLibrary.attributes.username, 'username');
assert.strictEqual(credentialLibrary.attributes.key_type, 'rsa');
assert.strictEqual(credentialLibrary.attributes.key_bits, 100);
assert.strictEqual(credentialLibrary.attributes.ttl, 'ttl');
assert.strictEqual(credentialLibrary.attributes.key_id, 'key_id');
assert.deepEqual(credentialLibrary.attributes.critical_options, {
co_key: 'co_value',
});
assert.deepEqual(credentialLibrary.attributes.extensions, {
ext_key: 'ext_value',
});
});
});
@@ -0,0 +1,44 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupIntl } from 'ember-intl/test-support';
module('Integration | Component | key-value-list', function (hooks) {
setupRenderingTest(hooks);
setupIntl(hooks);
test('it renders fields', async function (assert) {
await render(hbs`
<Form::Field::KeyValueList as |M|>
<M.Legend>Label</M.Legend>
<M.HelperText>Help</M.HelperText>
<M.Error as |E|>
<E.Message>Error!</E.Message>
</M.Error>
</Form::Field::KeyValueList>
`);
assert.dom('tbody tr').exists({ count: 1 });
assert.dom('legend').exists().hasText('Label');
assert.dom('.hds-form-helper-text').exists().hasText('Help');
assert.dom('.hds-form-error__message').exists().hasText('Error!');
assert.dom('button').exists().hasText('Add');
});
test('it renders multiple options', async function (assert) {
this.options = [
{ key: 'one', value: 'two' },
{ key: 'three', value: 'four' },
];
// Template block usage:
await render(hbs`
<Form::Field::KeyValueList
@options={{this.options}}
/>
`);
assert.dom('tbody tr').exists({ count: 3 });
});
});
@@ -0,0 +1,73 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import {
TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC,
TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
} from 'api/models/credential-library';
module('Unit | Abilities | credential-library', function (hooks) {
setupTest(hooks);
let features;
hooks.beforeEach(function () {
features = this.owner.lookup('service:features');
features.enable('credential-library-vault-ssh-certificate');
});
test('can read credential library type when authorized and feature is enabled', function (assert) {
assert.expect(2);
const canService = this.owner.lookup('service:can');
const store = this.owner.lookup('service:store');
const credentialLibrary = store.createRecord('credential-library', {
authorized_actions: ['read'],
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
});
assert.true(canService.can('read credential-library', credentialLibrary));
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
assert.true(canService.can('read credential-library', credentialLibrary));
});
test('cannot read credential library type when unauthorized and feature is enabled', function (assert) {
assert.expect(2);
const canService = this.owner.lookup('service:can');
const store = this.owner.lookup('service:store');
const credentialLibrary = store.createRecord('credential-library', {
authorized_actions: [],
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
});
assert.false(canService.can('read credential-library', credentialLibrary));
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
assert.false(canService.can('read credential-library', credentialLibrary));
});
test('cannot read credential library type when unauthorized and feature is disabled', function (assert) {
assert.expect(2);
const canService = this.owner.lookup('service:can');
const store = this.owner.lookup('service:store');
const featuresService = this.owner.lookup('service:features');
featuresService.disable('credential-library-vault-ssh-certificate');
const credentialLibrary = store.createRecord('credential-library', {
authorized_actions: [],
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
});
assert.false(canService.can('read credential-library', credentialLibrary));
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
assert.false(canService.can('read credential-library', credentialLibrary));
});
test('can read vault-generic but not vault-ssh-certificate when authorized and feature is disabled', function (assert) {
assert.expect(2);
const canService = this.owner.lookup('service:can');
const store = this.owner.lookup('service:store');
const featuresService = this.owner.lookup('service:features');
featuresService.disable('credential-library-vault-ssh-certificate');
const credentialLibrary = store.createRecord('credential-library', {
authorized_actions: ['read'],
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
});
assert.false(canService.can('read credential-library', credentialLibrary));
credentialLibrary.type = TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC;
assert.true(canService.can('read credential-library', credentialLibrary));
});
});