-
-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move Device Tracking Data to Crypto Store #594
Merged
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
83e4aa2
Initial attempt at device tracking -> indexeddb
dbkr 29d44f8
delay saving so we can batch multiple operations
dbkr 60052f5
Add localstorage & memory device data stores
dbkr 2cdb010
Fix lint
dbkr 6c1087e
Migrate from session store
dbkr a94f3c7
Fix migration
dbkr 36d7d33
Null fix & lint
dbkr 110f43a
Make DeviceList test pass
dbkr 27d28b8
More test fixing
dbkr 0174c56
Make tests pass, finally.
dbkr 5a0997d
lint
dbkr 585ea14
more lint
dbkr 5bab864
Fix device tracking with initial /sync
dbkr 461acbc
More test fixing
dbkr fb29da4
Update the catchingup flag
dbkr ea6974f
Return null if device data isn't set
dbkr 8b649ce
All the copyrights
dbkr 074cfb7
Add more comments
dbkr 4fbf4f1
Hopefully address PR feedback
dbkr 8c2645c
Comment typo
dbkr 470bd23
Add new devices as we get them
dbkr c3bede5
Fux lying comment
dbkr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
/* | ||
Copyright 2017 Vector Creations Ltd | ||
Copyright 2018 New Vector Ltd | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import DeviceList from '../../../lib/crypto/DeviceList'; | ||
import MockStorageApi from '../../MockStorageApi'; | ||
import WebStorageSessionStore from '../../../lib/store/session/webstorage'; | ||
import MemoryCryptoStore from '../../../lib/crypto/store/memory-crypto-store.js'; | ||
import testUtils from '../../test-utils'; | ||
import utils from '../../../lib/utils'; | ||
|
||
|
@@ -40,13 +58,15 @@ const signedDeviceList = { | |
describe('DeviceList', function() { | ||
let downloadSpy; | ||
let sessionStore; | ||
let cryptoStore; | ||
|
||
beforeEach(function() { | ||
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this | ||
|
||
downloadSpy = expect.createSpy(); | ||
const mockStorage = new MockStorageApi(); | ||
sessionStore = new WebStorageSessionStore(mockStorage); | ||
cryptoStore = new MemoryCryptoStore(); | ||
}); | ||
|
||
function createTestDeviceList() { | ||
|
@@ -56,7 +76,7 @@ describe('DeviceList', function() { | |
const mockOlm = { | ||
verifySignature: function(key, message, signature) {}, | ||
}; | ||
return new DeviceList(baseApis, sessionStore, mockOlm); | ||
return new DeviceList(baseApis, cryptoStore, sessionStore, mockOlm); | ||
} | ||
|
||
it("should successfully download and store device keys", function() { | ||
|
@@ -72,7 +92,7 @@ describe('DeviceList', function() { | |
queryDefer1.resolve(utils.deepCopy(signedDeviceList)); | ||
|
||
return prom1.then(() => { | ||
const storedKeys = sessionStore.getEndToEndDevicesForUser('@test1:sw1v.org'); | ||
const storedKeys = dl.getRawStoredDevicesForUser('@test1:sw1v.org'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can pull the stored key straight out of the DeviceList now rather than inspecting the backing storage, which I think makes it more of a unit test. |
||
expect(Object.keys(storedKeys)).toEqual(['HGKAWHRVJQ']); | ||
}); | ||
}); | ||
|
@@ -97,14 +117,15 @@ describe('DeviceList', function() { | |
dl.invalidateUserDeviceList('@test1:sw1v.org'); | ||
dl.refreshOutdatedDeviceLists(); | ||
|
||
// the first request completes | ||
queryDefer1.resolve({ | ||
device_keys: { | ||
'@test1:sw1v.org': {}, | ||
}, | ||
}); | ||
|
||
return prom1.then(() => { | ||
dl.saveIfDirty().then(() => { | ||
// the first request completes | ||
queryDefer1.resolve({ | ||
device_keys: { | ||
'@test1:sw1v.org': {}, | ||
}, | ||
}); | ||
return prom1; | ||
}).then(() => { | ||
// uh-oh; user restarts before second request completes. The new instance | ||
// should know we never got a complete device list. | ||
console.log("Creating new devicelist to simulate app reload"); | ||
|
@@ -121,7 +142,7 @@ describe('DeviceList', function() { | |
// allow promise chain to complete | ||
return prom3; | ||
}).then(() => { | ||
const storedKeys = sessionStore.getEndToEndDevicesForUser('@test1:sw1v.org'); | ||
const storedKeys = dl.getRawStoredDevicesForUser('@test1:sw1v.org'); | ||
expect(Object.keys(storedKeys)).toEqual(['HGKAWHRVJQ']); | ||
}); | ||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the test changes are the same pattern: add the explicit save calls and wait on them, and change the fetch from the store to the new callback based API.