From e555a876e23937715bb02a498d52e008c73af99c Mon Sep 17 00:00:00 2001 From: Aschen Date: Mon, 13 Jan 2020 17:40:49 +0100 Subject: [PATCH 1/2] Allow to pass port option as a string --- src/protocols/abstract/common.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/protocols/abstract/common.js b/src/protocols/abstract/common.js index 8eec74705..fec780fd9 100644 --- a/src/protocols/abstract/common.js +++ b/src/protocols/abstract/common.js @@ -12,7 +12,8 @@ class AbstractWrapper extends KuzzleEventEmitter { this._pendingRequests = new Map(); this._host = host; - this._port = typeof options.port === 'number' ? options.port : 7512; + const port = parseInt(options.port, 10); + this._port = isNaN(port) ? 7512 : port; this._ssl = typeof options.sslConnection === 'boolean' ? options.sslConnection : false; this.id = uuidv4(); From d6d45f68c8e52754941c7150ed6f5a3ea44885c7 Mon Sep 17 00:00:00 2001 From: Aschen Date: Mon, 13 Jan 2020 17:43:56 +0100 Subject: [PATCH 2/2] add tests --- test/protocol/common.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/protocol/common.test.js b/test/protocol/common.test.js index 329eb2414..4994d6149 100644 --- a/test/protocol/common.test.js +++ b/test/protocol/common.test.js @@ -18,6 +18,30 @@ describe('Common Protocol', () => { sendSpy = sinon.spy(protocol, 'send'); }); + describe('#constructor', () => { + it('should accept string as port', () => { + protocol = new AbstractWrapper('somewhere', { port: '443' }); + + should(protocol.port).be.eql(443); + }); + + it('should use 7512 when no port is given or when port is not a parseable number', () => { + protocol = new AbstractWrapper('somewhere', { port: 'foobar' }); + + should(protocol.port).be.eql(7512); + + protocol = new AbstractWrapper('somewhere'); + + should(protocol.port).be.eql(7512); + }); + + it('should accept number as port', () => { + protocol = new AbstractWrapper('somewhere', { port: 443 }); + + should(protocol.port).be.eql(443); + }); + }); + describe('#connected', () => { it('should return true if the protocol state is "connected"', () => { protocol.state = 'connected';