From 47292df1ffd84cbbecdf91137b2889cd98814eb7 Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Sat, 19 Jul 2025 11:45:28 +1000 Subject: [PATCH] Fix tests --- .../models/vault-filter.model.spec.ts | 14 +++++++++----- .../fido2/fido2-authenticator.service.spec.ts | 4 ++-- .../src/vault/models/domain/cipher.spec.ts | 18 +++++++++--------- .../src/vault/services/cipher.service.spec.ts | 4 ++-- .../vault/utils/cipher-view-like-utils.spec.ts | 5 +++-- ...netwrix-passwordsecure-csv-importer.spec.ts | 2 +- .../passsordxp/passwordxp-csv-importer.spec.ts | 2 +- .../item-details-section.component.spec.ts | 5 +++-- 8 files changed, 30 insertions(+), 24 deletions(-) diff --git a/libs/angular/src/vault/vault-filter/models/vault-filter.model.spec.ts b/libs/angular/src/vault/vault-filter/models/vault-filter.model.spec.ts index f5a49e25618..b2c0617fb44 100644 --- a/libs/angular/src/vault/vault-filter/models/vault-filter.model.spec.ts +++ b/libs/angular/src/vault/vault-filter/models/vault-filter.model.spec.ts @@ -1,3 +1,4 @@ +import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid"; import { CipherType } from "@bitwarden/common/vault/enums"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; @@ -119,14 +120,14 @@ describe("VaultFilter", () => { describe("given an organizational cipher (with organization and collections)", () => { const cipher = createCipher({ - organizationId: "organizationId", - collectionIds: ["collectionId", "anotherId"], + organizationId: "organizationId" as OrganizationId, + collectionIds: ["collectionId", "anotherId"] as CollectionId[], }); it("should return true when filter matches collection id", () => { const filterFunction = createFilterFunction({ selectedCollection: true, - selectedCollectionId: "collectionId", + selectedCollectionId: "collectionId" as CollectionId, }); const result = filterFunction(cipher); @@ -137,7 +138,7 @@ describe("VaultFilter", () => { it("should return false when filter does not match collection id", () => { const filterFunction = createFilterFunction({ selectedCollection: true, - selectedCollectionId: "nonMatchingId", + selectedCollectionId: "nonMatchingId" as CollectionId, }); const result = filterFunction(cipher); @@ -167,7 +168,10 @@ describe("VaultFilter", () => { }); describe("given an unassigned organizational cipher (with organization, without collection)", () => { - const cipher = createCipher({ organizationId: "organizationId", collectionIds: [] }); + const cipher = createCipher({ + organizationId: "organizationId" as OrganizationId, + collectionIds: [], + }); it("should return true when filtering for unassigned collection", () => { const filterFunction = createFilterFunction({ diff --git a/libs/common/src/platform/services/fido2/fido2-authenticator.service.spec.ts b/libs/common/src/platform/services/fido2/fido2-authenticator.service.spec.ts index fef64399b40..3644ea2c68a 100644 --- a/libs/common/src/platform/services/fido2/fido2-authenticator.service.spec.ts +++ b/libs/common/src/platform/services/fido2/fido2-authenticator.service.spec.ts @@ -5,7 +5,7 @@ import { BehaviorSubject, of } from "rxjs"; import { mockAccountServiceWith } from "../../../../spec"; import { Account } from "../../../auth/abstractions/account.service"; -import { CipherId, UserId } from "../../../types/guid"; +import { CipherId, OrganizationId, UserId } from "../../../types/guid"; import { CipherService, EncryptionContext } from "../../../vault/abstractions/cipher.service"; import { SyncService } from "../../../vault/abstractions/sync/sync.service.abstraction"; import { CipherRepromptType } from "../../../vault/enums/cipher-reprompt-type"; @@ -184,7 +184,7 @@ describe("FidoAuthenticatorService", () => { /** Devation: Organization ciphers are not checked against excluded credentials, even if the user has access to them. */ it("should not inform user of duplication when the excluded credential belongs to an organization", async () => { userInterfaceSession.informExcludedCredential.mockResolvedValue(); - excludedCipher.organizationId = "someOrganizationId"; + excludedCipher.organizationId = "someOrganizationId" as OrganizationId; try { await authenticator.makeCredential(params, windowReference); diff --git a/libs/common/src/vault/models/domain/cipher.spec.ts b/libs/common/src/vault/models/domain/cipher.spec.ts index 3ea8916a10b..78ff5da097a 100644 --- a/libs/common/src/vault/models/domain/cipher.spec.ts +++ b/libs/common/src/vault/models/domain/cipher.spec.ts @@ -18,7 +18,7 @@ import { EncString } from "../../../key-management/crypto/models/enc-string"; import { UriMatchStrategy } from "../../../models/domain/domain-service"; import { ContainerService } from "../../../platform/services/container.service"; import { InitializerKey } from "../../../platform/services/cryptography/initializer-key"; -import { UserId } from "../../../types/guid"; +import { OrganizationId, UserId } from "../../../types/guid"; import { CipherService } from "../../abstractions/cipher.service"; import { FieldType, LoginLinkedId, SecureNoteType } from "../../enums"; import { CipherRepromptType } from "../../enums/cipher-reprompt-type"; @@ -71,7 +71,7 @@ describe("Cipher DTO", () => { it("Decrypt should handle cipher key error", async () => { const cipher = new Cipher(); cipher.id = "id"; - cipher.organizationId = "orgId"; + cipher.organizationId = "orgId" as OrganizationId; cipher.folderId = "folderId"; cipher.edit = true; cipher.viewPassword = true; @@ -109,7 +109,7 @@ describe("Cipher DTO", () => { expect(cipherView).toMatchObject({ id: "id", - organizationId: "orgId", + organizationId: "orgId" as OrganizationId, folderId: "folderId", name: "[error: cannot decrypt]", type: 1, @@ -136,7 +136,7 @@ describe("Cipher DTO", () => { beforeEach(() => { cipherData = { id: "id", - organizationId: "orgId", + organizationId: "orgId" as OrganizationId, folderId: "folderId", edit: true, viewPassword: true, @@ -209,7 +209,7 @@ describe("Cipher DTO", () => { expect(cipher).toEqual({ initializerKey: InitializerKey.Cipher, id: "id", - organizationId: "orgId", + organizationId: "orgId" as OrganizationId, folderId: "folderId", name: { encryptedString: "EncryptedString", encryptionType: 0 }, notes: { encryptedString: "EncryptedString", encryptionType: 0 }, @@ -289,7 +289,7 @@ describe("Cipher DTO", () => { it("Decrypt", async () => { const cipher = new Cipher(); cipher.id = "id"; - cipher.organizationId = "orgId"; + cipher.organizationId = "orgId" as OrganizationId; cipher.folderId = "folderId"; cipher.edit = true; cipher.viewPassword = true; @@ -418,7 +418,7 @@ describe("Cipher DTO", () => { it("Decrypt", async () => { const cipher = new Cipher(); cipher.id = "id"; - cipher.organizationId = "orgId"; + cipher.organizationId = "orgId" as OrganizationId; cipher.folderId = "folderId"; cipher.edit = true; cipher.viewPassword = true; @@ -553,7 +553,7 @@ describe("Cipher DTO", () => { it("Decrypt", async () => { const cipher = new Cipher(); cipher.id = "id"; - cipher.organizationId = "orgId"; + cipher.organizationId = "orgId" as OrganizationId; cipher.folderId = "folderId"; cipher.edit = true; cipher.viewPassword = true; @@ -718,7 +718,7 @@ describe("Cipher DTO", () => { it("Decrypt", async () => { const cipher = new Cipher(); cipher.id = "id"; - cipher.organizationId = "orgId"; + cipher.organizationId = "orgId" as OrganizationId; cipher.folderId = "folderId"; cipher.edit = true; cipher.viewPassword = true; diff --git a/libs/common/src/vault/services/cipher.service.spec.ts b/libs/common/src/vault/services/cipher.service.spec.ts index bf30b78ca63..1bdda0a0316 100644 --- a/libs/common/src/vault/services/cipher.service.spec.ts +++ b/libs/common/src/vault/services/cipher.service.spec.ts @@ -23,7 +23,7 @@ import { Utils } from "../../platform/misc/utils"; import { EncArrayBuffer } from "../../platform/models/domain/enc-array-buffer"; import { SymmetricCryptoKey } from "../../platform/models/domain/symmetric-crypto-key"; import { ContainerService } from "../../platform/services/container.service"; -import { CipherId, UserId } from "../../types/guid"; +import { CipherId, CollectionId, UserId } from "../../types/guid"; import { CipherKey, OrgKey, UserKey } from "../../types/key"; import { CipherEncryptionService } from "../abstractions/cipher-encryption.service"; import { EncryptionContext } from "../abstractions/cipher.service"; @@ -190,7 +190,7 @@ describe("Cipher Service", () => { }); it("should call apiService.postCipherCreate if collectionsIds != null", async () => { - encryptionContext.cipher.collectionIds = ["123"]; + encryptionContext.cipher.collectionIds = ["123"] as CollectionId[]; const spy = jest .spyOn(apiService, "postCipherCreate") .mockImplementation(() => Promise.resolve(encryptionContext.cipher.toCipherData())); diff --git a/libs/common/src/vault/utils/cipher-view-like-utils.spec.ts b/libs/common/src/vault/utils/cipher-view-like-utils.spec.ts index f302340ef9e..6c9349f9233 100644 --- a/libs/common/src/vault/utils/cipher-view-like-utils.spec.ts +++ b/libs/common/src/vault/utils/cipher-view-like-utils.spec.ts @@ -1,5 +1,6 @@ import { CipherListView } from "@bitwarden/sdk-internal"; +import { OrganizationId } from "../../types/guid"; import { CipherType } from "../enums"; import { Attachment } from "../models/domain/attachment"; import { AttachmentView } from "../models/view/attachment.view"; @@ -142,7 +143,7 @@ describe("CipherViewLikeUtils", () => { }); it("returns false when the cipher is assigned to an organization and cannot be edited", () => { - cipherView.organizationId = "org-id"; + cipherView.organizationId = "org-id" as OrganizationId; cipherView.edit = false; cipherView.viewPassword = false; @@ -150,7 +151,7 @@ describe("CipherViewLikeUtils", () => { }); it("returns true when the cipher is assigned to an organization and can be edited", () => { - cipherView.organizationId = "org-id"; + cipherView.organizationId = "org-id" as OrganizationId; cipherView.edit = true; cipherView.viewPassword = true; diff --git a/libs/importer/src/importers/netwrix/netwrix-passwordsecure-csv-importer.spec.ts b/libs/importer/src/importers/netwrix/netwrix-passwordsecure-csv-importer.spec.ts index 93a6fd33421..b5479ce83cc 100644 --- a/libs/importer/src/importers/netwrix/netwrix-passwordsecure-csv-importer.spec.ts +++ b/libs/importer/src/importers/netwrix/netwrix-passwordsecure-csv-importer.spec.ts @@ -80,7 +80,7 @@ describe("Netwrix Password Secure CSV Importer", () => { }); it("should parse an item and create a collection when importing into an organization", async () => { - importer.organizationId = Utils.newGuid(); + importer.organizationId = Utils.newGuid() as OrganizationId; const result = await importer.parse(credentialsData); expect(result).not.toBeNull(); diff --git a/libs/importer/src/importers/passsordxp/passwordxp-csv-importer.spec.ts b/libs/importer/src/importers/passsordxp/passwordxp-csv-importer.spec.ts index 687558b2f59..67d90ef966a 100644 --- a/libs/importer/src/importers/passsordxp/passwordxp-csv-importer.spec.ts +++ b/libs/importer/src/importers/passsordxp/passwordxp-csv-importer.spec.ts @@ -147,7 +147,7 @@ describe("PasswordXPCsvImporter", () => { }); it("should convert folders to collections when importing into an organization", async () => { - importer.organizationId = "someOrg"; + importer.organizationId = "someOrg" as OrganizationId; const result: ImportResult = await importer.parse(withFolders); expect(result.success).toBe(true); expect(result.ciphers.length).toBe(5); diff --git a/libs/vault/src/cipher-form/components/item-details/item-details-section.component.spec.ts b/libs/vault/src/cipher-form/components/item-details/item-details-section.component.spec.ts index db8e2007c61..3b55b0063b7 100644 --- a/libs/vault/src/cipher-form/components/item-details/item-details-section.component.spec.ts +++ b/libs/vault/src/cipher-form/components/item-details/item-details-section.component.spec.ts @@ -14,6 +14,7 @@ import { Policy } from "@bitwarden/common/admin-console/models/domain/policy"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; +import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid"; import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view"; import { SelectComponent } from "@bitwarden/components"; @@ -33,9 +34,9 @@ const createMockCollection = ( canEdit = true, ): CollectionView => { return { - id, + id: id as CollectionId, name, - organizationId, + organizationId: organizationId as OrganizationId, externalId: "", readOnly, hidePasswords: false,