Files
Shade/packages/shade-transport-webrtc/tests/turn-relay.test.ts
Sterister e6fdf31b49
Some checks failed
Test / test (push) Has been cancelled
Cross-platform vectors / TypeScript vectors (bun) (push) Has been cancelled
Cross-platform vectors / Kotlin vectors (gradle) (push) Has been cancelled
Docker build and publish / docker (push) Has been cancelled
Publish / publish (push) Has been cancelled
release(v4.0.0): Shade GA — V3.x consolidation + audit prep
V3.1 → V3.12 consolidated and tagged for the first GA release. Wire
format unchanged from 0.4.x — 4.0 peers interoperate with 0.4.x peers
byte-for-byte. The version bump is semantic: audit-cycle complete,
opt-in surface fully exposed, threat model refreshed for every new
surface.

Highlights:
- All 24 @shade/* packages bumped to 4.0.0 in lockstep.
- CHANGELOG 4.0.0 section is the canonical manifest of what landed.
- THREAT-MODEL extended (§10 fingerprint gates, §11 WebRTC P2P, §12
  Web-Worker boundary) + residual-risks table refreshed.
- OpenAPI now covers all 27 routes: prekey, transfer, KT, inbox,
  bridge, observer, /metrics, /healthz, /ready.
- MIGRATION 0.3.x → 4.0 documented + smoke-tested against
  shade migrate-storage on a real SQLite DB.
- docs/audit/REVIEW-BUNDLE.md + SCOPE.md ready for external reviewer.
- scripts/soak.ts harness for the GA-stable 2-week soak window.
- All V*.md plans archived under docs/archive/ with Status: Done.
- Voice/Video carved out into V5.0; 4.0 audit focuses on the frozen
  non-realtime stack.

Tests: TS 1000/1000 + Kotlin 11/11 cross-platform vectors green.
Docker: gt.zyon.no/stian/shade-prekey:4.0.0 builds and reports
  version 4.0.0 on /health.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 18:35:35 +02:00

117 lines
3.6 KiB
TypeScript

/**
* V3.11 acceptance criterion: TURN-relay påtvinger relay-modus.
*
* We can't do real ICE in the memory factory, but we CAN verify that the
* RTCConfiguration we pass to the underlying factory carries the
* `iceTransportPolicy: 'relay'` flag through unchanged when the
* application configures a TURN-only setup. This guarantees a real
* RTCPeerConnection adapter (browser / wrtc / node-datachannel) will
* reject all non-relay candidate pairs as the spec requires.
*/
import { afterEach, describe, expect, it } from 'bun:test';
import { MemoryShadeBridge, WebRtcSignalingChannel } from '../src/signaling.js';
import { WebRtcConnectionManager } from '../src/manager.js';
import {
DEFAULT_STUN_SERVERS,
type IDataChannel,
type IPeerConnection,
type IRtcFactory,
type ShadeIceCandidate,
type ShadeRtcConfig,
type ShadeRtcConnectionState,
type ShadeSessionDescription,
} from '../src/types.js';
import { MemoryRtcFactory } from '../src/memory-rtc.js';
afterEach(() => {
MemoryRtcFactory.reset();
});
class CapturingFactory implements IRtcFactory {
configs: ShadeRtcConfig[] = [];
constructor(private readonly inner: IRtcFactory) {}
createPeerConnection(config: ShadeRtcConfig): IPeerConnection {
this.configs.push(config);
return this.inner.createPeerConnection(config);
}
}
describe('TURN-relay configuration plumbing', () => {
it('passes iceServers + iceTransportPolicy through to the underlying RTCConfiguration', async () => {
const turnServers = [
{
urls: 'turn:turn.example.com:3478',
username: 'shade',
credential: 'secret',
},
];
const inner = new MemoryRtcFactory();
const factory = new CapturingFactory(inner);
const { a, b } = MemoryShadeBridge.linked('alice', 'bob');
const aliceSig = new WebRtcSignalingChannel(a);
const bobSig = new WebRtcSignalingChannel(b);
const alice = new WebRtcConnectionManager({
factory,
signaling: aliceSig,
config: { iceServers: turnServers, iceTransportPolicy: 'relay' },
});
const bob = new WebRtcConnectionManager({
factory,
signaling: bobSig,
config: { iceServers: turnServers, iceTransportPolicy: 'relay' },
receiver: {
async onChunk() {
return { lastSeq: 0 };
},
async onResumeQuery() {
return null;
},
},
});
await alice.getOrCreate('bob');
// Both sides created at least one PC; each call's config should carry
// the TURN-only policy verbatim.
expect(factory.configs.length).toBeGreaterThanOrEqual(2);
for (const c of factory.configs) {
expect(c.iceTransportPolicy).toBe('relay');
expect(c.iceServers).toEqual(turnServers);
}
alice.destroy();
bob.destroy();
});
it('falls back to default public STUN when no iceServers are supplied', async () => {
const inner = new MemoryRtcFactory();
const factory = new CapturingFactory(inner);
const { a, b } = MemoryShadeBridge.linked('alice', 'bob');
const alice = new WebRtcConnectionManager({
factory,
signaling: new WebRtcSignalingChannel(a),
defaultStunServers: DEFAULT_STUN_SERVERS,
});
const bob = new WebRtcConnectionManager({
factory,
signaling: new WebRtcSignalingChannel(b),
defaultStunServers: DEFAULT_STUN_SERVERS,
receiver: {
async onChunk() {
return { lastSeq: 0 };
},
async onResumeQuery() {
return null;
},
},
});
await alice.getOrCreate('bob');
for (const c of factory.configs) {
expect(c.iceServers).toEqual(DEFAULT_STUN_SERVERS);
}
alice.destroy();
bob.destroy();
});
});