From 83c7b76f486b935a9b7ea35161143dce0159f691 Mon Sep 17 00:00:00 2001 From: Cameron Perera Date: Tue, 30 Aug 2022 20:40:31 -0500 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20Update=20passphrase?= =?UTF-8?q?=20to=20private=5Fkey=5Fpassphrase=20(#1290)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: ICU-5916 --- addons/api/addon/generated/models/credential.js | 4 ++-- addons/api/addon/serializers/credential.js | 14 +++++++------- addons/api/mirage/serializers/credential.js | 6 +++--- .../api/tests/unit/serializers/credential-test.js | 12 ++++++------ addons/core/translations/resources/en-us.yaml | 4 ++-- .../form/credential/ssh_private_key/index.hbs | 14 +++++++------- .../credential-store/credentials/update-test.js | 6 +++--- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/addons/api/addon/generated/models/credential.js b/addons/api/addon/generated/models/credential.js index 898beb83d..e9a5ad386 100644 --- a/addons/api/addon/generated/models/credential.js +++ b/addons/api/addon/generated/models/credential.js @@ -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; } diff --git a/addons/api/addon/serializers/credential.js b/addons/api/addon/serializers/credential.js index 8a9fcf64a..afe6f2274 100644 --- a/addons/api/addon/serializers/credential.js +++ b/addons/api/addon/serializers/credential.js @@ -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; } } diff --git a/addons/api/mirage/serializers/credential.js b/addons/api/mirage/serializers/credential.js index 243255d4d..cd46766a4 100644 --- a/addons/api/mirage/serializers/credential.js +++ b/addons/api/mirage/serializers/credential.js @@ -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; }, diff --git a/addons/api/tests/unit/serializers/credential-test.js b/addons/api/tests/unit/serializers/credential-test.js index 87ec047a4..566ea6e13 100644 --- a/addons/api/tests/unit/serializers/credential-test.js +++ b/addons/api/tests/unit/serializers/credential-test.js @@ -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: '', }, diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index b2269965b..0d1a931a4 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -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 diff --git a/ui/admin/app/components/form/credential/ssh_private_key/index.hbs b/ui/admin/app/components/form/credential/ssh_private_key/index.hbs index 36fb1a761..d1eee70be 100644 --- a/ui/admin/app/components/form/credential/ssh_private_key/index.hbs +++ b/ui/admin/app/components/form/credential/ssh_private_key/index.hbs @@ -124,18 +124,18 @@ {{/if}} - {{#if @model.errors.passphrase}} + {{#if @model.errors.private_key_passphrase}} - {{#each @model.errors.passphrase as |error|}} + {{#each @model.errors.private_key_passphrase as |error|}} {{error.message}} {{/each}} diff --git a/ui/admin/tests/acceptance/credential-store/credentials/update-test.js b/ui/admin/tests/acceptance/credential-store/credentials/update-test.js index 24375726a..9e70f5594 100644 --- a/ui/admin/tests/acceptance/credential-store/credentials/update-test.js +++ b/ui/admin/tests/acceptance/credential-store/credentials/update-test.js @@ -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(); }); } );