source: Dev/trunk/src/node_modules/request/tests/test-hawk.js @ 484

Last change on this file since 484 was 484, checked in by hendrikvanantwerpen, 11 years ago

Commit node_modules, to make checkouts and builds more deterministic.

  • Property svn:executable set to *
File size: 1013 bytes
Line 
1var createServer = require('http').createServer
2  , request = require('../index')
3  , hawk = require('hawk')
4  , assert = require('assert')
5  ;
6
7var server = createServer(function (req, resp) {
8 
9  var getCred = function (id, callback) {
10    assert.equal(id, 'dh37fgj492je')
11    var credentials =
12      { key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn'
13      , algorithm: 'sha256'
14      , user: 'Steve'
15      }
16    return callback(null, credentials)
17  }
18
19  hawk.server.authenticate(req, getCred, {}, function (err, credentials, attributes) {
20    resp.writeHead(!err ? 200 : 401, { 'Content-Type': 'text/plain' })
21    resp.end(!err ? 'Hello ' + credentials.user : 'Shoosh!')
22  })
23 
24})
25
26server.listen(8080, function () {
27  var creds = {key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn', algorithm: 'sha256', id:'dh37fgj492je'}
28  request('http://localhost:8080', {hawk:{credentials:creds}}, function (e, r, b) {
29    assert.equal(200, r.statusCode)
30    assert.equal(b, 'Hello Steve')
31    server.close()
32  })
33})
Note: See TracBrowser for help on using the repository browser.