react / wstein / node_modules / jest-cli / node_modules / jsdom / node_modules / request / node_modules / hawk / test / readme.js
81146 views// Load modules12var Code = require('code');3var Hawk = require('../lib');4var Hoek = require('hoek');5var Lab = require('lab');678// Declare internals910var internals = {};111213// Test shortcuts1415var lab = exports.lab = Lab.script();16var describe = lab.experiment;17var it = lab.test;18var expect = Code.expect;192021describe('Hawk', function () {2223describe('README', function () {2425describe('core', function () {2627var credentials = {28id: 'dh37fgj492je',29key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',30algorithm: 'sha256'31};3233var options = {34credentials: credentials,35timestamp: 1353832234,36nonce: 'j4h3g2',37ext: 'some-app-ext-data'38};3940it('should generate a header protocol example', function (done) {4142var header = Hawk.client.header('http://example.com:8000/resource/1?b=1&a=2', 'GET', options).field;4344expect(header).to.equal('Hawk id="dh37fgj492je", ts="1353832234", nonce="j4h3g2", ext="some-app-ext-data", mac="6R4rV5iE+NPoym+WwjeHzjAGXUtLNIxmo1vpMofpLAE="');45done();46});4748it('should generate a normalized string protocol example', function (done) {4950var normalized = Hawk.crypto.generateNormalizedString('header', {51credentials: credentials,52ts: options.timestamp,53nonce: options.nonce,54method: 'GET',55resource: '/resource?a=1&b=2',56host: 'example.com',57port: 8000,58ext: options.ext59});6061expect(normalized).to.equal('hawk.1.header\n1353832234\nj4h3g2\nGET\n/resource?a=1&b=2\nexample.com\n8000\n\nsome-app-ext-data\n');62done();63});6465var payloadOptions = Hoek.clone(options);66payloadOptions.payload = 'Thank you for flying Hawk';67payloadOptions.contentType = 'text/plain';6869it('should generate a header protocol example (with payload)', function (done) {7071var header = Hawk.client.header('http://example.com:8000/resource/1?b=1&a=2', 'POST', payloadOptions).field;7273expect(header).to.equal('Hawk id="dh37fgj492je", ts="1353832234", nonce="j4h3g2", hash="Yi9LfIIFRtBEPt74PVmbTF/xVAwPn7ub15ePICfgnuY=", ext="some-app-ext-data", mac="aSe1DERmZuRl3pI36/9BdZmnErTw3sNzOOAUlfeKjVw="');74done();75});7677it('should generate a normalized string protocol example (with payload)', function (done) {7879var normalized = Hawk.crypto.generateNormalizedString('header', {80credentials: credentials,81ts: options.timestamp,82nonce: options.nonce,83method: 'POST',84resource: '/resource?a=1&b=2',85host: 'example.com',86port: 8000,87hash: Hawk.crypto.calculatePayloadHash(payloadOptions.payload, credentials.algorithm, payloadOptions.contentType),88ext: options.ext89});9091expect(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');92done();93});94});95});96});979899100