Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 51 additions & 8 deletions js/net/src/connection/migrate.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, expect, test } from "bun:test";
import { afterEach, expect, spyOn, test } from "bun:test";
import { Instant, Manual, Milli, Nano } from "@moq/clock";
import { RefusedRedirect } from "../error.ts";
import * as Lite from "../lite/index.ts";
Expand All @@ -8,7 +8,7 @@ import * as Path from "../path.ts";
import { Stream } from "../stream.ts";
import { accept } from "./accept.ts";
import { Connection, resetShared } from "./pool.ts";
import { Reload } from "./reload.ts";
import { Redirects, Reload } from "./reload.ts";

const original = globalThis.WebTransport;

Expand Down Expand Up @@ -305,25 +305,38 @@ async function elapse(clock: Manual, pred: () => boolean): Promise<Milli> {

/**
* Let session `hop` live for `life`, then have its peer redirect it to the other address,
* minting a fresh credential in the query when `rotate` is set.
* minting a fresh credential in the query or userinfo when `rotate` is set.
* Returns once the client has acted on the GOAWAY, so any backoff timer is already armed.
*/
async function bounce(clock: Manual, reload: Reload, dials: Dial[], hop: number, rotate = false): Promise<string> {
async function bounce(
clock: Manual,
reload: Reload,
dials: Dial[],
hop: number,
rotate?: "query" | "userinfo",
): Promise<string> {
await waitUntil(() => dials.length === hop + 1 && reload.status.peek() === "connected");
const dial = dials[hop];
if (!dial) throw new Error(`no dial ${hop}`);
const peer = new URL(dial.url).port === moved.port ? url : moved;
const other = rotate ? `${peer.href}?jwt=${hop}` : peer.href;
const next = new URL(peer);
if (rotate === "query") next.searchParams.set("jwt", String(hop));
if (rotate === "userinfo") {
next.username = `token-${hop}`;
next.password = `secret-${hop}`;
}
const other = next.href;
await clock.advanceAsync(Nano.fromMilli(life));
await goaway(dial.server, other);
await waitUntil(() => reload.redirect.peek()?.href === other);
return other;
}

test.each([
["", false],
[" even with fresh credentials on every redirect", true],
])("two peers redirecting to each other escalate the backoff instead of cycling%s", async (_, rotate) => {
["", undefined],
[" even with fresh query credentials on every redirect", "query"],
[" even with fresh userinfo on every redirect", "userinfo"],
] as const)("two peers redirecting to each other escalate the backoff instead of cycling%s", async (_, rotate) => {
const clock = new Manual();
const restore = clock.install();
const { dials } = fleet();
Expand Down Expand Up @@ -354,6 +367,36 @@ test.each([
}
});

test("redirect endpoint keys omit userinfo without changing the dial URL", async () => {
const clock = new Manual();
const restore = clock.install();
const { dials } = fleet();
const from = new URL("https://first:secret@relay.example/room?jwt=a#x");
const to = new URL("https://second:other@relay.example:5443/room?jwt=b#y");
const moves = spyOn(Redirects.prototype, "move");
const reload = new Reload({
url: from,
websocket: { enabled: false },
goaway: { handover },
delay: { initial: Milli(10) },
});

try {
await waitUntil(() => reload.status.peek() === "connected");
await clock.advanceAsync(Nano.fromMilli(life));
await goaway(dials[0]?.server as WebTransport, to.href);
await elapse(clock, () => dials.length === 2);
expect(moves.mock.calls).toEqual([["https://relay.example/room", "https://relay.example:5443/room"]]);
expect(dials.map((dial) => dial.url)).toEqual([from.href, to.href]);
expect(from.username).toBe("first");
expect(from.password).toBe("secret");
} finally {
reload.close();
moves.mockRestore();
restore();
}
});

test("a redirect loop stops at the retry window", async () => {
const clock = new Manual();
const restore = clock.install();
Expand Down
6 changes: 4 additions & 2 deletions js/net/src/connection/reload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,11 +766,13 @@ class Draining {
}

/**
* Where `url` dials, without its query or fragment, where a peer may mint fresh credentials on
* every redirect. Two URLs that differ only there reach the same endpoint.
* Where `url` dials, without its userinfo, query, or fragment, where a peer may mint fresh
* credentials on every redirect. Two URLs that differ only there reach the same endpoint.
*/
function endpoint(url: URL): string {
const bare = new URL(url);
bare.username = "";
bare.password = "";
bare.search = "";
bare.hash = "";
return bare.href;
Expand Down
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ lite-07 stream type here.
- [A/V clock](/quest/m1/av-clock.md) - the audio playhead drives Sync.reference while audio plays, through per-track sync handles
- [Publish channel count](/quest/m1/publish-audio-channel-count.md) - forcing a channel count on an Audio.Capture stops costing the subscriber gaps of silence, and the media fixture's cold-start audio-tone flake is fixed at its cause
- [moq --listen admission test](/quest/m1/listen-admission-test.md) - an in-process test proves `moq --listen` bounds admission by `listen.timeout`
- [JS redirect keys strip userinfo](/quest/m1/js-reload-userinfo.md) - js/net keys a reconnect endpoint without URL userinfo, matching Rust
- [Container reads drop backfill](/quest/m1/read-backfill.md) - the JS container consumer drops groups below its read cursor like Rust
- [qmux no-wait opens](/quest/m1/qmux-no-wait.md) - the in-tree @moq/qmux rejects an over-limit create when waitUntilAvailable is false, like Chrome
- [TS fidelity and recovery](/quest/m1/ts-reliability/README.md) - both modes have explicit profiles, automated validation, loss tests, and a dedicated guide
Expand Down
16 changes: 0 additions & 16 deletions quest/m1/js-reload-userinfo.md

This file was deleted.

Loading