common-validation.spec.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 */
  9. 'use strict';
  10. var keyStore = require('../lib/index');
  11. describe('The key store module that should be able to ...', function() {
  12. var nonObject_;
  13. var emptyObject_;
  14. beforeAll(function() {
  15. nonObject_ = 999;
  16. emptyObject_ = {};
  17. });
  18. describe('create a key store service that should be able to ..', function() {
  19. it('throw an error when being created, using an invalid cryptographic policy',
  20. function() {
  21. expect(function() {
  22. Object.create(keyStore.newService({policy: null}));
  23. }).toThrow();
  24. expect(function() {
  25. Object.create(keyStore.newService({policy: nonObject_}));
  26. }).toThrow();
  27. expect(function() {
  28. Object.create(keyStore.newService({policy: emptyObject_}));
  29. }).toThrow();
  30. });
  31. it('throw an error when being created, using an invalid PBKDF service object',
  32. function() {
  33. expect(function() {
  34. Object.create(keyStore.newService({pbkdfService: null}));
  35. }).toThrow();
  36. expect(function() {
  37. Object.create(keyStore.newService({pbkdfService: nonObject_}));
  38. }).toThrow();
  39. expect(function() {
  40. Object.create(keyStore.newService({pbkdfService: emptyObject_}));
  41. }).toThrow();
  42. });
  43. it('throw an error when being created, using an invalid symmetric cryptography service object',
  44. function() {
  45. expect(function() {
  46. Object.create(
  47. keyStore.newService({symmetricCryptographyService: null}));
  48. }).toThrow();
  49. expect(function() {
  50. Object.create(
  51. keyStore.newService({symmetricCryptographyService: nonObject_}));
  52. }).toThrow();
  53. expect(function() {
  54. Object.create(keyStore.newService(
  55. {symmetricCryptographyService: emptyObject_}));
  56. }).toThrow();
  57. });
  58. it('throw an error when being created, using an invalid ElGamal cryptography service object',
  59. function() {
  60. expect(function() {
  61. Object.create(
  62. keyStore.newService({elGamalCryptographyService: null}));
  63. }).toThrow();
  64. expect(function() {
  65. Object.create(
  66. keyStore.newService({elGamalCryptographyService: nonObject_}));
  67. }).toThrow();
  68. expect(function() {
  69. Object.create(
  70. keyStore.newService({elGamalCryptographyService: emptyObject_}));
  71. }).toThrow();
  72. });
  73. });
  74. });