Icu 5651 create spk type (#1266)
Add functionality for creating a ssh private key credential and add corresponding acceptance tests. ✅ Closes: ICU-5651 Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com> Co-authored-by: Randall Morey <randall@randallmorey.com> Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
This commit is contained in:
9 files changed
+423
-129
No files matched your search
@@ -12,12 +12,15 @@ module(
|
||||
setupMirage(hooks);
|
||||
|
||||
let getCredentialsCount;
|
||||
let getUsernamePasswordCredentialCount;
|
||||
let getUsernameKeyPairCredentialCount;
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
org: null,
|
||||
project: null,
|
||||
},
|
||||
staticCredentialStore: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
@@ -52,19 +55,50 @@ module(
|
||||
getCredentialsCount = () => {
|
||||
return this.server.schema.credentials.all().models.length;
|
||||
};
|
||||
getUsernamePasswordCredentialCount = () => {
|
||||
return this.server.schema.credentials.where({
|
||||
type: 'username_password',
|
||||
}).length;
|
||||
};
|
||||
getUsernameKeyPairCredentialCount = () => {
|
||||
return this.server.schema.credentials.where({ type: 'ssh_private_key' })
|
||||
.length;
|
||||
};
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
test('Users can create a new credential', async function (assert) {
|
||||
assert.expect(1);
|
||||
test('Users can create a new username & password credential', async function (assert) {
|
||||
assert.expect(2);
|
||||
const credentialsCount = getCredentialsCount();
|
||||
const usernamePasswordCredentialCount =
|
||||
getUsernamePasswordCredentialCount();
|
||||
await visit(urls.newCredential);
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click('[type="submit"]');
|
||||
assert.strictEqual(getCredentialsCount(), credentialsCount + 1);
|
||||
assert.strictEqual(
|
||||
getUsernamePasswordCredentialCount(),
|
||||
usernamePasswordCredentialCount + 1
|
||||
);
|
||||
});
|
||||
|
||||
test('Users can cancel create new credential', async function (assert) {
|
||||
test('Users can create a new username & key pair credential', async function (assert) {
|
||||
assert.expect(2);
|
||||
const credentialsCount = getCredentialsCount();
|
||||
const usernameKeyPairCredentialCount =
|
||||
getUsernameKeyPairCredentialCount();
|
||||
await visit(urls.newCredential);
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click('[value="ssh_private_key"]');
|
||||
await click('[type="submit"]');
|
||||
assert.strictEqual(getCredentialsCount(), credentialsCount + 1);
|
||||
assert.strictEqual(
|
||||
getUsernameKeyPairCredentialCount(),
|
||||
usernameKeyPairCredentialCount + 1
|
||||
);
|
||||
});
|
||||
|
||||
test('Users can cancel create new username & password credential', async function (assert) {
|
||||
assert.expect(2);
|
||||
const credentialsCount = getCredentialsCount();
|
||||
await visit(urls.newCredential);
|
||||
@@ -74,6 +108,17 @@ module(
|
||||
assert.strictEqual(getCredentialsCount(), credentialsCount);
|
||||
});
|
||||
|
||||
test('Users can cancel create new username & key pair credential', async function (assert) {
|
||||
assert.expect(2);
|
||||
const credentialsCount = getCredentialsCount();
|
||||
await visit(urls.newCredential);
|
||||
await fillIn('[name="name"]', 'random string');
|
||||
await click('[value="ssh_private_key"]');
|
||||
await click('.rose-form-actions [type="button"]');
|
||||
assert.strictEqual(currentURL(), urls.credentials);
|
||||
assert.strictEqual(getCredentialsCount(), credentialsCount);
|
||||
});
|
||||
|
||||
test('Users cannot navigate to new credential route without proper authorization', async function (assert) {
|
||||
assert.expect(2);
|
||||
instances.staticCredentialStore.authorized_collection_actions.credentials =
|
||||
@@ -87,7 +132,7 @@ module(
|
||||
assert.notOk(find(`[href="${urls.newCredential}"]`));
|
||||
});
|
||||
|
||||
test('saving a new credential with invalid fields displays error messages', async function (assert) {
|
||||
test('saving a new username & password credential with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.post('/credentials', () => {
|
||||
return new Response(
|
||||
@@ -120,5 +165,40 @@ module(
|
||||
'Field required for creating a username-password credential.'
|
||||
);
|
||||
});
|
||||
|
||||
test('saving a new username & key pair credential with invalid fields displays error messages', async function (assert) {
|
||||
assert.expect(2);
|
||||
this.server.post('/credentials', () => {
|
||||
return new Response(
|
||||
400,
|
||||
{},
|
||||
{
|
||||
status: 400,
|
||||
code: 'invalid_argument',
|
||||
message: 'Error in provided request.',
|
||||
details: {
|
||||
request_fields: [
|
||||
{
|
||||
name: 'attributes.private_key',
|
||||
description:
|
||||
'Field required for creating a username-key-pair credential.',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
await visit(urls.newCredential);
|
||||
await click('[value="ssh_private_key"]');
|
||||
await click('[type="submit"]');
|
||||
assert.ok(
|
||||
find('[role="alert"]').textContent.trim(),
|
||||
'Error in provided request.'
|
||||
);
|
||||
assert.ok(
|
||||
find('.rose-form-error-message').textContent.trim(),
|
||||
'Field required for creating a username-key-pair credential.'
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
Reference in new issue
Block a user