VulpesOS/gaia/apps/sharedtest/test/unit/sync/sync-engine/fxsyncwebcrypto-mock.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

51 lines
1.6 KiB
JavaScript
Executable file

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
/* global SynctoServerFixture */
/* exported FxSyncWebCrypto */
requireApp('sharedtest/test/unit/sync/fixtures/synctoserver.js');
var FxSyncWebCrypto = function() {};
FxSyncWebCrypto.prototype = {
setKeys: function(kB, cryptoKeys) {
this.shouldWork = true;
if (kB !== SynctoServerFixture.syncEngineOptions.kB) {
this.shouldWork = false;
}
var correctCryptoKeys = JSON.parse(
SynctoServerFixture.remoteData.crypto.payload);
if (cryptoKeys.ciphertext !== correctCryptoKeys.ciphertext ||
cryptoKeys.IV !== correctCryptoKeys.IV ||
cryptoKeys.hmac !== correctCryptoKeys.hmac) {
this.shouldWork = false;
}
if (this.shouldWork) {
this.bulkKeyBundle = true;
return Promise.resolve();
}
return Promise.reject(`SyncKeys hmac could not be verified with current mai\
n key`);
},
encrypt: function(payload) {
if (this.shouldWork) {
return Promise.resolve({ mockEncrypted: JSON.stringify(payload) });
}
return Promise.reject();
},
decrypt: function(record) {
var decryptablePayload = JSON.parse(
SynctoServerFixture.remoteData.history.payload);
if (this.shouldWork &&
record.ciphertext === decryptablePayload.ciphertext &&
record.IV === decryptablePayload.IV &&
record.hmac === decryptablePayload.hmac) {
return Promise.resolve(
SynctoServerFixture.historyEntryDec.payload);
}
return Promise.reject(new Error(
'payload.ciphertext is not a Base64 string'));
}
};