]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/request/node_modules/hawk/test/readme.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / request / node_modules / hawk / test / readme.js
1 // Load modules
2
3 var Code = require('code');
4 var Hawk = require('../lib');
5 var Hoek = require('hoek');
6 var Lab = require('lab');
7
8
9 // Declare internals
10
11 var internals = {};
12
13
14 // Test shortcuts
15
16 var lab = exports.lab = Lab.script();
17 var describe = lab.experiment;
18 var it = lab.test;
19 var expect = Code.expect;
20
21
22 describe('README', function () {
23
24     describe('core', function () {
25
26         var credentials = {
27             id: 'dh37fgj492je',
28             key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',
29             algorithm: 'sha256'
30         };
31
32         var options = {
33             credentials: credentials,
34             timestamp: 1353832234,
35             nonce: 'j4h3g2',
36             ext: 'some-app-ext-data'
37         };
38
39         it('should generate a header protocol example', function (done) {
40
41             var header = Hawk.client.header('http://example.com:8000/resource/1?b=1&a=2', 'GET', options).field;
42
43             expect(header).to.equal('Hawk id="dh37fgj492je", ts="1353832234", nonce="j4h3g2", ext="some-app-ext-data", mac="6R4rV5iE+NPoym+WwjeHzjAGXUtLNIxmo1vpMofpLAE="');
44             done();
45         });
46
47         it('should generate a normalized string protocol example', function (done) {
48
49             var normalized = Hawk.crypto.generateNormalizedString('header', {
50                 credentials: credentials,
51                 ts: options.timestamp,
52                 nonce: options.nonce,
53                 method: 'GET',
54                 resource: '/resource?a=1&b=2',
55                 host: 'example.com',
56                 port: 8000,
57                 ext: options.ext
58             });
59
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');
61             done();
62         });
63
64         var payloadOptions = Hoek.clone(options);
65         payloadOptions.payload = 'Thank you for flying Hawk';
66         payloadOptions.contentType = 'text/plain';
67
68         it('should generate a header protocol example (with payload)', function (done) {
69
70             var header = Hawk.client.header('http://example.com:8000/resource/1?b=1&a=2', 'POST', payloadOptions).field;
71
72             expect(header).to.equal('Hawk id="dh37fgj492je", ts="1353832234", nonce="j4h3g2", hash="Yi9LfIIFRtBEPt74PVmbTF/xVAwPn7ub15ePICfgnuY=", ext="some-app-ext-data", mac="aSe1DERmZuRl3pI36/9BdZmnErTw3sNzOOAUlfeKjVw="');
73             done();
74         });
75
76         it('should generate a normalized string protocol example (with payload)', function (done) {
77
78             var normalized = Hawk.crypto.generateNormalizedString('header', {
79                 credentials: credentials,
80                 ts: options.timestamp,
81                 nonce: options.nonce,
82                 method: 'POST',
83                 resource: '/resource?a=1&b=2',
84                 host: 'example.com',
85                 port: 8000,
86                 hash: Hawk.crypto.calculatePayloadHash(payloadOptions.payload, credentials.algorithm, payloadOptions.contentType),
87                 ext: options.ext
88             });
89
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');
91             done();
92         });
93     });
94 });