From d172dfe2f6b0cbd8bed456a00e9aa3f0483e7e7a Mon Sep 17 00:00:00 2001 From: Robyn MacCallum Date: Thu, 7 Sep 2023 10:31:20 -0400 Subject: [PATCH] Only call postCipherAdmin if the orgId on a cipher is not null (#6209) --- .../src/vault/services/cipher.service.spec.ts | 13 ++++++++++++- libs/common/src/vault/services/cipher.service.ts | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/libs/common/src/vault/services/cipher.service.spec.ts b/libs/common/src/vault/services/cipher.service.spec.ts index daaa6fbc91..4df3d202ff 100644 --- a/libs/common/src/vault/services/cipher.service.spec.ts +++ b/libs/common/src/vault/services/cipher.service.spec.ts @@ -134,7 +134,7 @@ describe("Cipher Service", () => { }); describe("createWithServer()", () => { - it("should call apiService.postCipherAdmin when orgAdmin param is true", async () => { + it("should call apiService.postCipherAdmin when orgAdmin param is true and the cipher orgId != null", async () => { const spy = jest .spyOn(apiService, "postCipherAdmin") .mockImplementation(() => Promise.resolve(cipherObj)); @@ -144,6 +144,17 @@ describe("Cipher Service", () => { expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalledWith(expectedObj); }); + it("should call apiService.postCipher when orgAdmin param is true and the cipher orgId is null", async () => { + cipherObj.organizationId = null; + const spy = jest + .spyOn(apiService, "postCipher") + .mockImplementation(() => Promise.resolve(cipherObj)); + cipherService.createWithServer(cipherObj, true); + const expectedObj = new CipherRequest(cipherObj); + + expect(spy).toHaveBeenCalled(); + expect(spy).toHaveBeenCalledWith(expectedObj); + }); it("should call apiService.postCipherCreate if collectionsIds != null", async () => { cipherObj.collectionIds = ["123"]; diff --git a/libs/common/src/vault/services/cipher.service.ts b/libs/common/src/vault/services/cipher.service.ts index 52ca151dc5..0bae9a607a 100644 --- a/libs/common/src/vault/services/cipher.service.ts +++ b/libs/common/src/vault/services/cipher.service.ts @@ -525,7 +525,7 @@ export class CipherService implements CipherServiceAbstraction { async createWithServer(cipher: Cipher, orgAdmin?: boolean): Promise { let response: CipherResponse; - if (orgAdmin) { + if (orgAdmin && cipher.organizationId != null) { const request = new CipherCreateRequest(cipher); response = await this.apiService.postCipherAdmin(request); } else if (cipher.collectionIds != null) {