Support for non-friendly chars in url username and password (#858)
* Support for non-friendly chars in url username and password - Added auth option to Connection class - Updated pool.addConnection * Updated test
This commit is contained in:
committed by
GitHub
parent
844206ec9d
commit
95007b8c9d
@ -61,8 +61,23 @@ test('API', t => {
|
||||
t.deepEqual(pool._auth, { username: 'foo', password: 'bar' })
|
||||
|
||||
pool.addConnection('http://localhost:9201')
|
||||
t.strictEqual(pool.connections.get('http://localhost:9201/').url.username, 'foo')
|
||||
t.strictEqual(pool.connections.get('http://localhost:9201/').url.password, 'bar')
|
||||
const conn = pool.connections.get('http://localhost:9201/')
|
||||
t.strictEqual(conn.url.username, 'foo')
|
||||
t.strictEqual(conn.url.password, 'bar')
|
||||
t.strictEqual(conn.auth.username, 'foo')
|
||||
t.strictEqual(conn.auth.password, 'bar')
|
||||
t.end()
|
||||
})
|
||||
|
||||
t.test('addConnection should handle not-friendly url parameters for user and password', t => {
|
||||
const pool = new ConnectionPool({ Connection })
|
||||
const href = 'http://us"er:p@assword@localhost:9200/'
|
||||
pool.addConnection(href)
|
||||
const conn = pool.getConnection()
|
||||
t.strictEqual(conn.url.username, 'us%22er')
|
||||
t.strictEqual(conn.url.password, 'p%40assword')
|
||||
t.strictEqual(conn.auth.username, 'us"er')
|
||||
t.strictEqual(conn.auth.password, 'p@assword')
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
||||
@ -526,7 +526,8 @@ test('Url with auth', t => {
|
||||
|
||||
buildServer(handler, ({ port }, server) => {
|
||||
const connection = new Connection({
|
||||
url: new URL(`http://foo:bar@localhost:${port}`)
|
||||
url: new URL(`http://foo:bar@localhost:${port}`),
|
||||
auth: { username: 'foo', password: 'bar' }
|
||||
})
|
||||
connection.request({
|
||||
path: '/hello',
|
||||
|
||||
Reference in New Issue
Block a user