Imports the previously untracked working tree as-is so that the review changes that follow (requirements -> design -> implementation) can be reviewed as diffs and reverted if needed. No content changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
24 lines
2.1 KiB
JavaScript
24 lines
2.1 KiB
JavaScript
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { collaborationBase, normalizeAuthMetadata, createPrefixTransport } = require('../client-factory.cjs');
|
|
test('collaboration URLs remain within the authenticated workspace and same origin', () => {
|
|
const location = 'https://ide.example/workspaces/alpha/index.html';
|
|
assert.equal(collaborationBase('https://ide.example/workspaces/alpha/collaboration/', location).pathname, '/workspaces/alpha/collaboration/');
|
|
for (const url of ['https://external.example/workspaces/alpha/collaboration/', 'https://ide.example/workspaces/beta/collaboration/', 'https://ide.example/socket.io/', 'https://ide.example/workspaces/alpha/collaboration/?token=secret']) assert.throws(() => collaborationBase(url, location));
|
|
});
|
|
test('simple display-name form URL cannot escape the workspace basepath', () => {
|
|
const meta = normalizeAuthMetadata({ providers: [{ type: 'form', name: 'unverified', endpoint: '/api/login/simple' }, { type: 'web', name: 'github', endpoint: 'https://external.example' }] });
|
|
assert.equal(meta.providers.length, 1);
|
|
assert.equal(new URL(meta.providers[0].endpoint, 'https://ide.example/workspaces/alpha/collaboration/').pathname, '/workspaces/alpha/collaboration/api/login/simple');
|
|
assert.throws(() => normalizeAuthMetadata({ providers: [], loginPageUrl: 'https://external.example/login' }));
|
|
});
|
|
test('Socket.IO uses origin namespace plus a workspace-specific Engine.IO path', () => {
|
|
let observed; const socket = {};
|
|
const adapter = createPrefixTransport({ io: (...args) => { observed = args; return socket; }, SocketIoTransport: class { constructor(value) { this.socket = value; } } }, 'https://ide.example/workspaces/alpha/collaboration/');
|
|
const transport = adapter.createTransport('ignored', { 'x-oct-jwt': 'room-token' });
|
|
assert.equal(transport.socket, socket); assert.equal(observed[0], 'https://ide.example');
|
|
assert.equal(observed[1].path, '/workspaces/alpha/collaboration/socket.io');
|
|
assert.deepEqual(observed[1].transports, ['polling', 'websocket']);
|
|
assert.equal(observed[1].extraHeaders['x-oct-jwt'], 'room-token');
|
|
});
|