refactor: 💡 Update passphrase to private_key_passphrase (#1290)
✅ Closes: ICU-5916
This commit is contained in:
1 parent
cb3104a624
commit
83c7b76f48
7 files changed
+30
-30
No files matched your search
@@ -73,7 +73,7 @@ export default class GeneratedCredentialModel extends BaseModel {
|
||||
@attr('string', {
|
||||
for: 'ssh_private_key',
|
||||
isNestedAttribute: true,
|
||||
description: 'The passphrase for credential.',
|
||||
description: 'The private key passphrase for credential.',
|
||||
})
|
||||
passphrase;
|
||||
private_key_passphrase;
|
||||
}
|
||||
@@ -27,7 +27,7 @@ export default class CredentialSerializer extends ApplicationSerializer {
|
||||
const serialized = super.serialize(...arguments);
|
||||
// Remove non-username_password type attributes
|
||||
delete serialized.attributes.private_key;
|
||||
delete serialized.attributes.passphrase;
|
||||
delete serialized.attributes.private_key_passphrase;
|
||||
// Remove password from the payload if null
|
||||
// or empty string. This allows the user to only update
|
||||
// the username without providing the password again.
|
||||
@@ -42,13 +42,13 @@ export default class CredentialSerializer extends ApplicationSerializer {
|
||||
const serialized = super.serialize(...arguments);
|
||||
// Remove non-ssh_private_key type attributes
|
||||
delete serialized.attributes.password;
|
||||
// Remove private_key and/or passphrase from the payload if null
|
||||
// or empty string. This allows the user to only update
|
||||
// Remove private_key and/or private_key_passphrase from the payload
|
||||
// if null or empty string. This allows the user to only update
|
||||
// the username without providing the private key and passphrase again.
|
||||
// Users cannot unset the private key or passphrase, they would have
|
||||
// to delete the credential entirely.
|
||||
if (!serialized?.attributes?.passphrase)
|
||||
delete serialized.attributes.passphrase;
|
||||
if (!serialized?.attributes?.private_key_passphrase)
|
||||
delete serialized.attributes.private_key_passphrase;
|
||||
if (!serialized?.attributes?.private_key)
|
||||
delete serialized.attributes.private_key;
|
||||
return serialized;
|
||||
@@ -57,10 +57,10 @@ export default class CredentialSerializer extends ApplicationSerializer {
|
||||
normalize(typeClass, hash, ...rest) {
|
||||
const normalizedHash = copy(hash, true);
|
||||
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
|
||||
// Remove passphrase as we don't track it after being created/updated
|
||||
normalized.data.attributes.passphrase = '';
|
||||
// Remove secret fields as we don't track them after being created/updated
|
||||
normalized.data.attributes.password = '';
|
||||
normalized.data.attributes.private_key = '';
|
||||
normalized.data.attributes.private_key_passphrase = '';
|
||||
return normalized;
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,11 @@ export default ApplicationSerializer.extend({
|
||||
);
|
||||
json.credential_store_id = model.credentialStoreId;
|
||||
|
||||
// in a real API, the password, private_key, and passphrase
|
||||
// field is not returned so we delete it from the response
|
||||
// in a real API, the password, private_key, and private_key_passphrase
|
||||
// fields are not returned so we delete them from the response
|
||||
delete json.attributes?.password;
|
||||
delete json.attributes?.private_key;
|
||||
delete json.attributes?.passphrase;
|
||||
delete json.attributes?.private_key_passphrase;
|
||||
|
||||
return json;
|
||||
},
|
||||
|
||||
@@ -66,7 +66,7 @@ module('Unit | Serializer | credential', function (hooks) {
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('credential');
|
||||
const record = store.createRecord('credential', {
|
||||
passphrase: 'passphrasesaresosecure',
|
||||
private_key_passphrase: 'passphrasesaresosecure',
|
||||
private_key: 'superPriveKey',
|
||||
username: 'user',
|
||||
credential_store_id: 'csst_i7p1eu0Nw8',
|
||||
@@ -80,7 +80,7 @@ module('Unit | Serializer | credential', function (hooks) {
|
||||
|
||||
assert.deepEqual(serializedRecord, {
|
||||
attributes: {
|
||||
passphrase: 'passphrasesaresosecure',
|
||||
private_key_passphrase: 'passphrasesaresosecure',
|
||||
private_key: 'superPriveKey',
|
||||
username: 'user',
|
||||
},
|
||||
@@ -97,7 +97,7 @@ module('Unit | Serializer | credential', function (hooks) {
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('credential');
|
||||
const record = store.createRecord('credential', {
|
||||
passphrase: '',
|
||||
private_key_passphrase: '',
|
||||
private_key: '',
|
||||
username: 'user',
|
||||
credential_store_id: 'csst_i7p1eu0Nw8',
|
||||
@@ -143,7 +143,7 @@ module('Unit | Serializer | credential', function (hooks) {
|
||||
type: 'username_password',
|
||||
username: 'username',
|
||||
version: 1,
|
||||
passphrase: '',
|
||||
private_key_passphrase: '',
|
||||
private_key: '',
|
||||
password: '',
|
||||
},
|
||||
@@ -165,7 +165,7 @@ module('Unit | Serializer | credential', function (hooks) {
|
||||
type: 'ssh_private_key',
|
||||
attributes: {
|
||||
username: 'username',
|
||||
passphrase: 'random',
|
||||
private_key_passphrase: 'random',
|
||||
private_key_hmac: 'completenonsense',
|
||||
},
|
||||
};
|
||||
@@ -177,7 +177,7 @@ module('Unit | Serializer | credential', function (hooks) {
|
||||
type: 'ssh_private_key',
|
||||
username: 'username',
|
||||
version: 1,
|
||||
passphrase: '',
|
||||
private_key_passphrase: '',
|
||||
private_key: '',
|
||||
password: '',
|
||||
},
|
||||
|
||||
@@ -425,8 +425,8 @@ credential:
|
||||
private_key:
|
||||
label: SSH Private Key
|
||||
help: The private key to use when connecting with this credential store.
|
||||
passphrase:
|
||||
label: Pass phrase
|
||||
private_key_passphrase:
|
||||
label: Passphrase
|
||||
help: Optional.
|
||||
scope:
|
||||
title: Scope
|
||||
|
||||
@@ -124,18 +124,18 @@
|
||||
{{/if}}
|
||||
</form.textarea>
|
||||
<form.textarea
|
||||
@name='passphrase'
|
||||
@value={{@model.passphrase}}
|
||||
@label={{t 'resources.credential.form.passphrase.label'}}
|
||||
@helperText={{t 'resources.credential.form.passphrase.help'}}
|
||||
@error={{@model.errors.passphrase}}
|
||||
@name='private_key_passphrase'
|
||||
@value={{@model.private_key_passphrase}}
|
||||
@label={{t 'resources.credential.form.private_key_passphrase.label'}}
|
||||
@helperText={{t 'resources.credential.form.private_key_passphrase.help'}}
|
||||
@error={{@model.errors.private_key_passphrase}}
|
||||
disabled={{@model.isSaving}}
|
||||
readonly={{false}}
|
||||
as |field|
|
||||
>
|
||||
{{#if @model.errors.passphrase}}
|
||||
{{#if @model.errors.private_key_passphrase}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.passphrase as |error|}}
|
||||
{{#each @model.errors.private_key_passphrase as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
|
||||
@@ -331,15 +331,15 @@ module(
|
||||
assert.dom('[name="password"]').isVisible();
|
||||
});
|
||||
|
||||
test('private_key and passphrase fields render in edit mode only for a username & key pair credential', async function (assert) {
|
||||
test('private_key and private_key_passphrase fields render in edit mode only for a username & key pair credential', async function (assert) {
|
||||
assert.expect(5);
|
||||
await visit(urls.usernameKeyPairCredential);
|
||||
assert.dom('[name="private_key"]').doesNotExist();
|
||||
assert.dom('[name="passphrase"]').doesNotExist();
|
||||
assert.dom('[name="private_key_passphrase"]').doesNotExist();
|
||||
await click('form [type="button"]', 'Activate edit mode');
|
||||
assert.strictEqual(currentURL(), urls.usernameKeyPairCredential);
|
||||
assert.dom('[name="private_key"]').isVisible();
|
||||
assert.dom('[name="passphrase"]').isVisible();
|
||||
assert.dom('[name="private_key_passphrase"]').isVisible();
|
||||
});
|
||||
}
|
||||
);
|
||||
Reference in new issue
Block a user