Persist tracked event ID hash using localStorage

This commit is contained in:
Luke Barnard 2018-06-15 15:26:53 +01:00
parent 011154396c
commit f08274585e
3 changed files with 45 additions and 4 deletions

View file

@ -150,4 +150,34 @@ describe.only('DecryptionFailureTracker', function() {
done();
});
it('should not track a failure for an event that was tracked in a previous session', (done) => {
// This test uses localStorage, clear it beforehand
localStorage.clear();
const decryptedEvent = createFailedDecryptionEvent();
const failures = [];
const tracker = new DecryptionFailureTracker((failure) => failures.push(failure));
// Indicate decryption
tracker.eventDecrypted(decryptedEvent);
// Pretend "now" is Infinity
// NB: This saves to localStorage specific to DFT
tracker.checkFailures(Infinity);
tracker.trackFailure();
// Simulate the browser refreshing by destroying tracker and creating a new tracker
const secondTracker = new DecryptionFailureTracker((failure) => failures.push(failure));
secondTracker.loadTrackedEventHashMap();
secondTracker.eventDecrypted(decryptedEvent);
secondTracker.checkFailures(Infinity);
secondTracker.trackFailure();
expect(failures.length).toBe(1, 'should track a single failure per event per session, got ' + failures.length);
done();
});
});