aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/tests/harness
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/tests/harness')
-rw-r--r--packages/meshbay-hub/tests/harness/chat_send_probe.py45
1 files changed, 43 insertions, 2 deletions
diff --git a/packages/meshbay-hub/tests/harness/chat_send_probe.py b/packages/meshbay-hub/tests/harness/chat_send_probe.py
index 2df12e3..b6dd957 100644
--- a/packages/meshbay-hub/tests/harness/chat_send_probe.py
+++ b/packages/meshbay-hub/tests/harness/chat_send_probe.py
@@ -178,6 +178,12 @@ function makeTransport(name, chatReply) {
// Sealed under the group key, as `_do_chat_keys_req` sends it.
answer({ type: 'chat_keys_resp', v: '2.0', group_id: tp._groupId,
nonce: hex('__KEYS_NONCE_HEX__'), ct: hex('__KEYS_CT_HEX__') });
+ } else if (obj.type === 'device_hello') {
+ // What `_do_device_hello` answers once the signature checks out. Driving
+ // the real `_announceDevice` through it is the point: the composer has to
+ // come back from the code that actually re-identifies the device after a
+ // reconnect, not from a test poking `devicePk`.
+ answer({ type: 'device_hello_ack', v: '2.0' });
} else if (obj.type === 'chat_msg') {
// Recorded so the test can assert what actually left the browser, rather
// than trusting that a composer which accepted the text sealed it.
@@ -297,8 +303,27 @@ async function runScenario(name, chatReply, duringSession) {
out.scenarios.push(await runScenario(
'reconnect', { type: 'ack', v: '0.14' },
async (tp, snap) => {
- tp._setDevicePk('', 'new connection');
+ // The real `connect()`, called the way `_reconnectLoop` calls it. It
+ // fails — there is no hub here to sign an offer with — and that is what
+ // makes the point: the identity is already gone by then, because
+ // connect() drops it before it touches the network. Nothing about this
+ // step is simulated, and the clear is not poked in by the test.
+ await tp.connect('node-1', 'token', tp._groupId, tp._gekRaw,
+ tp._sessionKeys, null, 'me', 'user-me').then(
+ () => log.push('reconnect: connect() unexpectedly succeeded'),
+ (e) => log.push('reconnect: connect() stopped at signaling, as expected: '
+ + (e && e.message || e)));
+ // The dead peer connection would otherwise reach "failed" and start a
+ // real reconnect loop of its own, against a hub that is not there.
+ tp._closed = true;
+ try { if (tp._pc) tp._pc.close(); } catch (e) { /* already gone */ }
+ // After the close event, not before: the real channel's `onclose` is
+ // delivered as its own task and sets `_connected` back to false, so a
+ // stand-in installed ahead of it is undone a tick later.
await wait(100);
+ tp._channel = { readyState: 'open', send() {} };
+ tp._connected = true;
+ await wait(50);
snap('device identity cleared');
// A live message arrives — the ordinary thing that re-renders this
// panel, and the step that made the old defect permanent. The composer
@@ -312,7 +337,13 @@ async function runScenario(name, chatReply, duringSession) {
}
await wait(100);
snap('a message arrived meanwhile');
- tp._setDevicePk(DEVICE_PK_B64, 'device_hello_ack');
+ // What the handshake leaves behind, and all `_announceDevice` needs of
+ // it: connect() above already set `_userId`.
+ tp._nonceNode = hex('00'.repeat(32));
+ tp.nodePk = 'a-node-public-key';
+ const pk = await tp._announceDevice();
+ log.push('reconnect: _announceDevice settled on '
+ + (pk === DEVICE_PK_B64 ? 'the device key' : JSON.stringify(pk)));
await wait(100);
snap('device identity restored');
}));
@@ -326,6 +357,16 @@ class H(http.server.BaseHTTPRequestHandler):
pass
def do_POST(self):
+ # Only the measurement. The `reconnect` scenario drives the real
+ # `connect()`, which POSTs its offer to the hub's signaling endpoint --
+ # there is no hub here, and answering that with 204 both swallowed the
+ # measurement and put the machine's own SDP (public address included)
+ # into the probe's output. It gets a 404, which is what makes connect()
+ # stop where the scenario needs it to.
+ if self.path != "/log":
+ self.send_response(404)
+ self.end_headers()
+ return
RECORDS.append(json.loads(
self.rfile.read(int(self.headers["Content-Length"])).decode()))
self.send_response(204)