registration.spec.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. 'use strict';
  2. const { expect } = require('chai');
  3. const { v4 } = require('uuid');
  4. const { sequelize } = require('../../../db');
  5. const {
  6. registerParty,
  7. } = require('../../../processes/registration');
  8. describe('VEN registration', function() {
  9. before(async () => {
  10. await sequelize.sync();
  11. });
  12. describe('registerParty', function() {
  13. let venId, commonName, registrationResponse;
  14. before(async () => {
  15. venId = v4().replace(/-/g, '').substring(0,20).toUpperCase().match(/.{2}/g).join(':');
  16. const requestId = v4().replace(/-/g, '');
  17. commonName = v4().replace(/-/g, '').substring(0, 12);
  18. const request = {
  19. requestId: requestId,
  20. venId: venId,
  21. oadrProfileName: '2.0b',
  22. oadrTransportName: 'simplehttp',
  23. oadrReportOnly: false,
  24. oadrXmlSignature: false,
  25. oadrVenName: `VEN ${commonName}`,
  26. oadrHttpPullModel: true
  27. };
  28. registrationResponse = await registerParty(request, commonName, venId);
  29. });
  30. it ('allows registration of a new VEN', async () => {
  31. expect(registrationResponse.registrationId).to.be.a('string');
  32. });
  33. it ('rejects VEN with non-matching venId', async () => {
  34. const venId = v4().replace(/-/g, '').substring(0,20).toUpperCase().match(/.{2}/g).join(':');
  35. const requestId = v4().replace(/-/g, '');
  36. const commonName = v4().replace(/-/g, '').substring(0, 12);
  37. const request = {
  38. requestId: requestId,
  39. venId: venId,
  40. oadrProfileName: '2.0b',
  41. oadrTransportName: 'simplehttp',
  42. oadrReportOnly: false,
  43. oadrXmlSignature: false,
  44. oadrVenName: `VEN ${commonName}`,
  45. oadrHttpPullModel: true
  46. };
  47. let exception;
  48. try {
  49. await registerParty(request, commonName, `${venId}:FF`);
  50. } catch (e) {
  51. exception = e;
  52. }
  53. expect(exception).is.an('error');
  54. expect(exception.message).to.eql('VenID does not match certificate.');
  55. });
  56. it ('rejects registration when common name changes', async () => {
  57. const requestId = v4().replace(/-/g, '');
  58. const commonName2 = v4().replace(/-/g, '').substring(0, 12);
  59. const request = {
  60. requestId: requestId,
  61. venId: venId,
  62. oadrProfileName: '2.0b',
  63. oadrTransportName: 'simplehttp',
  64. oadrReportOnly: false,
  65. oadrXmlSignature: false,
  66. oadrVenName: `VEN ${commonName}`,
  67. oadrHttpPullModel: true
  68. };
  69. let exception;
  70. try {
  71. await registerParty(request, commonName2, venId);
  72. } catch (e) {
  73. exception = e;
  74. }
  75. expect(exception).is.an('error');
  76. expect(exception.message).to.eql('Client certificate CN mismatch.');
  77. });
  78. it ('rejects registration with existing common name but different venId', async () => {
  79. const requestId = v4().replace(/-/g, '');
  80. const venId2 = v4().replace(/-/g, '').substring(0,20).toUpperCase().match(/.{2}/g).join(':');
  81. const request = {
  82. requestId: requestId,
  83. venId: venId2,
  84. oadrProfileName: '2.0b',
  85. oadrTransportName: 'simplehttp',
  86. oadrReportOnly: false,
  87. oadrXmlSignature: false,
  88. oadrVenName: `VEN ${commonName}`,
  89. oadrHttpPullModel: true
  90. };
  91. let exception;
  92. try {
  93. await registerParty(request, commonName, venId2);
  94. } catch (e) {
  95. exception = e;
  96. }
  97. expect(exception).is.an('error');
  98. expect(exception.message).to.eql('Ven already exists with that CN.');
  99. });
  100. });
  101. });