index-validation.spec.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2018 Scytl Secure Electronic Voting SA
  3. *
  4. * All rights reserved
  5. *
  6. * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
  7. */
  8. /* jshint node:true, jasmine:true */
  9. 'use strict';
  10. var messageDigest = require('../lib/index');
  11. describe('The message digest module should be able to ...', function() {
  12. var digester_;
  13. var nonUint8Array_;
  14. beforeAll(function() {
  15. digester_ = messageDigest.newService().newDigester();
  16. nonUint8Array_ = 999;
  17. });
  18. describe('create a message digest service that should be able to ..', function() {
  19. it('throw an error when being created, using an invalid cryptographic policy',
  20. function() {
  21. var nonObject = 999;
  22. var emptyObject = {};
  23. expect(function() {
  24. Object.create(messageDigest.newService({policy: null}));
  25. }).toThrow();
  26. expect(function() {
  27. Object.create(messageDigest.newService({policy: nonObject}));
  28. }).toThrow();
  29. expect(function() {
  30. Object.create(messageDigest.newService({policy: emptyObject}));
  31. }).toThrow();
  32. });
  33. describe('create a message digester that should be able to', function() {
  34. it('throw an error when digesting, using invalid input data', function() {
  35. expect(function() {
  36. digester_.digest(null);
  37. }).toThrow();
  38. expect(function() {
  39. digester_.digest(nonUint8Array_);
  40. }).toThrow();
  41. });
  42. it('throw an error when updating, using invalid input data', function() {
  43. expect(function() {
  44. digester_.update();
  45. }).toThrow();
  46. expect(function() {
  47. digester_.update(undefined);
  48. }).toThrow();
  49. expect(function() {
  50. digester_.update(null);
  51. }).toThrow();
  52. expect(function() {
  53. digester_.update(nonUint8Array_);
  54. }).toThrow();
  55. });
  56. });
  57. });
  58. });