Skip to content

Commit

Permalink
All: Fixed issue that could cause application to needlessly lock the …
Browse files Browse the repository at this point in the history
…sync target
  • Loading branch information
laurent22 committed Nov 10, 2021
1 parent 7c3785e commit 0de6e9e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/lib/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"css": "^3.0.0",
"diff-match-patch": "^1.0.4",
"es6-promise-pool": "^2.5.0",
"fast-deep-equal": "^3.1.3",
"file-uri-to-path": "^1.0.0",
"follow-redirects": "^1.2.4",
"form-data": "^2.1.4",
Expand Down
60 changes: 59 additions & 1 deletion packages/lib/services/synchronizer/syncInfoUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterAllCleanUp, setupDatabaseAndSynchronizer, switchClient, encryptionService } from '../../testing/test-utils';
import MasterKey from '../../models/MasterKey';
import { masterKeyEnabled, setMasterKeyEnabled } from './syncInfoUtils';
import { masterKeyEnabled, setMasterKeyEnabled, SyncInfo, syncInfoEquals } from './syncInfoUtils';

describe('syncInfoUtils', function() {

Expand Down Expand Up @@ -34,4 +34,62 @@ describe('syncInfoUtils', function() {
expect(masterKeyEnabled(await MasterKey.load(mk2.id))).toBe(false);
});

it('should tell if two sync info are equal', async () => {
{
const syncInfo1 = new SyncInfo();
const syncInfo2 = new SyncInfo();
expect(syncInfoEquals(syncInfo1, syncInfo2)).toBe(true);
}

{
const syncInfo1 = new SyncInfo();
syncInfo1.masterKeys = [{
id: 'id',
content: 'content',
}];

const syncInfo2 = new SyncInfo();
syncInfo2.masterKeys = [{
id: 'id',
content: 'different',
}];

expect(syncInfoEquals(syncInfo1, syncInfo2)).toBe(false);
}

{
const syncInfo1 = new SyncInfo();
syncInfo1.masterKeys = [{
id: 'id',
content: 'content',
}];

const syncInfo2 = new SyncInfo();
syncInfo2.masterKeys = [{
id: 'id',
content: 'content',
}];

expect(syncInfoEquals(syncInfo1, syncInfo2)).toBe(true);
}

{
// Should disregard object key order

const syncInfo1 = new SyncInfo();
syncInfo1.masterKeys = [{
content: 'content',
id: 'id',
}];

const syncInfo2 = new SyncInfo();
syncInfo2.masterKeys = [{
id: 'id',
content: 'content',
}];

expect(syncInfoEquals(syncInfo1, syncInfo2)).toBe(true);
}
});

});
3 changes: 2 additions & 1 deletion packages/lib/services/synchronizer/syncInfoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Setting from '../../models/Setting';
import { State } from '../../reducer';
import { PublicPrivateKeyPair } from '../e2ee/ppk';
import { MasterKeyEntity } from '../e2ee/types';
const fastDeepEqual = require('fast-deep-equal');

export interface SyncInfoValueBoolean {
value: boolean;
Expand Down Expand Up @@ -113,7 +114,7 @@ export function mergeSyncInfos(s1: SyncInfo, s2: SyncInfo): SyncInfo {
}

export function syncInfoEquals(s1: SyncInfo, s2: SyncInfo): boolean {
return s1.serialize() === s2.serialize();
return fastDeepEqual(s1.toObject(), s2.toObject());
}

export class SyncInfo {
Expand Down

0 comments on commit 0de6e9e

Please sign in to comment.