Only call postCipherAdmin if the orgId on a cipher is not null (#6209)

This commit is contained in:
Robyn MacCallum 2023-09-07 10:31:20 -04:00 committed by GitHub
parent 2d73f754bf
commit d172dfe2f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -134,7 +134,7 @@ describe("Cipher Service", () => {
}); });
describe("createWithServer()", () => { 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 const spy = jest
.spyOn(apiService, "postCipherAdmin") .spyOn(apiService, "postCipherAdmin")
.mockImplementation(() => Promise.resolve<any>(cipherObj)); .mockImplementation(() => Promise.resolve<any>(cipherObj));
@ -144,6 +144,17 @@ describe("Cipher Service", () => {
expect(spy).toHaveBeenCalled(); expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith(expectedObj); 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<any>(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 () => { it("should call apiService.postCipherCreate if collectionsIds != null", async () => {
cipherObj.collectionIds = ["123"]; cipherObj.collectionIds = ["123"];

View File

@ -525,7 +525,7 @@ export class CipherService implements CipherServiceAbstraction {
async createWithServer(cipher: Cipher, orgAdmin?: boolean): Promise<any> { async createWithServer(cipher: Cipher, orgAdmin?: boolean): Promise<any> {
let response: CipherResponse; let response: CipherResponse;
if (orgAdmin) { if (orgAdmin && cipher.organizationId != null) {
const request = new CipherCreateRequest(cipher); const request = new CipherCreateRequest(cipher);
response = await this.apiService.postCipherAdmin(request); response = await this.apiService.postCipherAdmin(request);
} else if (cipher.collectionIds != null) { } else if (cipher.collectionIds != null) {