index-validation.spec.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 pbkdf = require('../lib/index');
  11. var codec = require('scytl-codec');
  12. describe('The PBKDF module should be able to ...', function() {
  13. var PASSWORD = 'Test';
  14. var SALT = 'TestTestTestTestTestTestTestTest';
  15. var salt_;
  16. var deriver_;
  17. var nonObject_ = 999;
  18. var emptyObject_ = {};
  19. var nonString_ = 999;
  20. beforeAll(function() {
  21. salt_ = codec.utf8Encode(SALT);
  22. deriver_ = pbkdf.newService().newDeriver();
  23. });
  24. describe('create a PBKDF service that should be able to ..', function() {
  25. it('throw an error when being created, using an invalid cryptographic policy',
  26. function() {
  27. expect(function() {
  28. Object.create(pbkdf.newService({policy: null}));
  29. }).toThrow();
  30. expect(function() {
  31. Object.create(pbkdf.newService({policy: nonObject_}));
  32. }).toThrow();
  33. expect(function() {
  34. Object.create(pbkdf.newService({policy: emptyObject_}));
  35. }).toThrow();
  36. });
  37. describe('create a PBKDF deriver that should be able to', function() {
  38. it('throw an error when deriving a key, using an invalid password',
  39. function() {
  40. expect(function() {
  41. deriver_.derive(undefined, salt_);
  42. }).toThrow();
  43. expect(function() {
  44. deriver_.derive(null, salt_);
  45. }).toThrow();
  46. expect(function() {
  47. deriver_.derive(nonString_, salt_);
  48. }).toThrow();
  49. });
  50. it('throw an error when deriving a key, using invalid salt', function() {
  51. expect(function() {
  52. deriver_.derive(PASSWORD);
  53. }).toThrow();
  54. expect(function() {
  55. deriver_.derive(PASSWORD, undefined);
  56. }).toThrow();
  57. expect(function() {
  58. deriver_.derive(PASSWORD, null);
  59. }).toThrow();
  60. expect(function() {
  61. deriver_.derive(PASSWORD, '');
  62. }).toThrow();
  63. expect(function() {
  64. deriver_.derive(PASSWORD, nonString_);
  65. }).toThrow();
  66. });
  67. });
  68. });
  69. });