crypto.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Load modules
  2. var Code = require('code');
  3. var Hawk = require('../lib');
  4. var Lab = require('lab');
  5. // Declare internals
  6. var internals = {};
  7. // Test shortcuts
  8. var lab = exports.lab = Lab.script();
  9. var describe = lab.experiment;
  10. var it = lab.test;
  11. var expect = Code.expect;
  12. describe('Crypto', function () {
  13. describe('generateNormalizedString()', function () {
  14. it('should return a valid normalized string', function (done) {
  15. expect(Hawk.crypto.generateNormalizedString('header', {
  16. ts: 1357747017,
  17. nonce: 'k3k4j5',
  18. method: 'GET',
  19. resource: '/resource/something',
  20. host: 'example.com',
  21. port: 8080
  22. })).to.equal('hawk.1.header\n1357747017\nk3k4j5\nGET\n/resource/something\nexample.com\n8080\n\n\n');
  23. done();
  24. });
  25. it('should return a valid normalized string (ext)', function (done) {
  26. expect(Hawk.crypto.generateNormalizedString('header', {
  27. ts: 1357747017,
  28. nonce: 'k3k4j5',
  29. method: 'GET',
  30. resource: '/resource/something',
  31. host: 'example.com',
  32. port: 8080,
  33. ext: 'this is some app data'
  34. })).to.equal('hawk.1.header\n1357747017\nk3k4j5\nGET\n/resource/something\nexample.com\n8080\n\nthis is some app data\n');
  35. done();
  36. });
  37. it('should return a valid normalized string (payload + ext)', function (done) {
  38. expect(Hawk.crypto.generateNormalizedString('header', {
  39. ts: 1357747017,
  40. nonce: 'k3k4j5',
  41. method: 'GET',
  42. resource: '/resource/something',
  43. host: 'example.com',
  44. port: 8080,
  45. hash: 'U4MKKSmiVxk37JCCrAVIjV/OhB3y+NdwoCr6RShbVkE=',
  46. ext: 'this is some app data'
  47. })).to.equal('hawk.1.header\n1357747017\nk3k4j5\nGET\n/resource/something\nexample.com\n8080\nU4MKKSmiVxk37JCCrAVIjV/OhB3y+NdwoCr6RShbVkE=\nthis is some app data\n');
  48. done();
  49. });
  50. });
  51. });