Fix isHttpConnection check (#1526)

This commit is contained in:
Tomas Della Vedova
2021-08-20 12:40:25 +02:00
committed by GitHub
parent f161946984
commit a0dcace7cd
2 changed files with 32 additions and 2 deletions

View File

@ -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:'
}
}

View File

@ -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)