forked from request/request
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-hawk.js
More file actions
executable file
·41 lines (35 loc) · 1.21 KB
/
Copy pathtest-hawk.js
File metadata and controls
executable file
·41 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
try {
require('hawk')
} catch (e) {
console.error('hawk must be installed to run this test.')
console.error('skipping this test. please install hawk and run again if you need to test this feature.')
process.exit(0)
}
var createServer = require('http').createServer
, request = require('../index')
, hawk = require('hawk')
, assert = require('assert')
;
var server = createServer(function (req, resp) {
var getCred = function (id, callback) {
assert.equal(id, 'dh37fgj492je')
var credentials =
{ key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn'
, algorithm: 'sha256'
, user: 'Steve'
}
return callback(null, credentials)
}
hawk.server.authenticate(req, getCred, {}, function (err, credentials, attributes) {
resp.writeHead(!err ? 200 : 401, { 'Content-Type': 'text/plain' })
resp.end(!err ? 'Hello ' + credentials.user : 'Shoosh!')
})
})
server.listen(8080, function () {
var creds = {key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', algorithm: 'sha256', id:'dh37fgj492je'}
request('http://localhost:8080', {hawk:{credentials:creds}}, function (e, r, b) {
assert.equal(200, r.statusCode)
assert.equal(b, 'Hello Steve')
server.close()
})
})