Send party_id on events and check the party_id of incoming events matches
Includes a basic test to assert that it actually does: we should
build out a decent test suite for calls as there's a lot of edge-case
functionality that can break and slip through the cracks (eg. glare).
This is a start.
Fixes https://github.com/matrix-org/matrix-js-sdk/issues/1511
The earlier commit, d3ce0cb82f3ee76a22ed8b80db18f679c01f8525, has most of the juicy details on this. In addition to d3ce's changes, we also:
* Use `TestClient` in many integration tests due to subtle behaviour changes in imports when switching to ES6. Namely the behaviour where setting the request function is less reliable in the way we did it, but `TestClient` is very reliable.
* We now use the Olm loader more often to avoid having to maintain so much duplicate code. This makes the imports slightly easier to read.
To finish all pending flushes between tests. This stops the unit
tests from hanging on node 11 when run in certain combinations.
Requires https://github.com/matrix-org/matrix-mock-request/pull/6
(so will need a release of matrix-mock-request before merging)
Mostly making tests aware of new storage format or making them
force it to be written. Also some bugfixes like we didn't json
encode some things in the localstorage store and we didn't
correctly check the promise when requesting device data saves.
When we no longer share any rooms with a given user, the server will stop
sending us updates on their device list, and will (once synapse is updated)
send us a notification of that fact via the 'left' field in the device_lists
field in /sync, or the response from /keys/changes.
Add lots of calls to `syncPromise` to cope with the fact that sync responses
are now handled asynchronously, which makes them prone to races otherwise.
Also a quick sanity-check in crypto to make one of the test failures less
cryptic.
Once we switch to bluebird, suddenly a load of timing issues come out of the
woodwork. Basically, we need to try harder when flushing requests. Bump to
matrix-mock-request 1.1.0, which provides `flushAllExpected`, and waits for
requests to arrive when given a `numToFlush`; then use `flushAllExpected` in
various places to make the tests more resilient.
There is a common pattern in the tests which is, when we want to mock a /sync,
to flush it, and then, in the next tick of the promise loop, to wait for the
syncing event. However, this is racy: there is no guarantee that the syncing
event will not happen before the next tick of the promise loop.
Instead, we should set the expectation of the syncing event, then do the flush.
(Technically we only need to wait for the syncing event, but by waiting for
both we'll catch any errors thrown by the flush, and make sure we don't have
any outstanding flushes before proceeding).
Add a utility method to TestClient to do the above, and use it where we have a
TestClient.
(Also fixes a couple of other minor buglets in the tests).
Delay the upload of one-time keys until we have received a sync *without any
to-device messages*. Doing so means that we can try to avoid throwing away our
private keys just before we receive the to-device messages which use them.
Once we've decided to go ahead and upload them, we keep uploading them in
batches of 5 until we get to the desired 50 keys on the server. We then
periodically check that there are still enough on the server.
89ced198 added some code which flagged our own device list as in need of an
update. However, 8d502743 then added code such that we invalidate *all* members
of e2e rooms on the first initialsync - which should include ourselves. We can
therefore remove the redundant special-case, which mostly serves to simplify
the tests.
Much of this transformation has been done automatically:
* add expect import to each file
* replace `not.to` with `toNot`
* replace `to[Not]Be{Undefined,Null}` with equivalents
* replace `jasmine.createSpy(...)` with `except.createSpy`, and `andCallFake`
with `andCall`
Also:
* replace `jasmine.createSpyObj` with manual alternatives
* replace `jasmine.Clock` with `lolex`