Fix issue with sync entry being set and get differently.

master
Tom Hacohen 7 years ago
parent 9c8df0a854
commit 2507dfd5b3

@ -75,7 +75,7 @@ it('Journal Entry sync', async () => {
let entries = await entryManager.list(null);
expect(entries.length).toBe(0);
const syncEntry = new EteSync.SyncEntry({content: 'bla'});
const syncEntry = new EteSync.SyncEntry({action: 'ADD', content: 'bla'});
let prevUid = null;
let entry = new EteSync.Entry();
entry.setSyncEntry(cryptoManager, syncEntry, prevUid);
@ -84,6 +84,12 @@ it('Journal Entry sync', async () => {
await expect(entryManager.create(entries, prevUid)).resolves.toBeDefined();
prevUid = entry.uid;
// Verify we get back what we sent
entries = await entryManager.list(null);
expect(entries[0].serialize()).toEqual(entry.serialize());
syncEntry.uid = entries[0].uid;
expect(entries[0].getSyncEntry(cryptoManager, null)).toEqual(syncEntry);
let entry2 = new EteSync.Entry();
entry2.setSyncEntry(cryptoManager, syncEntry, prevUid);

@ -73,7 +73,7 @@ interface BaseJson {
class BaseJournal<T extends BaseJson> {
protected _json: T;
protected _encrypted: byte[];
protected _content?: string;
protected _content?: object;
constructor() {
this._json = {} as any;
@ -131,8 +131,8 @@ export class Journal extends BaseJournal<JournalJson> {
setInfo(cryptoManager: CryptoManager, info: CollectionInfo) {
this._json.uid = info.uid;
this._content = JSON.stringify(info);
const encrypted = cryptoManager.encrypt(this._content);
this._content = info;
const encrypted = cryptoManager.encrypt(JSON.stringify(this._content));
this._encrypted = this.calculateHmac(cryptoManager, encrypted).concat(encrypted);
}
@ -185,8 +185,8 @@ export interface EntryJson extends BaseJson {
export class Entry extends BaseJournal<EntryJson> {
setSyncEntry(cryptoManager: CryptoManager, info: SyncEntry, prevUid: string | null) {
this._content = JSON.stringify(info);
this._encrypted = cryptoManager.encrypt(this._content);
this._content = info;
this._encrypted = cryptoManager.encrypt(JSON.stringify(this._content));
this._json.uid = hmacToHex(this.calculateHmac(cryptoManager, this._encrypted, prevUid));
}

Loading…
Cancel
Save