Improve tests

This commit is contained in:
Schluffe committed 2026-10-28 22:24:24 +01:00
1 parent 8f82700736
commit ae871a2647
2 files changed
+118 -825

No files matched your search

+75 -825
View File
File diff suppressed because it is too large. Load diff
+43
View File
@@ -1239,9 +1239,14 @@ describe('tracker signaling', () => {
await until(() => FakePeer.all[0]?.channels.length);
FakePeer.all[0]!.channels[0]!.drop = (data) => typeof data === 'string' && data.includes('"proof"');
await until(() => sender.logged('waiting for the security check'));
// The sender's proof still reaches it.
await until(() => silent.logged('security check passed'));
vi.advanceTimersByTime(PROOF_TIMEOUT);
await until(() => sender.logged('waiting for the next receiver'));
expect(sender.logged('the peer proved no code')).toBe(true);
expect(sender.logged('offered')).toBe(false);
// Left without the sender, it looks again.
await until(() => silent.logged('looking again'));
silent.stop();
await receiveViaTracker(code, receiver.events, receiver.signal);
@@ -1282,6 +1287,8 @@ describe('tracker signaling', () => {
await until(() => sender.errors.length && receiver.errors.length);
expect(sender.errors).toEqual([rejected]);
expect(receiver.errors).toEqual([rejected]);
// Neither keeps a timer, not even its expiry.
expect(vi.getTimerCount()).toBe(0);
trackers.clear();
const lonely = side();
@@ -1317,6 +1324,42 @@ describe('tracker signaling', () => {
expect(receiver.errors).toEqual([]);
});
// A tracker sees all signaling, without the code it can read none of it nor get anything answered:
// not an SDP of its own, not the receiver's sealed offer passed off as an answer.
it('seals the offers, ignores answers without the code', async () => {
const tracker = new FakeTracker(URLS[0]!, ({ info_hash }) => ({ action: 'announce', interval: 120, info_hash }));
settings.trackers = [URLS[0]!];
const receiver = side();
await receiveViaTracker('somecode123', receiver.events, receiver.signal);
await until(() => tracker.announced.length);
const [{ offer_id, offer }] = tracker.announced[0].offers;
expect(offer.sdp).not.toContain('a=fingerprint');
expect(offer.sdp).not.toContain('candidate');
for (const sdp of ['v=0\r\na=fingerprint:sha-256 AA\r\n', offer.sdp]) {
tracker.sockets[0]!.deliver(relayed({ offer_id, answer: { type: 'answer', sdp } }));
}
await until(() => receiver.count('answer without the code') === 2);
expect(receiver.logged('answer via')).toBe(false);
expect(FakePeer.all.map((pc) => pc.remoteDescription)).toEqual([null]);
});
// Trimmed and NFC, an ü typed on one system can be other bytes than on the next.
it('takes the own salt into the swarm, the share is found only with it', async () => {
const tracker = new FakeTracker(URLS[0]!);
settings.trackers = [URLS[0]!];
const [sender, other, receiver] = [side(), side(), side()];
const { code } = await sendViaTracker(file(10), sender.events, sender.signal, ' Gru\u0308ße ');
await until(() => tracker.announced.length);
expect(tracker.announced[0].info_hash).toBe((await secrets(code, codeSalt(code, 'Grüße'))).hash);
await receiveViaTracker(code, other.events, other.signal, 'Grüße!');
await until(() => other.status()?.startsWith('retry: No sender'));
expect(other.status()).toBe(
'retry: No sender with this code on any tracker. Check the code and the salt, still looking',
);
await receiveViaTracker(code, receiver.events, receiver.signal, 'Grüße');
await until(() => receiver.files[0]);
});
// Anyone with the code can send offers no browser can parse, as many as they like.
it('lets go of every unusable offer and keeps the tracker, ignores offers without the code', async () => {
const tracker = new FakeTracker(URLS[0]!, ({ info_hash }) => ({ action: 'announce', interval: 120, info_hash }));