From a0dcace7cd2672a945b2333a245e199699a27789 Mon Sep 17 00:00:00 2001 From: Tomas Della Vedova Date: Fri, 20 Aug 2021 12:40:25 +0200 Subject: [PATCH] Fix isHttpConnection check (#1526) --- index.js | 4 ++-- test/unit/client.test.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 11b60a56d..6c8212d9a 100644 --- a/index.js +++ b/index.js @@ -323,9 +323,9 @@ function getAuth (node) { function isHttpConnection (node) { if (Array.isArray(node)) { - return node.some((n) => new URL(n).protocol === 'http:') + return node.some((n) => (typeof n === 'string' ? new URL(n).protocol : n.url.protocol) === 'http:') } else { - return new URL(node).protocol === 'http:' + return (typeof node === 'string' ? new URL(node).protocol : node.url.protocol) === 'http:' } } diff --git a/test/unit/client.test.js b/test/unit/client.test.js index cd6484ffe..20c1ce568 100644 --- a/test/unit/client.test.js +++ b/test/unit/client.test.js @@ -1586,6 +1586,36 @@ test('caFingerprint can\'t be configured over http / 3', t => { } }) +test('caFingerprint can\'t be configured over http / 4', t => { + t.plan(2) + + try { + new Client({ // eslint-disable-line + node: { url: new URL('http://localhost:9200') }, + caFingerprint: 'FO:OB:AR' + }) + t.fail('shuld throw') + } catch (err) { + t.ok(err instanceof errors.ConfigurationError) + t.equal(err.message, 'You can\'t configure the caFingerprint with a http connection') + } +}) + +test('caFingerprint can\'t be configured over http / 5', t => { + t.plan(2) + + try { + new Client({ // eslint-disable-line + nodes: [{ url: new URL('http://localhost:9200') }], + caFingerprint: 'FO:OB:AR' + }) + t.fail('should throw') + } catch (err) { + t.ok(err instanceof errors.ConfigurationError) + t.equal(err.message, 'You can\'t configure the caFingerprint with a http connection') + } +}) + test('Error body that is not a json', t => { t.plan(5)