2
0

index.spec.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 cryptoPolicy = require('../lib/index');
  11. describe('The cryptographic policy module should be able to ...', function() {
  12. describe(
  13. 'create a cryptographic policy instance that should be able to ..',
  14. function() {
  15. it('provide access to policy options', function() {
  16. expect(function() {
  17. // It's `strict`, so it will fail if any of the values is not
  18. // present in the options object.
  19. var policy = cryptoPolicy.newInstance();
  20. var value = policy.asymmetric.keyPair.encryption;
  21. expect(value).toBeDefined();
  22. }).not.toThrow();
  23. });
  24. it('restore default settings', function() {
  25. // Load the policy
  26. var policy = cryptoPolicy.newInstance();
  27. // Check that the policy has default values.
  28. expect(policy.asymmetric.keyPair.encryption.algorithm).toEqual('RSA');
  29. // Change a value.
  30. policy.asymmetric.keyPair.encryption.algorithm = 'RSE';
  31. // Check that the value has changed.
  32. expect(policy.asymmetric.keyPair.encryption.algorithm).toEqual('RSE');
  33. // Get a new default policy.
  34. policy = cryptoPolicy.newInstance();
  35. // Check that the policy has default values again.
  36. expect(policy.asymmetric.keyPair.encryption.algorithm).toEqual('RSA');
  37. });
  38. it('provide access to policy options', function() {
  39. // Load the policy
  40. var policy = cryptoPolicy.newInstance();
  41. expect(function() {
  42. policy.asymmetric.keyPair.encryption.algorithm =
  43. cryptoPolicy.options.asymmetric.keyPair.encryption.algorithm
  44. .RSA;
  45. }).not.toThrow();
  46. });
  47. it('allow overriding of the default policy', function() {
  48. var otherValue = 'XYZ';
  49. // Load the policy
  50. var policy = cryptoPolicy.newInstance({
  51. asymmetric: {cipher: {algorithm: {name: otherValue}}},
  52. newOption: otherValue
  53. });
  54. expect(policy.asymmetric.cipher.algorithm.name).toEqual(otherValue);
  55. expect(policy.newOption).toBeDefined();
  56. expect(policy.newOption).toEqual(otherValue);
  57. });
  58. it('throw an error when being created with an invalid policy',
  59. function() {
  60. expect(function() {
  61. Object.create(cryptoPolicy.newInstance(null));
  62. }).toThrow();
  63. expect(function() {
  64. Object.create(cryptoPolicy.newInstance('non object'));
  65. }).toThrow();
  66. expect(function() {
  67. Object.create(cryptoPolicy.newInstance({}));
  68. }).toThrow();
  69. });
  70. });
  71. });