fix: 🐛 credential library serializer for SSH certificate (#2790)

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16880
This commit is contained in:
Cameron Perera authored and GitHub committed 2025-04-25 10:23:51 -05:00
1 parent de83d59bde
commit 40ec4493ea
2 files changed
+61

No files matched your search

@@ -28,6 +28,7 @@ export default class CredentialLibrarySerializer extends ApplicationSerializer {
case TYPE_CREDENTIAL_LIBRARY_VAULT_GENERIC:
return this.serializeVaultGeneric(...arguments);
case TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE:
return this.serializeVaultSshCertificate(...arguments);
default:
return super.serialize(...arguments);
}
@@ -61,4 +62,16 @@ export default class CredentialLibrarySerializer extends ApplicationSerializer {
return serialized;
}
}
serializeVaultSshCertificate() {
const serialized = super.serialize(...arguments);
if (serialized.attributes) {
const { key_type } = serialized.attributes;
if (key_type !== 'rsa' && key_type !== 'ecdsa') {
// If the key type is not RSA or ECDSA, set key_bits to null
serialized.attributes.key_bits = null;
}
return serialized;
}
}
}
@@ -231,4 +231,52 @@ module('Unit | Serializer | credential library', function (hooks) {
version: 1,
});
});
test('it serializes vault_ssh_certificate correctly when changing type to ed25519', function (assert) {
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('credential-library');
store.push({
data: {
id: '1',
type: 'credential-library',
attributes: {
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
version: 1,
name: 'Name',
description: 'Description',
path: '/vault/path',
username: 'user',
key_type: 'rsa',
key_bits: 100,
ttl: '100',
key_id: 'id',
extensions: [{ key: 'key', value: 'value' }],
critical_options: [{ key: 'key', value: 'value' }],
},
},
});
const record = store.peekRecord('credential-library', '1');
record.key_type = 'ed25519';
const snapshot = record._createSnapshot();
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
type: TYPE_CREDENTIAL_LIBRARY_VAULT_SSH_CERTIFICATE,
credential_store_id: null,
name: 'Name',
description: 'Description',
attributes: {
path: '/vault/path',
username: 'user',
key_type: 'ed25519',
key_bits: null,
ttl: '100',
key_id: 'id',
extensions: { key: 'value' },
critical_options: { key: 'value' },
},
version: 1,
});
});
});