2
0

validators.spec.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /* global OV */
  9. /* global TD */
  10. /* jshint maxlen: 6666 */
  11. describe('Validators api', function() {
  12. 'use strict';
  13. var TD = require('./mocks/testdata.json');
  14. it('should parse a start voting key', function() {
  15. var testKey = TD.startVotingKey;
  16. var eeid = TD.eventId;
  17. var expected = {
  18. credentialId: TD.infoResponse.credentialData.id,
  19. pin: '4df144b2c04b0b45ec1035adbba89e22'
  20. };
  21. expect(OV.parseStartVotingKey(testKey, eeid)).toEqual(expected);
  22. });
  23. it('should parse a server serverChallengeMessage', function() {
  24. var pin = '414dbbfbe79a26e53ce63f32747fc5cf';
  25. // no data
  26. // expect(function() {
  27. // var dataToVerify = {
  28. // challengeValue: TD.infoResponse.serverChallengeMessage.serverChallenge,
  29. // timestamp: TD.infoResponse.serverChallengeMessage.timestamp,
  30. // electionEventId: TD.eventId,
  31. // credentialId: TD.infoResponse.credentialData.id
  32. // };
  33. // var credentials = OV.parseCredentials(TD.infoResponse.credentialData, pin);
  34. // OV.parseServerChallenge(TD.infoResponse, dataToVerify, credentials);
  35. // }).not.toThrow();
  36. expect(function() {
  37. OV.parseServerChallenge({
  38. serverChallengeMessage: 'adsf'
  39. });
  40. }).toThrow(new Error('Bad server challenge'));
  41. expect(function() {
  42. OV.parseServerChallenge({
  43. serverChallengeMessage: {
  44. signature: 'asdf'
  45. }
  46. });
  47. }).toThrow(new Error('Bad server challenge'));
  48. expect(function() {
  49. OV.parseServerChallenge({
  50. serverChallengeMessage: {
  51. serverChallenge: '2190381097405701',
  52. timestamp: '1428486196320'
  53. }
  54. });
  55. }).toThrow(new Error('Bad server challenge'));
  56. });
  57. it('should parse a ballot box response', function() {
  58. expect(function() {
  59. OV.parseEncryptionParams(TD.authResponse);
  60. }).not.toThrow();
  61. });
  62. });