| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- 'use strict';
- const { expect } = require('chai');
- const { v4 } = require('uuid');
- const rewire = require('rewire');
- const FakeNantumModule = require('../utils/fake-nantum-module');
- describe('VEN registration', function() {
- let rewired;
- before(async () => {
- rewired = rewire('../../../processes/registration.js');
- rewired.__set__({
- nantum: new FakeNantumModule(),
- });
- });
- describe('registerParty', function() {
- let venId, commonName, registrationResponse;
- beforeEach(async () => {
- venId = v4()
- .replace(/-/g, '')
- .substring(0, 20)
- .toUpperCase()
- .match(/.{2}/g)
- .join(':');
- const requestId = v4().replace(/-/g, '');
- commonName = v4()
- .replace(/-/g, '')
- .substring(0, 12);
- const request = {
- requestId: requestId,
- venId: venId,
- oadrProfileName: '2.0b',
- oadrTransportName: 'simpleHttp',
- oadrReportOnly: false,
- oadrXmlSignature: false,
- oadrVenName: `VEN ${commonName}`,
- oadrHttpPullModel: true,
- };
- registrationResponse = await rewired.registerParty(
- request,
- commonName,
- venId,
- );
- });
- it('allows registration of a new VEN', async () => {
- expect(registrationResponse.registrationId).to.be.a('string');
- });
- it('rejects VEN with non-matching venId', async () => {
- const venId = v4()
- .replace(/-/g, '')
- .substring(0, 20)
- .toUpperCase()
- .match(/.{2}/g)
- .join(':');
- const requestId = v4().replace(/-/g, '');
- const commonName = v4()
- .replace(/-/g, '')
- .substring(0, 12);
- const request = {
- requestId: requestId,
- venId: venId,
- oadrProfileName: '2.0b',
- oadrTransportName: 'simpleHttp',
- oadrReportOnly: false,
- oadrXmlSignature: false,
- oadrVenName: `VEN ${commonName}`,
- oadrHttpPullModel: true,
- };
- let exception;
- try {
- await rewired.registerParty(request, commonName, `${venId}:FF`);
- } catch (e) {
- exception = e;
- }
- expect(exception).is.an('error');
- expect(exception.message).to.eql('VenID does not match certificate');
- });
- it('rejects registration when common name changes', async () => {
- const requestId = v4().replace(/-/g, '');
- const commonName2 = v4()
- .replace(/-/g, '')
- .substring(0, 12);
- const request = {
- requestId: requestId,
- venId: venId,
- oadrProfileName: '2.0b',
- oadrTransportName: 'simpleHttp',
- oadrReportOnly: false,
- oadrXmlSignature: false,
- oadrVenName: `VEN ${commonName}`,
- oadrHttpPullModel: true,
- };
- let exception;
- try {
- await rewired.registerParty(request, commonName2, venId);
- } catch (e) {
- exception = e;
- }
- expect(exception).is.an('error');
- expect(exception.message).to.eql('Client certificate CN mismatch');
- });
- });
- describe('query', function() {
- let venId, commonName, queryResponse;
- beforeEach(async () => {
- venId = v4()
- .replace(/-/g, '')
- .substring(0, 20)
- .toUpperCase()
- .match(/.{2}/g)
- .join(':');
- const requestId = v4().replace(/-/g, '');
- commonName = v4()
- .replace(/-/g, '')
- .substring(0, 12);
- const request = {
- requestId: requestId,
- };
- queryResponse = await rewired.query(request, commonName, venId);
- });
- it('does not return venId or registrationId for new device', async () => {
- expect(queryResponse.registrationId).to.be.undefined;
- expect(queryResponse.venId).to.be.undefined;
- });
- it('returns registrationId if already registered', async () => {
- venId = v4()
- .replace(/-/g, '')
- .substring(0, 20)
- .toUpperCase()
- .match(/.{2}/g)
- .join(':');
- const requestId = v4().replace(/-/g, '');
- commonName = v4()
- .replace(/-/g, '')
- .substring(0, 12);
- const registerRequest = {
- requestId: requestId,
- venId: venId,
- oadrProfileName: '2.0b',
- oadrTransportName: 'simpleHttp',
- oadrReportOnly: false,
- oadrXmlSignature: false,
- oadrVenName: `VEN ${commonName}`,
- oadrHttpPullModel: true,
- };
- const registrationResponse = await rewired.registerParty(
- registerRequest,
- commonName,
- venId,
- );
- const initialRegistrationId = registrationResponse.registrationId;
- const queryRequest = {
- requestId: requestId,
- };
- queryResponse = await rewired.query(queryRequest, commonName, venId);
- expect(queryResponse.registrationId).to.eql(initialRegistrationId);
- expect(queryResponse.venId).to.eql(venId);
- });
- it('rejects XMPP client', async () => {
- venId = v4()
- .replace(/-/g, '')
- .substring(0, 20)
- .toUpperCase()
- .match(/.{2}/g)
- .join(':');
- const requestId = v4().replace(/-/g, '');
- commonName = v4()
- .replace(/-/g, '')
- .substring(0, 12);
- const registerRequest = {
- requestId: requestId,
- venId: venId,
- oadrProfileName: '2.0b',
- oadrTransportName: 'xmpp',
- oadrReportOnly: false,
- oadrXmlSignature: false,
- oadrVenName: `VEN ${commonName}`,
- oadrHttpPullModel: true,
- };
- let lastError;
- try {
- await rewired.registerParty(registerRequest, commonName, venId);
- } catch (e) {
- lastError = e;
- }
- expect(lastError).to.be.an('error');
- expect(lastError.message).to.eql('Transport name must be simpleHttp');
- });
- it('rejects 2.0a client', async () => {
- venId = v4()
- .replace(/-/g, '')
- .substring(0, 20)
- .toUpperCase()
- .match(/.{2}/g)
- .join(':');
- const requestId = v4().replace(/-/g, '');
- commonName = v4()
- .replace(/-/g, '')
- .substring(0, 12);
- const registerRequest = {
- requestId: requestId,
- venId: venId,
- oadrProfileName: '2.0a',
- oadrTransportName: 'simpleHttp',
- oadrReportOnly: false,
- oadrXmlSignature: false,
- oadrVenName: `VEN ${commonName}`,
- oadrHttpPullModel: true,
- };
- let lastError;
- try {
- await rewired.registerParty(registerRequest, commonName, venId);
- } catch (e) {
- lastError = e;
- }
- expect(lastError).to.be.an('error');
- expect(lastError.message).to.eql('Profile name must be 2.0b');
- });
- });
- describe('cancelParty', function() {
- let venId, commonName, registrationResponse;
- beforeEach(async () => {
- venId = v4()
- .replace(/-/g, '')
- .substring(0, 20)
- .toUpperCase()
- .match(/.{2}/g)
- .join(':');
- const requestId = v4().replace(/-/g, '');
- commonName = v4()
- .replace(/-/g, '')
- .substring(0, 12);
- const request = {
- requestId: requestId,
- venId: venId,
- oadrProfileName: '2.0b',
- oadrTransportName: 'simpleHttp',
- oadrReportOnly: false,
- oadrXmlSignature: false,
- oadrVenName: `VEN ${commonName}`,
- oadrHttpPullModel: true,
- };
- registrationResponse = await rewired.registerParty(
- request,
- commonName,
- venId,
- );
- });
- it('successfully cancels an existing registration', async () => {
- const cancelRequestId = v4().replace(/-/g, '');
- const cancelRequest = {
- requestId: cancelRequestId,
- registrationId: registrationResponse.registrationId,
- venId: venId,
- };
- const cancelResponse = await rewired.cancelParty(
- cancelRequest,
- commonName,
- venId,
- );
- expect(cancelResponse.responseCode).to.eql('200');
- expect(cancelResponse.responseDescription).to.eql('OK');
- expect(cancelResponse.responseRequestId).to.eql(cancelRequestId);
- expect(cancelResponse.venId).to.eql(venId);
- });
- it('fails if venID does not match certificate', async () => {
- const otherVenId = v4().replace(/-/g, '');
- const cancelRequestId = v4().replace(/-/g, '');
- const cancelRequest = {
- requestId: cancelRequestId,
- registrationId: registrationResponse.registrationId,
- venId: venId,
- };
- let error;
- try {
- await rewired.cancelParty(cancelRequest, commonName, otherVenId);
- } catch (e) {
- error = e;
- }
- expect(error).to.be.an('error');
- expect(error.message).to.eql('VenID does not match certificate');
- });
- });
- });
|