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
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,42 @@ describe('initializeRemoteComms', () => {
expect(is(validParams, initializeRemoteCommsSpec.params)).toBe(true);
});

it('should accept params with allowedWsHosts', () => {
const validParams = {
keySeed: '0x1234567890abcdef',
allowedWsHosts: ['localhost', 'example.com'],
};

expect(is(validParams, initializeRemoteCommsSpec.params)).toBe(true);
});

it('should accept params with empty allowedWsHosts array', () => {
const validParams = {
keySeed: '0x1234567890abcdef',
allowedWsHosts: [],
};

expect(is(validParams, initializeRemoteCommsSpec.params)).toBe(true);
});

it('should reject params with non-array allowedWsHosts', () => {
const invalidParams = {
keySeed: '0x1234567890abcdef',
allowedWsHosts: 'not-an-array',
};

expect(is(invalidParams, initializeRemoteCommsSpec.params)).toBe(false);
});

it('should reject params with non-string elements in allowedWsHosts', () => {
const invalidParams = {
keySeed: '0x1234567890abcdef',
allowedWsHosts: ['localhost', 123],
};

expect(is(invalidParams, initializeRemoteCommsSpec.params)).toBe(false);
});

it('should accept params with incarnationId', () => {
const validParams = {
keySeed: '0x1234567890abcdef',
Expand Down Expand Up @@ -562,6 +598,31 @@ describe('initializeRemoteComms', () => {
);
});

it('should pass allowedWsHosts to hook when provided', async () => {
const mockInitializeRemoteComms: InitializeRemoteComms = vi.fn(
async () => null,
);

const hooks = {
initializeRemoteComms: mockInitializeRemoteComms,
};

const params = {
keySeed: '0xtestseed',
allowedWsHosts: ['localhost', 'example.com'],
};

await initializeRemoteCommsHandler.implementation(hooks, params);

expect(mockInitializeRemoteComms).toHaveBeenCalledWith(
'0xtestseed',
{
allowedWsHosts: ['localhost', 'example.com'],
},
undefined,
);
});

it('should pass all options when all are provided', async () => {
const mockInitializeRemoteComms: InitializeRemoteComms = vi.fn(
async () => null,
Expand All @@ -576,6 +637,7 @@ describe('initializeRemoteComms', () => {
relays: ['/dns4/relay.example/tcp/443/wss/p2p/relay'],
maxRetryAttempts: 5,
maxQueue: 100,
allowedWsHosts: ['localhost'],
};

await initializeRemoteCommsHandler.implementation(hooks, params);
Expand All @@ -586,6 +648,7 @@ describe('initializeRemoteComms', () => {
relays: ['/dns4/relay.example/tcp/443/wss/p2p/relay'],
maxRetryAttempts: 5,
maxQueue: 100,
allowedWsHosts: ['localhost'],
},
undefined,
);
Expand Down Expand Up @@ -620,6 +683,7 @@ describe('initializeRemoteComms', () => {
expect(options).not.toHaveProperty('relays');
expect(options).not.toHaveProperty('maxRetryAttempts');
expect(options).not.toHaveProperty('maxQueue');
expect(options).not.toHaveProperty('allowedWsHosts');
return null;
},
);
Expand All @@ -641,6 +705,7 @@ describe('initializeRemoteComms', () => {
relays: ['/dns4/relay.example/tcp/443/wss/p2p/relay'],
maxRetryAttempts: 5,
maxQueue: 100,
allowedWsHosts: ['localhost'],
};

expect(is(validParams, initializeRemoteCommsSpec.params)).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const initializeRemoteCommsParamsStruct = object({
relays: optional(array(string())),
maxRetryAttempts: optional(number()),
maxQueue: optional(number()),
allowedWsHosts: optional(array(string())),
incarnationId: optional(string()),
});

Expand All @@ -23,6 +24,7 @@ type InitializeRemoteCommsParams = {
relays?: string[];
maxRetryAttempts?: number;
maxQueue?: number;
allowedWsHosts?: string[];
incarnationId?: string;
};

Expand Down Expand Up @@ -69,6 +71,9 @@ export const initializeRemoteCommsHandler: InitializeRemoteCommsHandler = {
if (params.maxQueue !== undefined) {
options.maxQueue = params.maxQueue;
}
if (params.allowedWsHosts !== undefined) {
options.allowedWsHosts = params.allowedWsHosts;
}
Comment on lines +74 to +76

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (params.allowedWsHosts !== undefined) {
options.allowedWsHosts = params.allowedWsHosts;
}
const options = { relays, maxRetryAttempts, maxQueue, allowedWsHosts } = params;
return await initializeRemoteComms(
params.keySeed,
ifDefined(options),

return await initializeRemoteComms(
params.keySeed,
options,
Expand Down
Loading