3 var Code = require('code');
\r
4 var Hawk = require('../lib');
\r
5 var Hoek = require('hoek');
\r
6 var Lab = require('lab');
\r
16 var lab = exports.lab = Lab.script();
\r
17 var describe = lab.experiment;
\r
19 var expect = Code.expect;
\r
22 describe('README', function () {
\r
24 describe('core', function () {
\r
28 key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',
\r
33 credentials: credentials,
\r
34 timestamp: 1353832234,
\r
36 ext: 'some-app-ext-data'
\r
39 it('should generate a header protocol example', function (done) {
\r
41 var header = Hawk.client.header('http://example.com:8000/resource/1?b=1&a=2', 'GET', options).field;
\r
43 expect(header).to.equal('Hawk id="dh37fgj492je", ts="1353832234", nonce="j4h3g2", ext="some-app-ext-data", mac="6R4rV5iE+NPoym+WwjeHzjAGXUtLNIxmo1vpMofpLAE="');
\r
47 it('should generate a normalized string protocol example', function (done) {
\r
49 var normalized = Hawk.crypto.generateNormalizedString('header', {
\r
50 credentials: credentials,
\r
51 ts: options.timestamp,
\r
52 nonce: options.nonce,
\r
54 resource: '/resource?a=1&b=2',
\r
55 host: 'example.com',
\r
60 expect(normalized).to.equal('hawk.1.header\n1353832234\nj4h3g2\nGET\n/resource?a=1&b=2\nexample.com\n8000\n\nsome-app-ext-data\n');
\r
64 var payloadOptions = Hoek.clone(options);
\r
65 payloadOptions.payload = 'Thank you for flying Hawk';
\r
66 payloadOptions.contentType = 'text/plain';
\r
68 it('should generate a header protocol example (with payload)', function (done) {
\r
70 var header = Hawk.client.header('http://example.com:8000/resource/1?b=1&a=2', 'POST', payloadOptions).field;
\r
72 expect(header).to.equal('Hawk id="dh37fgj492je", ts="1353832234", nonce="j4h3g2", hash="Yi9LfIIFRtBEPt74PVmbTF/xVAwPn7ub15ePICfgnuY=", ext="some-app-ext-data", mac="aSe1DERmZuRl3pI36/9BdZmnErTw3sNzOOAUlfeKjVw="');
\r
76 it('should generate a normalized string protocol example (with payload)', function (done) {
\r
78 var normalized = Hawk.crypto.generateNormalizedString('header', {
\r
79 credentials: credentials,
\r
80 ts: options.timestamp,
\r
81 nonce: options.nonce,
\r
83 resource: '/resource?a=1&b=2',
\r
84 host: 'example.com',
\r
86 hash: Hawk.crypto.calculatePayloadHash(payloadOptions.payload, credentials.algorithm, payloadOptions.contentType),
\r
90 expect(normalized).to.equal('hawk.1.header\n1353832234\nj4h3g2\nPOST\n/resource?a=1&b=2\nexample.com\n8000\nYi9LfIIFRtBEPt74PVmbTF/xVAwPn7ub15ePICfgnuY=\nsome-app-ext-data\n');
\r