mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
Convert to function's
Co-authored-by: Andreas Coroiu <acoroiu@bitwarden.com>
This commit is contained in:
@@ -350,13 +350,12 @@ describe("cryptoService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("userPrivateKey$", () => {
|
describe("userPrivateKey$", () => {
|
||||||
const setupKeys = ({
|
type SetupKeysParams = {
|
||||||
makeMasterKey,
|
|
||||||
makeUserKey,
|
|
||||||
}: {
|
|
||||||
makeMasterKey: boolean;
|
makeMasterKey: boolean;
|
||||||
makeUserKey: boolean;
|
makeUserKey: boolean;
|
||||||
}): [UserKey, MasterKey] => {
|
};
|
||||||
|
|
||||||
|
function setupKeys({ makeMasterKey, makeUserKey }: SetupKeysParams): [UserKey, MasterKey] {
|
||||||
const userKeyState = stateProvider.singleUser.getFake(mockUserId, USER_KEY);
|
const userKeyState = stateProvider.singleUser.getFake(mockUserId, USER_KEY);
|
||||||
const fakeMasterKey = makeMasterKey ? makeSymmetricCryptoKey<MasterKey>(64) : null;
|
const fakeMasterKey = makeMasterKey ? makeSymmetricCryptoKey<MasterKey>(64) : null;
|
||||||
masterPasswordService.masterKeySubject.next(fakeMasterKey);
|
masterPasswordService.masterKeySubject.next(fakeMasterKey);
|
||||||
@@ -364,7 +363,7 @@ describe("cryptoService", () => {
|
|||||||
const fakeUserKey = makeUserKey ? makeSymmetricCryptoKey<UserKey>(64) : null;
|
const fakeUserKey = makeUserKey ? makeSymmetricCryptoKey<UserKey>(64) : null;
|
||||||
userKeyState.stateSubject.next([mockUserId, fakeUserKey]);
|
userKeyState.stateSubject.next([mockUserId, fakeUserKey]);
|
||||||
return [fakeUserKey, fakeMasterKey];
|
return [fakeUserKey, fakeMasterKey];
|
||||||
};
|
}
|
||||||
|
|
||||||
it("will return users decrypted private key when legacy support set to %legacySupport and user hasUserKey = $hasUserKey and user hasMasterKey = $hasMasterKey", async () => {
|
it("will return users decrypted private key when legacy support set to %legacySupport and user hasUserKey = $hasUserKey and user hasMasterKey = $hasMasterKey", async () => {
|
||||||
const [userKey] = setupKeys({
|
const [userKey] = setupKeys({
|
||||||
@@ -426,7 +425,7 @@ describe("cryptoService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("cipherDecryptionKeys$", () => {
|
describe("cipherDecryptionKeys$", () => {
|
||||||
const fakePrivateKeyDecryption = (encryptedPrivateKey: Encrypted, key: SymmetricCryptoKey) => {
|
function fakePrivateKeyDecryption(encryptedPrivateKey: Encrypted, key: SymmetricCryptoKey) {
|
||||||
const output = new Uint8Array(64);
|
const output = new Uint8Array(64);
|
||||||
output.set(encryptedPrivateKey.dataBytes);
|
output.set(encryptedPrivateKey.dataBytes);
|
||||||
output.set(
|
output.set(
|
||||||
@@ -434,9 +433,9 @@ describe("cryptoService", () => {
|
|||||||
encryptedPrivateKey.dataBytes.length,
|
encryptedPrivateKey.dataBytes.length,
|
||||||
);
|
);
|
||||||
return output;
|
return output;
|
||||||
};
|
}
|
||||||
|
|
||||||
const fakeOrgKeyDecryption = (encryptedString: EncString, userPrivateKey: Uint8Array) => {
|
function fakeOrgKeyDecryption(encryptedString: EncString, userPrivateKey: Uint8Array) {
|
||||||
const output = new Uint8Array(64);
|
const output = new Uint8Array(64);
|
||||||
output.set(encryptedString.dataBytes);
|
output.set(encryptedString.dataBytes);
|
||||||
output.set(
|
output.set(
|
||||||
@@ -444,18 +443,18 @@ describe("cryptoService", () => {
|
|||||||
encryptedString.dataBytes.length,
|
encryptedString.dataBytes.length,
|
||||||
);
|
);
|
||||||
return output;
|
return output;
|
||||||
};
|
}
|
||||||
|
|
||||||
const org1Id = "org1" as OrganizationId;
|
const org1Id = "org1" as OrganizationId;
|
||||||
|
|
||||||
const updateKeys = (
|
type UpdateKeysParams = {
|
||||||
keys: Partial<{
|
userKey: UserKey;
|
||||||
userKey: UserKey;
|
encryptedPrivateKey: EncString;
|
||||||
encryptedPrivateKey: EncString;
|
orgKeys: Record<string, EncryptedOrganizationKeyData>;
|
||||||
orgKeys: Record<string, EncryptedOrganizationKeyData>;
|
providerKeys: Record<string, EncryptedString>;
|
||||||
providerKeys: Record<string, EncryptedString>;
|
};
|
||||||
}> = {},
|
|
||||||
) => {
|
function updateKeys(keys: Partial<UpdateKeysParams> = {}) {
|
||||||
if ("userKey" in keys) {
|
if ("userKey" in keys) {
|
||||||
const userKeyState = stateProvider.singleUser.getFake(mockUserId, USER_KEY);
|
const userKeyState = stateProvider.singleUser.getFake(mockUserId, USER_KEY);
|
||||||
userKeyState.stateSubject.next([mockUserId, keys.userKey]);
|
userKeyState.stateSubject.next([mockUserId, keys.userKey]);
|
||||||
@@ -496,7 +495,7 @@ describe("cryptoService", () => {
|
|||||||
encryptService.rsaDecrypt.mockImplementation((data, privateKey) => {
|
encryptService.rsaDecrypt.mockImplementation((data, privateKey) => {
|
||||||
return Promise.resolve(fakeOrgKeyDecryption(data, privateKey));
|
return Promise.resolve(fakeOrgKeyDecryption(data, privateKey));
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
it("returns decryption keys when there are not org or provider keys set", async () => {
|
it("returns decryption keys when there are not org or provider keys set", async () => {
|
||||||
updateKeys({
|
updateKeys({
|
||||||
|
|||||||
Reference in New Issue
Block a user