Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81146 views
1
// Load modules
2
3
var Code = require('code');
4
var Hawk = require('../lib');
5
var Lab = require('lab');
6
7
8
// Declare internals
9
10
var internals = {};
11
12
13
// Test shortcuts
14
15
var lab = exports.lab = Lab.script();
16
var describe = lab.experiment;
17
var it = lab.test;
18
var expect = Code.expect;
19
20
21
describe('Hawk', function () {
22
23
describe('Crypto', function () {
24
25
describe('#generateNormalizedString', function () {
26
27
it('should return a valid normalized string', function (done) {
28
29
expect(Hawk.crypto.generateNormalizedString('header', {
30
credentials: {
31
key: 'dasdfasdf',
32
algorithm: 'sha256'
33
},
34
ts: 1357747017,
35
nonce: 'k3k4j5',
36
method: 'GET',
37
resource: '/resource/something',
38
host: 'example.com',
39
port: 8080
40
})).to.equal('hawk.1.header\n1357747017\nk3k4j5\nGET\n/resource/something\nexample.com\n8080\n\n\n');
41
42
done();
43
});
44
45
it('should return a valid normalized string (ext)', function (done) {
46
47
expect(Hawk.crypto.generateNormalizedString('header', {
48
credentials: {
49
key: 'dasdfasdf',
50
algorithm: 'sha256'
51
},
52
ts: 1357747017,
53
nonce: 'k3k4j5',
54
method: 'GET',
55
resource: '/resource/something',
56
host: 'example.com',
57
port: 8080,
58
ext: 'this is some app data'
59
})).to.equal('hawk.1.header\n1357747017\nk3k4j5\nGET\n/resource/something\nexample.com\n8080\n\nthis is some app data\n');
60
61
done();
62
});
63
64
it('should return a valid normalized string (payload + ext)', function (done) {
65
66
expect(Hawk.crypto.generateNormalizedString('header', {
67
credentials: {
68
key: 'dasdfasdf',
69
algorithm: 'sha256'
70
},
71
ts: 1357747017,
72
nonce: 'k3k4j5',
73
method: 'GET',
74
resource: '/resource/something',
75
host: 'example.com',
76
port: 8080,
77
hash: 'U4MKKSmiVxk37JCCrAVIjV/OhB3y+NdwoCr6RShbVkE=',
78
ext: 'this is some app data'
79
})).to.equal('hawk.1.header\n1357747017\nk3k4j5\nGET\n/resource/something\nexample.com\n8080\nU4MKKSmiVxk37JCCrAVIjV/OhB3y+NdwoCr6RShbVkE=\nthis is some app data\n');
80
81
done();
82
});
83
});
84
});
85
});
86
87
88