diff --git a/libs/common/src/vault/models/domain/ssh-key.spec.ts b/libs/common/src/vault/models/domain/ssh-key.spec.ts new file mode 100644 index 000000000000..32ae27019287 --- /dev/null +++ b/libs/common/src/vault/models/domain/ssh-key.spec.ts @@ -0,0 +1,67 @@ +import { mockEnc } from "../../../../spec"; +import { SSHKeyApi } from "../api/ssh-key.api"; +import { SSHKeyData } from "../data/ssh-key.data"; + +import { SSHKey } from "./ssh-key"; + +describe("SSHkey", () => { + let data: SSHKeyData; + + beforeEach(() => { + data = new SSHKeyData( + new SSHKeyApi({ + PrivateKey: "privateKey", + PublicKey: "publicKey", + KeyFingerprint: "keyFingerprint", + }), + ); + }); + + it("Convert", () => { + const sshKey = new SSHKey(data); + + expect(sshKey).toEqual({ + privateKey: { encryptedString: "privateKey", encryptionType: 0 }, + publicKey: { encryptedString: "publicKey", encryptionType: 0 }, + keyFingerprint: { encryptedString: "keyFingerprint", encryptionType: 0 }, + }); + }); + + it("Convert from empty", () => { + const data = new SSHKeyData(); + const sshKey = new SSHKey(data); + + expect(sshKey).toEqual({ + privateKey: null, + publicKey: null, + keyFingerprint: null, + }); + }); + + it("toSSHKeyData", () => { + const sshKey = new SSHKey(data); + expect(sshKey.toSSHKeyData()).toEqual(data); + }); + + it("Decrypt", async () => { + const sshKey = Object.assign(new SSHKey(), { + privateKey: mockEnc("privateKey"), + publicKey: mockEnc("publicKey"), + keyFingerprint: mockEnc("keyFingerprint"), + }); + const expectedView = { + privateKey: "privateKey", + publicKey: "publicKey", + keyFingerprint: "keyFingerprint", + }; + + const loginView = await sshKey.decrypt(null); + expect(loginView).toEqual(expectedView); + }); + + describe("fromJSON", () => { + it("returns null if object is null", () => { + expect(SSHKey.fromJSON(null)).toBeNull(); + }); + }); +}); diff --git a/libs/vault/src/cipher-form/components/sshkey-section/sshkey-section.component.html b/libs/vault/src/cipher-form/components/sshkey-section/sshkey-section.component.html index e2cd87d9ed5b..4c85ce782e2b 100644 --- a/libs/vault/src/cipher-form/components/sshkey-section/sshkey-section.component.html +++ b/libs/vault/src/cipher-form/components/sshkey-section/sshkey-section.component.html @@ -1,6 +1,6 @@ -

+

{{ "typeSSHKey" | i18n }}

diff --git a/libs/vault/src/cipher-view/cipher-view.component.html b/libs/vault/src/cipher-view/cipher-view.component.html index 385587b94216..6c8fc46715d9 100644 --- a/libs/vault/src/cipher-view/cipher-view.component.html +++ b/libs/vault/src/cipher-view/cipher-view.component.html @@ -23,7 +23,7 @@ - + diff --git a/libs/vault/src/cipher-view/cipher-view.component.ts b/libs/vault/src/cipher-view/cipher-view.component.ts index 387debfc8fa2..accd95ca7d44 100644 --- a/libs/vault/src/cipher-view/cipher-view.component.ts +++ b/libs/vault/src/cipher-view/cipher-view.component.ts @@ -80,6 +80,10 @@ export class CipherViewComponent implements OnInit, OnDestroy { return this.cipher.login?.uris.length > 0; } + get hasSshKey() { + return this.cipher.sshKey?.privateKey; + } + async loadCipherData() { if (this.cipher.collectionIds.length > 0) { this.collections$ = this.collectionService diff --git a/libs/vault/src/cipher-view/sshkey-sections/sshkey-view.component.html b/libs/vault/src/cipher-view/sshkey-sections/sshkey-view.component.html index 738be187a2f0..4f8159c29152 100644 --- a/libs/vault/src/cipher-view/sshkey-sections/sshkey-view.component.html +++ b/libs/vault/src/cipher-view/sshkey-sections/sshkey-view.component.html @@ -2,7 +2,7 @@

{{ "typeSSHKey" | i18n }}

- + {{ "sshPublicKey" | i18n }}