2021-06-25 14:51:36 +01:00
|
|
|
import Setting from '../models/Setting';
|
2021-06-26 22:13:38 +01:00
|
|
|
import { setupDatabaseAndSynchronizer, switchClient } from '../testing/test-utils';
|
2021-06-25 14:51:36 +01:00
|
|
|
import MigrationService from './MigrationService';
|
2021-06-26 22:13:38 +01:00
|
|
|
import { SyncTargetInfo } from './synchronizer/syncTargetInfoUtils';
|
2021-06-25 14:51:36 +01:00
|
|
|
|
|
|
|
|
function migrationService() {
|
|
|
|
|
return new MigrationService();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe('MigrationService', function() {
|
|
|
|
|
beforeEach(async (done) => {
|
|
|
|
|
await setupDatabaseAndSynchronizer(1);
|
|
|
|
|
await switchClient(1);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
2021-06-26 22:13:38 +01:00
|
|
|
// Hard to test how it would migrate master keys since the code to save them
|
|
|
|
|
// to the database no longer exists.
|
2021-06-25 14:51:36 +01:00
|
|
|
|
2021-06-26 22:13:38 +01:00
|
|
|
// it('should migrate to v40 - with keys', async () => {
|
|
|
|
|
// const startTime = Date.now();
|
2021-06-25 14:51:36 +01:00
|
|
|
|
2021-06-26 22:13:38 +01:00
|
|
|
// const mk1 = await MasterKey.save(await encryptionService().generateMasterKey('1'));
|
|
|
|
|
// const mk2 = await MasterKey.save(await encryptionService().generateMasterKey('2'));
|
|
|
|
|
// Setting.setValue('encryption.enabled', true);
|
|
|
|
|
// Setting.setValue('encryption.activeMasterKeyId', mk1.id);
|
2021-06-25 14:51:36 +01:00
|
|
|
|
2021-06-26 22:13:38 +01:00
|
|
|
// await migrationService().runScript(40, MasterKey.db());
|
|
|
|
|
|
|
|
|
|
// const info: SyncTargetInfo = JSON.parse(Setting.value('sync.info'));
|
|
|
|
|
// expect(info.e2ee).toBe(true);
|
|
|
|
|
// expect(info.activeMasterKeyId).toBe(mk1.id);
|
|
|
|
|
// expect(info.version).toBe(0);
|
|
|
|
|
// expect(Object.keys(info.masterKeys).sort()).toEqual([mk1.id, mk2.id].sort());
|
|
|
|
|
// expect(info.updatedTime).toBeGreaterThanOrEqual(startTime);
|
|
|
|
|
// });
|
2021-06-25 14:51:36 +01:00
|
|
|
|
|
|
|
|
it('should migrate to v40 - empty', async () => {
|
|
|
|
|
const startTime = Date.now();
|
|
|
|
|
|
|
|
|
|
await migrationService().runScript(40);
|
|
|
|
|
|
|
|
|
|
const info: SyncTargetInfo = JSON.parse(Setting.value('sync.info'));
|
|
|
|
|
expect(info.e2ee).toBe(false);
|
|
|
|
|
expect(info.activeMasterKeyId).toBe('');
|
2021-06-26 22:13:38 +01:00
|
|
|
expect(info.version).toBe(0);
|
2021-06-25 14:51:36 +01:00
|
|
|
expect(Object.keys(info.masterKeys)).toEqual([]);
|
|
|
|
|
expect(info.updatedTime).toBeGreaterThanOrEqual(startTime);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|