registration.spec.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. 'use strict';
  2. const { expect } = require('chai');
  3. const { v4 } = require('uuid');
  4. const { sequelize } = require('../../../db');
  5. const {
  6. query,
  7. registerParty,
  8. } = require('../../../processes/registration');
  9. describe('VEN registration', function() {
  10. before(async () => {
  11. await sequelize.sync();
  12. });
  13. describe('registerParty', function() {
  14. let venId, commonName, registrationResponse;
  15. before(async () => {
  16. venId = v4().replace(/-/g, '').substring(0, 20).toUpperCase().match(/.{2}/g).join(':');
  17. const requestId = v4().replace(/-/g, '');
  18. commonName = v4().replace(/-/g, '').substring(0, 12);
  19. const request = {
  20. requestId: requestId,
  21. venId: venId,
  22. oadrProfileName: '2.0b',
  23. oadrTransportName: 'simplehttp',
  24. oadrReportOnly: false,
  25. oadrXmlSignature: false,
  26. oadrVenName: `VEN ${commonName}`,
  27. oadrHttpPullModel: true
  28. };
  29. registrationResponse = await registerParty(request, commonName, venId);
  30. });
  31. it('allows registration of a new VEN', async () => {
  32. expect(registrationResponse.registrationId).to.be.a('string');
  33. });
  34. it('rejects VEN with non-matching venId', async () => {
  35. const venId = v4().replace(/-/g, '').substring(0, 20).toUpperCase().match(/.{2}/g).join(':');
  36. const requestId = v4().replace(/-/g, '');
  37. const commonName = v4().replace(/-/g, '').substring(0, 12);
  38. const request = {
  39. requestId: requestId,
  40. venId: venId,
  41. oadrProfileName: '2.0b',
  42. oadrTransportName: 'simplehttp',
  43. oadrReportOnly: false,
  44. oadrXmlSignature: false,
  45. oadrVenName: `VEN ${commonName}`,
  46. oadrHttpPullModel: true
  47. };
  48. let exception;
  49. try {
  50. await registerParty(request, commonName, `${venId}:FF`);
  51. } catch (e) {
  52. exception = e;
  53. }
  54. expect(exception).is.an('error');
  55. expect(exception.message).to.eql('VenID does not match certificate.');
  56. });
  57. it('rejects registration when common name changes', async () => {
  58. const requestId = v4().replace(/-/g, '');
  59. const commonName2 = v4().replace(/-/g, '').substring(0, 12);
  60. const request = {
  61. requestId: requestId,
  62. venId: venId,
  63. oadrProfileName: '2.0b',
  64. oadrTransportName: 'simplehttp',
  65. oadrReportOnly: false,
  66. oadrXmlSignature: false,
  67. oadrVenName: `VEN ${commonName}`,
  68. oadrHttpPullModel: true
  69. };
  70. let exception;
  71. try {
  72. await registerParty(request, commonName2, venId);
  73. } catch (e) {
  74. exception = e;
  75. }
  76. expect(exception).is.an('error');
  77. expect(exception.message).to.eql('Client certificate CN mismatch.');
  78. });
  79. it('rejects registration with existing common name but different venId', async () => {
  80. const requestId = v4().replace(/-/g, '');
  81. const venId2 = v4().replace(/-/g, '').substring(0, 20).toUpperCase().match(/.{2}/g).join(':');
  82. const request = {
  83. requestId: requestId,
  84. venId: venId2,
  85. oadrProfileName: '2.0b',
  86. oadrTransportName: 'simplehttp',
  87. oadrReportOnly: false,
  88. oadrXmlSignature: false,
  89. oadrVenName: `VEN ${commonName}`,
  90. oadrHttpPullModel: true
  91. };
  92. let exception;
  93. try {
  94. await registerParty(request, commonName, venId2);
  95. } catch (e) {
  96. exception = e;
  97. }
  98. expect(exception).is.an('error');
  99. expect(exception.message).to.eql('Ven already exists with that CN.');
  100. });
  101. });
  102. describe('query', function() {
  103. let venId, commonName, queryResponse;
  104. before(async () => {
  105. venId = v4().replace(/-/g, '').substring(0, 20).toUpperCase().match(/.{2}/g).join(':');
  106. const requestId = v4().replace(/-/g, '');
  107. commonName = v4().replace(/-/g, '').substring(0, 12);
  108. const request = {
  109. requestId: requestId
  110. };
  111. queryResponse = await query(request, commonName, venId);
  112. });
  113. it('does not return venId or registrationId for new device', async () => {
  114. expect(queryResponse.registrationId).to.be.undefined;
  115. expect(queryResponse.venId).to.be.undefined;
  116. });
  117. it('returns registrationId if already registered', async () => {
  118. venId = v4().replace(/-/g, '').substring(0,20).toUpperCase().match(/.{2}/g).join(':');
  119. const requestId = v4().replace(/-/g, '');
  120. commonName = v4().replace(/-/g, '').substring(0, 12);
  121. const registerRequest = {
  122. requestId: requestId,
  123. venId: venId,
  124. oadrProfileName: '2.0b',
  125. oadrTransportName: 'simplehttp',
  126. oadrReportOnly: false,
  127. oadrXmlSignature: false,
  128. oadrVenName: `VEN ${commonName}`,
  129. oadrHttpPullModel: true
  130. };
  131. const registrationResponse = await registerParty(registerRequest, commonName, venId);
  132. const initialRegistrationId = registrationResponse.registrationId;
  133. const queryRequest = {
  134. requestId: requestId
  135. };
  136. queryResponse = await query(queryRequest, commonName, venId);
  137. expect(queryResponse.registrationId).to.eql(initialRegistrationId);
  138. expect(queryResponse.venId).to.eql(venId);
  139. });
  140. });
  141. });