crypto.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Load modules
  2. var Lab = require('lab');
  3. var Hawk = require('../lib');
  4. // Declare internals
  5. var internals = {};
  6. // Test shortcuts
  7. var expect = Lab.expect;
  8. var before = Lab.before;
  9. var after = Lab.after;
  10. var describe = Lab.experiment;
  11. var it = Lab.test;
  12. describe('Hawk', function () {
  13. describe('Crypto', function () {
  14. describe('#generateNormalizedString', function () {
  15. it('should return a valid normalized string', function (done) {
  16. expect(Hawk.crypto.generateNormalizedString('header', {
  17. credentials: {
  18. key: 'dasdfasdf',
  19. algorithm: 'sha256'
  20. },
  21. ts: 1357747017,
  22. nonce: 'k3k4j5',
  23. method: 'GET',
  24. resource: '/resource/something',
  25. host: 'example.com',
  26. port: 8080
  27. })).to.equal('hawk.1.header\n1357747017\nk3k4j5\nGET\n/resource/something\nexample.com\n8080\n\n\n');
  28. done();
  29. });
  30. it('should return a valid normalized string (ext)', function (done) {
  31. expect(Hawk.crypto.generateNormalizedString('header', {
  32. credentials: {
  33. key: 'dasdfasdf',
  34. algorithm: 'sha256'
  35. },
  36. ts: 1357747017,
  37. nonce: 'k3k4j5',
  38. method: 'GET',
  39. resource: '/resource/something',
  40. host: 'example.com',
  41. port: 8080,
  42. ext: 'this is some app data'
  43. })).to.equal('hawk.1.header\n1357747017\nk3k4j5\nGET\n/resource/something\nexample.com\n8080\n\nthis is some app data\n');
  44. done();
  45. });
  46. it('should return a valid normalized string (payload + ext)', function (done) {
  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. hash: 'U4MKKSmiVxk37JCCrAVIjV/OhB3y+NdwoCr6RShbVkE=',
  59. ext: 'this is some app data'
  60. })).to.equal('hawk.1.header\n1357747017\nk3k4j5\nGET\n/resource/something\nexample.com\n8080\nU4MKKSmiVxk37JCCrAVIjV/OhB3y+NdwoCr6RShbVkE=\nthis is some app data\n');
  61. done();
  62. });
  63. });
  64. });
  65. });