Skip to content

Commit

Permalink
🛠 fix wsUrl bug & 🤖 randomize default token (#711)
Browse files Browse the repository at this point in the history
* 🛠fix wsUrl bug & 🤖 randomize default token
* 💚 tests
  • Loading branch information
stevejpurves authored Nov 21, 2023
1 parent 1ce79f6 commit bda77f7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
10 changes: 7 additions & 3 deletions packages/core/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
SavedSessionOptions,
MathjaxOptions,
} from './types';
import { shortId } from './utils';

export function makeBinderOptions(opts: BinderOptions) {
return {
Expand Down Expand Up @@ -36,12 +37,15 @@ export function makeKernelOptions(opts: KernelOptions): Required<KernelOptions>
}

export function makeServerSettings(settings: ServerSettings): Required<ServerSettings> {
const baseUrl = settings.baseUrl ?? 'http://localhost:8888';
const wsUrl = settings.wsUrl ?? baseUrl.replace(/^http/, 'ws');

return {
baseUrl: 'http://localhost:8888',
token: 'test-secret',
token: shortId(), // randomized default token to prevent accidental access to a local server
appendToken: true,
wsUrl: 'ws://localhost:8888',
...settings,
wsUrl,
baseUrl,
};
}

Expand Down
14 changes: 8 additions & 6 deletions packages/core/tests/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ describe('config', () => {
});
});
test('server settings', () => {
expect(config.serverSettings).toEqual({
baseUrl: 'http://localhost:8888',
token: 'test-secret',
appendToken: true,
wsUrl: 'ws://localhost:8888',
});
expect(config.serverSettings).toEqual(
expect.objectContaining({
baseUrl: 'http://localhost:8888',
token: expect.any(String),
appendToken: true,
wsUrl: 'ws://localhost:8888',
}),
);
});
});
});
14 changes: 8 additions & 6 deletions packages/core/tests/options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ describe('options', () => {
});
describe('server settings', () => {
test('defaults', () => {
expect(makeServerSettings({})).toEqual({
baseUrl: 'http://localhost:8888',
token: 'test-secret',
appendToken: true,
wsUrl: 'ws://localhost:8888',
});
expect(makeServerSettings({})).toEqual(
expect.objectContaining({
baseUrl: 'http://localhost:8888',
token: expect.any(String),
appendToken: true,
wsUrl: 'ws://localhost:8888',
}),
);
});
test('overrides', () => {
expect(
Expand Down

0 comments on commit bda77f7

Please sign in to comment.