2
0

index.spec.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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, mocha:true */
  9. 'use strict';
  10. var expect = require('chai').expect;
  11. var Policy = require('../lib/index');
  12. describe('The policy object', function() {
  13. it('should provide static access to policy options', function() {
  14. expect(function() {
  15. // It's `strict`, so it will fail if any of the values is not present in
  16. // the options object.
  17. Policy.options.asymmetric.keypair.encryption;
  18. }).not.to.throw();
  19. });
  20. it('should be able to restore default settings', function() {
  21. // Load the policy
  22. var policy = new Policy();
  23. // Check that the policy has default values.
  24. expect(policy.asymmetric.keypair.encryption.algorithm).to.equal('RSA');
  25. // Change a value.
  26. policy.asymmetric.keypair.encryption.algorithm = 'RSE';
  27. // Check that the value has changed.
  28. expect(policy.asymmetric.keypair.encryption.algorithm).to.equal('RSE');
  29. // Get a new default policy.
  30. policy = new Policy();
  31. // Check that the policy has default values again.
  32. expect(policy.asymmetric.keypair.encryption.algorithm).to.equal('RSA');
  33. });
  34. it('should provide access to policy options', function() {
  35. // Load the policy
  36. var policy = new Policy();
  37. expect(function() {
  38. policy.asymmetric.keypair.encryption.algorithm =
  39. Policy.options.asymmetric.keypair.encryption.algorithm.RSA;
  40. }).not.to.throw();
  41. });
  42. it('should allow overriding of the default policy', function() {
  43. var otherValue = 'XYZ';
  44. // Load the policy
  45. var policy = new Policy({
  46. asymmetric: {cipher: {algorithm: {name: otherValue}}},
  47. newOption: otherValue
  48. });
  49. expect(policy.asymmetric.cipher.algorithm.name).to.equal(otherValue);
  50. expect(policy.newOption).to.equal(otherValue);
  51. });
  52. });