Skip to content

Commit

Permalink
Refuse to start when network_key has invalid length. Koenkk/zigbee2mq…
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Feb 8, 2020
1 parent 372d03b commit a276356
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,18 @@ class Controller extends events.EventEmitter {
*/
public constructor(options: Options) {
super();
this.options = mixin(DefaultOptions, options);
this.options = mixin(JSON.parse(JSON.stringify(DefaultOptions)), options);

// Validate options
for (const channel of this.options.network.channelList) {
if (channel < 11 || channel > 26) {
throw new Error(`'${channel}' is an invalid channel, use a channel between 11 - 26.`);
}
}

if (this.options.network.networkKey.length !== 16) {
throw new Error(`Network key must be 16 digits long, got ${this.options.network.networkKey.length}.`);
}
}

/**
Expand Down
10 changes: 9 additions & 1 deletion test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ describe('Controller', () => {
}).toThrowError("'10' is an invalid channel, use a channel between 11 - 26.");
});

it('Call controller constructor error on invalid channel', async () => {
const newOptions = deepClone(options);
newOptions.network.networkKey = [1,2,3];
expect(() => {
new Controller(newOptions);
}).toThrowError('Network key must be 16 digits long, got 3.');
});

it('Controller start', async () => {
jest.useFakeTimers();
await controller.start();
Expand Down Expand Up @@ -1393,7 +1401,7 @@ describe('Controller', () => {
expect(controller.getDeviceByIeeeAddr('0x171').modelID).toBe('lumi.remote.b286opcn01')
});

it('onlythis Gledopto GL-C-007/GL-C-008 join (all endpoints support genBasic but only 12 responds)', async () => {
it('Gledopto GL-C-007/GL-C-008 join (all endpoints support genBasic but only 12 responds)', async () => {
// - https://github.com/Koenkk/zigbee2mqtt/issues/2872
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 172, ieeeAddr: '0x172'});
Expand Down

0 comments on commit a276356

Please sign in to comment.