Remove auth data from inspect and toJSON in connection class (#887)
* Remove auth data from inspect and toJSON in connection class * Updated test
This commit is contained in:
committed by
delvedor
parent
39bbd77bec
commit
66fd94643d
@ -231,7 +231,7 @@ class Connection {
|
|||||||
// access them with `instance.agent` and `instance.ssl`.
|
// access them with `instance.agent` and `instance.ssl`.
|
||||||
[inspect.custom] (depth, options) {
|
[inspect.custom] (depth, options) {
|
||||||
return {
|
return {
|
||||||
url: this.url,
|
url: stripAuth(this.url.toString()),
|
||||||
id: this.id,
|
id: this.id,
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
deadCount: this.deadCount,
|
deadCount: this.deadCount,
|
||||||
@ -244,7 +244,7 @@ class Connection {
|
|||||||
|
|
||||||
toJSON () {
|
toJSON () {
|
||||||
return {
|
return {
|
||||||
url: this.url,
|
url: stripAuth(this.url.toString()),
|
||||||
id: this.id,
|
id: this.id,
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
deadCount: this.deadCount,
|
deadCount: this.deadCount,
|
||||||
|
|||||||
@ -723,11 +723,11 @@ test('setRole', t => {
|
|||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Util.inspect Connection class should hide agent and ssl', t => {
|
test('Util.inspect Connection class should hide agent, ssl and auth', t => {
|
||||||
t.plan(1)
|
t.plan(1)
|
||||||
|
|
||||||
const connection = new Connection({
|
const connection = new Connection({
|
||||||
url: new URL('http://localhost:9200'),
|
url: new URL('http://user:password@localhost:9200'),
|
||||||
id: 'node-id',
|
id: 'node-id',
|
||||||
headers: { foo: 'bar' }
|
headers: { foo: 'bar' }
|
||||||
})
|
})
|
||||||
@ -741,20 +741,7 @@ test('Util.inspect Connection class should hide agent and ssl', t => {
|
|||||||
.replace(/(\r\n|\n|\r)/gm, '')
|
.replace(/(\r\n|\n|\r)/gm, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
t.strictEqual(cleanStr(inspect(connection)), cleanStr(`{ url:
|
t.strictEqual(cleanStr(inspect(connection)), cleanStr(`{ url: 'http://localhost:9200/',
|
||||||
URL {
|
|
||||||
href: 'http://localhost:9200/',
|
|
||||||
origin: 'http://localhost:9200',
|
|
||||||
protocol: 'http:',
|
|
||||||
username: '',
|
|
||||||
password: '',
|
|
||||||
host: 'localhost:9200',
|
|
||||||
hostname: 'localhost',
|
|
||||||
port: '9200',
|
|
||||||
pathname: '/',
|
|
||||||
search: '',
|
|
||||||
searchParams: URLSearchParams {},
|
|
||||||
hash: '' },
|
|
||||||
id: 'node-id',
|
id: 'node-id',
|
||||||
headers: { foo: 'bar' },
|
headers: { foo: 'bar' },
|
||||||
deadCount: 0,
|
deadCount: 0,
|
||||||
@ -765,6 +752,34 @@ test('Util.inspect Connection class should hide agent and ssl', t => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('connection.toJSON should hide agent, ssl and auth', t => {
|
||||||
|
t.plan(1)
|
||||||
|
|
||||||
|
const connection = new Connection({
|
||||||
|
url: new URL('http://user:password@localhost:9200'),
|
||||||
|
id: 'node-id',
|
||||||
|
headers: { foo: 'bar' }
|
||||||
|
})
|
||||||
|
|
||||||
|
t.deepEqual(connection.toJSON(), {
|
||||||
|
url: 'http://localhost:9200/',
|
||||||
|
id: 'node-id',
|
||||||
|
headers: {
|
||||||
|
foo: 'bar'
|
||||||
|
},
|
||||||
|
deadCount: 0,
|
||||||
|
resurrectTimeout: 0,
|
||||||
|
_openRequests: 0,
|
||||||
|
status: 'alive',
|
||||||
|
roles: {
|
||||||
|
master: true,
|
||||||
|
data: true,
|
||||||
|
ingest: true,
|
||||||
|
ml: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// https://github.com/elastic/elasticsearch-js/issues/843
|
// https://github.com/elastic/elasticsearch-js/issues/843
|
||||||
test('Port handling', t => {
|
test('Port handling', t => {
|
||||||
t.test('http 80', t => {
|
t.test('http 80', t => {
|
||||||
|
|||||||
Reference in New Issue
Block a user