Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quexten committed Aug 30, 2024
1 parent 32713b8 commit cc36ebb
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
67 changes: 67 additions & 0 deletions libs/common/src/vault/models/domain/ssh-key.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<bit-section [formGroup]="sshKeyForm">
<bit-section-header>
<h2 bitTypography="h5">
<h2 bitTypography="h6">
{{ "typeSSHKey" | i18n }}
</h2>
</bit-section-header>
Expand Down
2 changes: 1 addition & 1 deletion libs/vault/src/cipher-view/cipher-view.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</app-view-identity-sections>

<!-- SSHKEY SECTIONS -->
<app-sshkey-view *ngIf="cipher.sshKey" [sshKey]="cipher.sshKey"></app-sshkey-view>
<app-sshkey-view *ngIf="hasSshKey" [sshKey]="cipher.sshKey"></app-sshkey-view>

<!-- ADDITIONAL OPTIONS -->
<ng-container *ngIf="cipher.notes">
Expand Down
4 changes: 4 additions & 0 deletions libs/vault/src/cipher-view/cipher-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<bit-section-header>
<h2 bitTypography="h6">{{ "typeSSHKey" | i18n }}</h2>
</bit-section-header>
<bit-card>
<bit-card class="[&_bit-form-field:last-of-type]:tw-mb-0">
<bit-form-field>
<bit-label>{{ "sshPublicKey" | i18n }}</bit-label>
<input readonly bitInput [value]="sshKey.publicKey" aria-readonly="true" />
Expand Down

0 comments on commit cc36ebb

Please sign in to comment.