[Backport 7.x] Fix isHttpConnection check (#1528)
Co-authored-by: Tomas Della Vedova <delvedor@users.noreply.github.com>
This commit is contained in:
committed by
delvedor
parent
649f95afca
commit
1d5b8fa5c2
4
index.js
4
index.js
@ -323,9 +323,9 @@ function getAuth (node) {
|
|||||||
|
|
||||||
function isHttpConnection (node) {
|
function isHttpConnection (node) {
|
||||||
if (Array.isArray(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 {
|
} else {
|
||||||
return new URL(node).protocol === 'http:'
|
return (typeof node === 'string' ? new URL(node).protocol : node.url.protocol) === 'http:'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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 => {
|
test('Error body that is not a json', t => {
|
||||||
t.plan(5)
|
t.plan(5)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user