Updated test

This commit is contained in:
delvedor
2018-12-13 16:54:15 +01:00
parent 1cda67bcdb
commit 7cbc887ea0
2 changed files with 66 additions and 1 deletions

View File

@ -191,6 +191,71 @@ test('Node with auth data in the url', t => {
})
})
test('Custom authentication per request', t => {
t.plan(6)
var first = true
function handler (req, res) {
t.match(req.headers, {
authorization: first ? 'hello' : 'Basic Zm9vOmJhcg=='
})
res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' }))
}
buildServer(handler, ({ port }, server) => {
const client = new Client({
node: `http://foo:bar@localhost:${port}`
})
client.info({}, {
headers: {
authorization: 'hello'
}
}, (err, { body }) => {
t.error(err)
t.deepEqual(body, { hello: 'world' })
first = false
client.info((err, { body }) => {
t.error(err)
t.deepEqual(body, { hello: 'world' })
server.stop()
})
})
})
})
test('Custom headers per request', t => {
t.plan(3)
function handler (req, res) {
t.match(req.headers, {
'x-foo': 'bar',
'x-baz': 'faz'
})
res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' }))
}
buildServer(handler, ({ port }, server) => {
const client = new Client({
node: `http://foo:bar@localhost:${port}`
})
client.info({}, {
headers: {
'x-foo': 'bar',
'x-baz': 'faz'
}
}, (err, { body }) => {
t.error(err)
t.deepEqual(body, { hello: 'world' })
server.stop()
})
})
})
test('Client close', t => {
t.plan(2)