feat: Implement --baseUrl flag.

Closes https://github.com/solid/community-server/issues/372
This commit is contained in:
Ruben Verborgh
2020-12-01 15:52:44 +01:00
parent 528688bc4c
commit eabe6bc4ed
13 changed files with 60 additions and 66 deletions

View File

@@ -2,36 +2,31 @@ import { createResponse } from 'node-mocks-http';
import { WebSocketAdvertiser } from '../../../../src/server/middleware/WebSocketAdvertiser';
describe('A WebSocketAdvertiser', (): void => {
it('writes a default HTTP WebSocket.', async(): Promise<void> => {
const writer = new WebSocketAdvertiser();
const response = createResponse();
await writer.handle({ response } as any);
expect(response.getHeaders()).toEqual({ 'updates-via': 'ws://localhost/' });
});
it('writes an HTTP WebSocket with port 80.', async(): Promise<void> => {
const writer = new WebSocketAdvertiser({ hostname: 'test.example', port: 80, protocol: 'http' });
it('writes a ws: socket when given an http: URL.', async(): Promise<void> => {
const writer = new WebSocketAdvertiser('http://test.example/');
const response = createResponse();
await writer.handle({ response } as any);
expect(response.getHeaders()).toEqual({ 'updates-via': 'ws://test.example/' });
});
it('writes an HTTP WebSocket with port 3000.', async(): Promise<void> => {
const writer = new WebSocketAdvertiser({ hostname: 'test.example', port: 3000, protocol: 'http' });
it('writes a ws: socket when given a ws: URL.', async(): Promise<void> => {
const writer = new WebSocketAdvertiser('ws://test.example/');
const response = createResponse();
await writer.handle({ response } as any);
expect(response.getHeaders()).toEqual({ 'updates-via': 'ws://test.example:3000/' });
expect(response.getHeaders()).toEqual({ 'updates-via': 'ws://test.example/' });
});
it('writes an HTTPS WebSocket with port 443.', async(): Promise<void> => {
const writer = new WebSocketAdvertiser({ hostname: 'test.example', port: 443, protocol: 'https' });
it('writes a wss: socket when given an https: URL.', async(): Promise<void> => {
const writer = new WebSocketAdvertiser('https://test.example/');
const response = createResponse();
await writer.handle({ response } as any);
expect(response.getHeaders()).toEqual({ 'updates-via': 'wss://test.example/' });
});
it('rejects an invalid hostname.', (): void => {
expect((): any => new WebSocketAdvertiser({ hostname: 'test.example/invalid' }))
.toThrow('Invalid hostname: test.example/invalid');
it('writes a wss: socket when given a wss: URL.', async(): Promise<void> => {
const writer = new WebSocketAdvertiser('wss://test.example/');
const response = createResponse();
await writer.handle({ response } as any);
expect(response.getHeaders()).toEqual({ 'updates-via': 'wss://test.example/' });
});
});