Updated test
This commit is contained in:
@ -252,7 +252,7 @@ TestRunner.prototype.set = function (key, name) {
|
||||
TestRunner.prototype.do = function (action, done) {
|
||||
const cmd = this.parseDo(action)
|
||||
const api = delve(this.client, cmd.method).bind(this.client)
|
||||
const options = { ignore: cmd.params.ignore }
|
||||
const options = { ignore: cmd.params.ignore, headers: cmd.params.headers }
|
||||
api(cmd.params, options, (err, { body, warnings }) => {
|
||||
if (action.warnings && warnings === null) {
|
||||
this.tap.fail('We should get a warning header', action.warnings)
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user