@itentialopensource/adapter-tcpwave
Version:
This adapter integrates with system described as: tcpwaveRestapiStore.
1,372 lines (1,299 loc) • 1.37 MB
JavaScript
/* @copyright Itential, LLC 2019 (pre-modifications) */
// Set globals
/* global describe it log pronghornProps */
/* eslint no-unused-vars: warn */
/* eslint no-underscore-dangle: warn */
/* eslint import/no-dynamic-require:warn */
// include required items for testing & logging
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const util = require('util');
const mocha = require('mocha');
const winston = require('winston');
const { expect } = require('chai');
const { use } = require('chai');
const td = require('testdouble');
const log = require('../../utils/logger');
const anything = td.matchers.anything();
// stub and attemptTimeout are used throughout the code so set them here
const isRapidFail = false;
const isSaveMockData = false;
// read in the properties from the sampleProperties files
let adaptdir = __dirname;
if (adaptdir.endsWith('/test/integration')) {
adaptdir = adaptdir.substring(0, adaptdir.length - 17);
} else if (adaptdir.endsWith('/test/unit')) {
adaptdir = adaptdir.substring(0, adaptdir.length - 10);
}
const samProps = require(`${adaptdir}/sampleProperties.json`).properties;
// these variables can be changed to run in integrated mode so easier to set them here
// always check these in with bogus data!!!
samProps.stub = true;
// uncomment if connecting
// samProps.host = 'replace.hostorip.here';
// samProps.authentication.username = 'username';
// samProps.authentication.password = 'password';
// samProps.authentication.token = 'password';
// samProps.protocol = 'http';
// samProps.port = 80;
// samProps.ssl.enabled = false;
// samProps.ssl.accept_invalid_cert = false;
if (samProps.request.attempt_timeout < 30000) {
samProps.request.attempt_timeout = 30000;
}
samProps.devicebroker.enabled = true;
const attemptTimeout = samProps.request.attempt_timeout;
const { stub } = samProps;
// these are the adapter properties. You generally should not need to alter
// any of these after they are initially set up
global.pronghornProps = {
pathProps: {
encrypted: false
},
adapterProps: {
adapters: [{
id: 'Test-tcpwave',
type: 'Tcpwave',
properties: samProps
}]
}
};
global.$HOME = `${__dirname}/../..`;
/**
* Runs the common asserts for test
*/
function runCommonAsserts(data, error) {
assert.equal(undefined, error);
assert.notEqual(undefined, data);
assert.notEqual(null, data);
assert.notEqual(undefined, data.response);
assert.notEqual(null, data.response);
}
/**
* Runs the error asserts for the test
*/
function runErrorAsserts(data, error, code, origin, displayStr) {
assert.equal(null, data);
assert.notEqual(undefined, error);
assert.notEqual(null, error);
assert.notEqual(undefined, error.IAPerror);
assert.notEqual(null, error.IAPerror);
assert.notEqual(undefined, error.IAPerror.displayString);
assert.notEqual(null, error.IAPerror.displayString);
assert.equal(code, error.icode);
assert.equal(origin, error.IAPerror.origin);
assert.equal(displayStr, error.IAPerror.displayString);
}
/**
* @function saveMockData
* Attempts to take data from responses and place them in MockDataFiles to help create Mockdata.
* Note, this was built based on entity file structure for Adapter-Engine 1.6.x
* @param {string} entityName - Name of the entity saving mock data for
* @param {string} actionName - Name of the action saving mock data for
* @param {string} descriptor - Something to describe this test (used as a type)
* @param {string or object} responseData - The data to put in the mock file.
*/
function saveMockData(entityName, actionName, descriptor, responseData) {
// do not need to save mockdata if we are running in stub mode (already has mock data) or if told not to save
if (stub || !isSaveMockData) {
return false;
}
// must have a response in order to store the response
if (responseData && responseData.response) {
let data = responseData.response;
// if there was a raw response that one is better as it is untranslated
if (responseData.raw) {
data = responseData.raw;
try {
const temp = JSON.parse(data);
data = temp;
} catch (pex) {
// do not care if it did not parse as we will just use data
}
}
try {
const base = path.join(__dirname, `../../entities/${entityName}/`);
const mockdatafolder = 'mockdatafiles';
const filename = `mockdatafiles/${actionName}-${descriptor}.json`;
if (!fs.existsSync(base + mockdatafolder)) {
fs.mkdirSync(base + mockdatafolder);
}
// write the data we retrieved
fs.writeFile(base + filename, JSON.stringify(data, null, 2), 'utf8', (errWritingMock) => {
if (errWritingMock) throw errWritingMock;
// update the action file to reflect the changes. Note: We're replacing the default object for now!
fs.readFile(`${base}action.json`, (errRead, content) => {
if (errRead) throw errRead;
// parse the action file into JSON
const parsedJson = JSON.parse(content);
// The object update we'll write in.
const responseObj = {
type: descriptor,
key: '',
mockFile: filename
};
// get the object for method we're trying to change.
const currentMethodAction = parsedJson.actions.find((obj) => obj.name === actionName);
// if the method was not found - should never happen but...
if (!currentMethodAction) {
throw Error('Can\'t find an action for this method in the provided entity.');
}
// if there is a response object, we want to replace the Response object. Otherwise we'll create one.
const actionResponseObj = currentMethodAction.responseObjects.find((obj) => obj.type === descriptor);
// Add the action responseObj back into the array of response objects.
if (!actionResponseObj) {
// if there is a default response object, we want to get the key.
const defaultResponseObj = currentMethodAction.responseObjects.find((obj) => obj.type === 'default');
// save the default key into the new response object
if (defaultResponseObj) {
responseObj.key = defaultResponseObj.key;
}
// save the new response object
currentMethodAction.responseObjects = [responseObj];
} else {
// update the location of the mock data file
actionResponseObj.mockFile = responseObj.mockFile;
}
// Save results
fs.writeFile(`${base}action.json`, JSON.stringify(parsedJson, null, 2), (err) => {
if (err) throw err;
});
});
});
} catch (e) {
log.debug(`Failed to save mock data for ${actionName}. ${e.message}`);
return false;
}
}
// no response to save
log.debug(`No data passed to save into mockdata for ${actionName}`);
return false;
}
// require the adapter that we are going to be using
const Tcpwave = require('../../adapter');
// begin the testing - these should be pretty well defined between the describe and the it!
describe('[integration] Tcpwave Adapter Test', () => {
describe('Tcpwave Class Tests', () => {
const a = new Tcpwave(
pronghornProps.adapterProps.adapters[0].id,
pronghornProps.adapterProps.adapters[0].properties
);
if (isRapidFail) {
const state = {};
state.passed = true;
mocha.afterEach(function x() {
state.passed = state.passed
&& (this.currentTest.state === 'passed');
});
mocha.beforeEach(function x() {
if (!state.passed) {
return this.currentTest.skip();
}
return true;
});
}
describe('#class instance created', () => {
it('should be a class with properties', (done) => {
try {
assert.notEqual(null, a);
assert.notEqual(undefined, a);
const checkId = global.pronghornProps.adapterProps.adapters[0].id;
assert.equal(checkId, a.id);
assert.notEqual(null, a.allProps);
const check = global.pronghornProps.adapterProps.adapters[0].properties.healthcheck.type;
assert.equal(check, a.healthcheckType);
done();
} catch (error) {
log.error(`Test Failure: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#connect', () => {
it('should get connected - no healthcheck', (done) => {
try {
a.healthcheckType = 'none';
a.connect();
try {
assert.equal(true, a.alive);
done();
} catch (error) {
log.error(`Test Failure: ${error}`);
done(error);
}
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
});
it('should get connected - startup healthcheck', (done) => {
try {
a.healthcheckType = 'startup';
a.connect();
try {
assert.equal(true, a.alive);
done();
} catch (error) {
log.error(`Test Failure: ${error}`);
done(error);
}
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
});
});
describe('#healthCheck', () => {
it('should be healthy', (done) => {
try {
a.healthCheck(null, (data) => {
try {
assert.equal(true, a.healthy);
saveMockData('system', 'healthcheck', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
// broker tests
describe('#getDevicesFiltered - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
const opts = {
filter: {
name: 'deviceName'
}
};
a.getDevicesFiltered(opts, (data, error) => {
try {
if (stub) {
if (samProps.devicebroker.getDevicesFiltered[0].handleFailure === 'ignore') {
assert.equal(null, error);
assert.notEqual(undefined, data);
assert.notEqual(null, data);
assert.equal(0, data.total);
assert.equal(0, data.list.length);
} else {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
}
} else {
runCommonAsserts(data, error);
}
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#iapGetDeviceCount - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
const opts = {
filter: {
name: 'deviceName'
}
};
a.iapGetDeviceCount((data, error) => {
try {
if (stub) {
if (samProps.devicebroker.getDevicesFiltered[0].handleFailure === 'ignore') {
assert.equal(null, error);
assert.notEqual(undefined, data);
assert.notEqual(null, data);
assert.equal(0, data.count);
} else {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
}
} else {
runCommonAsserts(data, error);
}
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
// exposed cache tests
describe('#iapPopulateEntityCache - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.iapPopulateEntityCache('Device', (data, error) => {
try {
if (stub) {
assert.equal(null, data);
assert.notEqual(undefined, error);
assert.notEqual(null, error);
done();
} else {
assert.equal(undefined, error);
assert.equal('success', data[0]);
done();
}
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#iapRetrieveEntitiesCache - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.iapRetrieveEntitiesCache('Device', {}, (data, error) => {
try {
if (stub) {
assert.equal(null, data);
assert.notEqual(null, error);
assert.notEqual(undefined, error);
} else {
assert.equal(undefined, error);
assert.notEqual(null, data);
assert.notEqual(undefined, data);
}
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
/*
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*** All code above this comment will be replaced during a migration ***
******************* DO NOT REMOVE THIS COMMENT BLOCK ******************
-----------------------------------------------------------------------
-----------------------------------------------------------------------
*/
const aclServiceAclCreateBodyParam = {
name: 'cardsprod',
newName: 'eurprod',
special: 'TRUE',
value: '10.1.10.172',
refAclName: 'cardsprod',
sequence: 2,
exclude: '10.0.0.0/24',
aclDataList: '[(name = cardsmig, value = 10.0.0.0, exclude = no, sequence = 1)]',
aclElementList: '[10.0.0.1,10.0.0.3,any]',
referenceCount: 3
};
describe('#aclCreate - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.aclCreate(aclServiceAclCreateBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AclService', 'aclCreate', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aclServiceAclMultiDeleteBodyParam = [
'string'
];
describe('#aclMultiDelete - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.aclMultiDelete(aclServiceAclMultiDeleteBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AclService', 'aclMultiDelete', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aclServiceAclUpdateBodyParam = {
name: 'cardsprod',
newName: 'eurprod',
special: 'TRUE',
value: '10.1.10.172',
refAclName: 'cardsprod',
sequence: 2,
exclude: '10.0.0.0/24',
aclDataList: '[(name = cardsmig, value = 10.0.0.0, exclude = no, sequence = 1)]',
aclElementList: '[10.0.0.1,10.0.0.3,any]',
referenceCount: 3
};
describe('#aclUpdate - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.aclUpdate(aclServiceAclUpdateBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AclService', 'aclUpdate', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#aclGet - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.aclGet('fakedata', (data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal(1, data.response.id);
assert.equal('cardsprod', data.response.name);
assert.equal('eurprod', data.response.newName);
assert.equal('Access Control List for the cardsprod.', data.response.description);
assert.equal('TRUE', data.response.special);
assert.equal('10.1.10.172', data.response.value);
assert.equal('cardsprod', data.response.refAclName);
assert.equal(2, data.response.sequence);
assert.equal('10.0.0.0/24', data.response.exclude);
assert.equal('[(name = cardsmig, value = 10.0.0.0, exclude = no, sequence = 1)]', data.response.aclDataList);
assert.equal('[10.0.0.1,10.0.0.3,any]', data.response.aclElementList);
assert.equal(3, data.response.referenceCount);
assert.equal(2017, data.response.created_by);
assert.equal('Stephen', data.response.created_by_name);
assert.equal('3/18/2016 4:37', data.response.created_time);
assert.equal(2019, data.response.updated_by);
assert.equal('John', data.response.updated_by_name);
assert.equal('3/18/2016 4:37', data.response.updated_time);
assert.equal('3/18/2016 3:39', data.response.updated_time_string);
assert.equal('3/18/2016 3:39', data.response.created_time_string);
assert.equal('Stephen', data.response.created_by_login_name);
assert.equal('John', data.response.updated_by_login_name);
} else {
runCommonAsserts(data, error);
}
saveMockData('AclService', 'aclGet', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aclServiceName = 'fakedata';
describe('#aclGetReferences - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.aclGetReferences(aclServiceName, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AclService', 'aclGetReferences', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#aclList - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.aclList((data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal('object', typeof data.response[0]);
assert.equal('object', typeof data.response[1]);
} else {
runCommonAsserts(data, error);
}
saveMockData('AclService', 'aclList', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#aclPage - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.aclPage(null, null, (data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal(20, data.response.total);
assert.equal(40, data.response.recordsTotal);
assert.equal(40, data.response.recordsFiltered);
assert.equal(true, Array.isArray(data.response.data));
} else {
runCommonAsserts(data, error);
}
saveMockData('AclService', 'aclPage', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const activeDirectoryServiceAdUserAuthenticateBodyParam = {
dc_id: 1,
dc_ip: '10.0.0.3',
dc_name: 'dc.tcpwave.com',
domain_name: 'tcpwave.com',
service_type: 'DNS',
principal_name: 'computer.tcpwave.com',
realm: 'TCPWAVE.COM',
encryption_type: 'RC4-HMAC-NT employs 128-bit encryption.',
updated_by_name: '2017',
updated_time: '3/18/2016 3:37',
created_by_name: 'admin',
created_time: '3/18/2016 3:37',
file_data: 'string',
file_name: 'krb5.keytab',
dnsDomainName: 'tcpwave.com',
dnsServerName: 'ns.tcpwave.com',
dnsIp: '10.0.0.2',
dnsId: 1
};
describe('#adUserAuthenticate - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.adUserAuthenticate(activeDirectoryServiceAdUserAuthenticateBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('ActiveDirectoryService', 'adUserAuthenticate', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const activeDirectoryServiceAdUserDeleteBodyParam = [
{
id: 1,
dc_id: 1,
dc_ip: '10.0.0.3',
dc_name: 'dc.tcpwave.com',
domain_name: 'tcpwave.com',
service_type: 'DNS',
principal_type: 'string',
principal_name: 'computer.tcpwave.com',
realm: 'TCPWAVE.COM',
encryption_type: 'RC4-HMAC-NT employs 128-bit encryption.',
updated_by_name: '2017',
updated_time: '3/18/2016 3:37',
created_by_name: 'admin',
created_time: '3/18/2016 3:37',
file_data: 'string',
file_name: 'krb5.keytab',
dnsDomainName: 'tcpwave.com',
dnsServerName: 'ns.tcpwave.com',
dnsIp: '10.0.0.2',
dnsId: 1
}
];
describe('#adUserDelete - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.adUserDelete(activeDirectoryServiceAdUserDeleteBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('ActiveDirectoryService', 'adUserDelete', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const activeDirectoryServiceAdUserAddBodyParam = {
dc_id: 1,
dc_ip: '10.0.0.3',
dc_name: 'dc.tcpwave.com',
domain_name: 'tcpwave.com',
service_type: 'DNS',
principal_name: 'computer.tcpwave.com',
realm: 'TCPWAVE.COM',
encryption_type: 'RC4-HMAC-NT employs 128-bit encryption.',
updated_by_name: '2017',
updated_time: '3/18/2016 3:37',
created_by_name: 'admin',
created_time: '3/18/2016 3:37',
file_data: 'string',
file_name: 'krb5.keytab',
dnsDomainName: 'tcpwave.com',
dnsServerName: 'ns.tcpwave.com',
dnsIp: '10.0.0.2',
dnsId: 1
};
describe('#adUserAdd - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.adUserAdd(activeDirectoryServiceAdUserAddBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('ActiveDirectoryService', 'adUserAdd', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#adUserList - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.adUserList((data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal('object', typeof data.response[0]);
assert.equal('object', typeof data.response[1]);
assert.equal('object', typeof data.response[2]);
} else {
runCommonAsserts(data, error);
}
saveMockData('ActiveDirectoryService', 'adUserList', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const adminGroupServiceCreateBodyParam = {
name: 'Admin-group-1',
oldName: 'Admin-group',
organization_name: 'TCPWave'
};
describe('#create - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.create(adminGroupServiceCreateBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AdminGroupService', 'create', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const adminGroupServiceName = 'fakedata';
const adminGroupServiceOrganizationName = 'fakedata';
describe('#del - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.del(null, adminGroupServiceName, null, adminGroupServiceOrganizationName, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AdminGroupService', 'del', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const adminGroupServiceEditBodyParam = {
name: 'Admin-group-1',
oldName: 'Admin-group',
organization_name: 'TCPWave'
};
describe('#edit - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.edit(adminGroupServiceEditBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AdminGroupService', 'edit', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const adminGroupServiceAdminGroupName = 'fakedata';
describe('#get - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.get(null, adminGroupServiceAdminGroupName, (data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal(121, data.response.id);
assert.equal('Admin-group-1', data.response.name);
assert.equal('Admin-group', data.response.oldName);
assert.equal('Admin group description', data.response.description);
assert.equal(111, data.response.organizationId);
assert.equal('TCPWave', data.response.organizationName);
assert.equal('1479201874000', data.response.updated_time);
assert.equal('admin1', data.response.updated_by_name);
assert.equal('admin2', data.response.created_by_name);
assert.equal('1479201867000', data.response.created_time);
assert.equal('12/15/2016 7:14:17', data.response.updated_time_string);
assert.equal('11/15/2016 6:04:15', data.response.created_time_string);
} else {
runCommonAsserts(data, error);
}
saveMockData('AdminGroupService', 'get', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const adminGroupServiceOrgName = 'fakedata';
describe('#list - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.list(null, adminGroupServiceOrgName, (data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal('object', typeof data.response[0]);
assert.equal('object', typeof data.response[1]);
assert.equal('object', typeof data.response[2]);
} else {
runCommonAsserts(data, error);
}
saveMockData('AdminGroupService', 'list', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const adminGroupServicePage = 555;
const adminGroupServiceRows = 555;
describe('#adminGroupPage - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.adminGroupPage(adminGroupServicePage, adminGroupServiceRows, (data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal(20, data.response.total);
assert.equal(40, data.response.recordsTotal);
assert.equal(40, data.response.recordsFiltered);
assert.equal(true, Array.isArray(data.response.data));
} else {
runCommonAsserts(data, error);
}
saveMockData('AdminGroupService', 'adminGroupPage', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const alarmSubscriptionServiceAddSubscriptionsBodyParam = [
{
id: 44,
contactId: 54,
contactName: 'James Francis Stuart',
contactMail: 'james@tcpwave.com',
componentId: 364,
componentType: 'DNS',
componentName: 'ns0001',
componentAddress: '10.31.2.55',
thresholdId: 5,
thresholdName: 'SYSTEM_CPU',
sendCritical: true,
sendWarning: true,
organizationName: 'TCPWave',
organizationId: 3,
createdBy: 'Stephen',
createdByLoginName: 'Stephen',
createdTime: 'string',
createdTimeString: '07:17:17 02-20-2019'
}
];
describe('#addSubscriptions - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.addSubscriptions(alarmSubscriptionServiceAddSubscriptionsBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AlarmSubscriptionService', 'addSubscriptions', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const alarmSubscriptionServiceDeleteSubscriptionBodyParam = [
{
id: 44,
contactId: 54,
contactName: 'James Francis Stuart',
contactMail: 'james@tcpwave.com',
componentId: 364,
componentType: 'DNS',
componentName: 'ns0001',
componentAddress: '10.31.2.55',
thresholdId: 7,
thresholdName: 'SYSTEM_CPU',
sendCritical: true,
sendWarning: true,
organizationName: 'TCPWave',
organizationId: 8,
createdBy: 'Stephen',
createdByLoginName: 'Stephen',
createdTime: 'string',
createdTimeString: '07:17:17 02-20-2019'
}
];
describe('#deleteSubscription - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.deleteSubscription(alarmSubscriptionServiceDeleteSubscriptionBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AlarmSubscriptionService', 'deleteSubscription', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#categoryList - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.categoryList((data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal('string', data.response[0]);
} else {
runCommonAsserts(data, error);
}
saveMockData('AlarmSubscriptionService', 'categoryList', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const alarmSubscriptionServiceServiceList = 'fakedata';
const alarmSubscriptionServiceOrgName = 'fakedata';
const alarmSubscriptionServiceStart = 555;
const alarmSubscriptionServiceLength = 555;
describe('#listComponents - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.listComponents(alarmSubscriptionServiceServiceList, alarmSubscriptionServiceOrgName, null, alarmSubscriptionServiceStart, alarmSubscriptionServiceLength, null, null, null, (data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal(40, data.response.recordsTotal);
assert.equal(40, data.response.recordsFiltered);
assert.equal(true, Array.isArray(data.response.data));
} else {
runCommonAsserts(data, error);
}
saveMockData('AlarmSubscriptionService', 'listComponents', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#getAlarmSubscriptionList - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.getAlarmSubscriptionList(null, alarmSubscriptionServiceStart, alarmSubscriptionServiceLength, null, null, null, (data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal(40, data.response.recordsTotal);
assert.equal(40, data.response.recordsFiltered);
assert.equal(true, Array.isArray(data.response.data));
} else {
runCommonAsserts(data, error);
}
saveMockData('AlarmSubscriptionService', 'getAlarmSubscriptionList', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const alarmSubscriptionServiceCategory = 'fakedata';
describe('#listCategoryMonitorService - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.listCategoryMonitorService(alarmSubscriptionServiceCategory, (data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal('object', typeof data.response[0]);
assert.equal('object', typeof data.response[1]);
assert.equal('object', typeof data.response[2]);
} else {
runCommonAsserts(data, error);
}
saveMockData('AlarmSubscriptionService', 'listCategoryMonitorService', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#getAlgoList - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.getAlgoList((data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal('object', typeof data.response[0]);
assert.equal('object', typeof data.response[1]);
} else {
runCommonAsserts(data, error);
}
saveMockData('AlgorithmService', 'getAlgoList', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#tsigList - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.tsigList((data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal('object', typeof data.response[0]);
assert.equal('object', typeof data.response[1]);
} else {
runCommonAsserts(data, error);
}
saveMockData('AlgorithmService', 'tsigList', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const applianceGroupServicePostAppliancegroupAddBodyParam = {
organization_id: 990,
organization_name: 'EARTH'
};
describe('#postAppliancegroupAdd - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.postAppliancegroupAdd(applianceGroupServicePostAppliancegroupAddBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('ApplianceGroupService', 'postAppliancegroupAdd', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const applianceGroupServicePostAppliancegroupEditBodyParam = {
organization_id: 990,
organization_name: 'EARTH'
};
describe('#postAppliancegroupEdit - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.postAppliancegroupEdit(applianceGroupServicePostAppliancegroupEditBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('ApplianceGroupService', 'postAppliancegroupEdit', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const applianceGroupServiceName = 'fakedata';
const applianceGroupServiceOrganization = 'fakedata';
describe('#deleteApplianceGroup - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.deleteApplianceGroup(applianceGroupServiceName, applianceGroupServiceOrganization, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-tcpwave-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('ApplianceGroupService', 'deleteApplianceGroup', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#getApplianceGroup - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.getApplianceGroup(applianceGroupServiceName, applianceGroupServiceOrganization, (data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal(1234, data.response.id);
assert.equal('Test', data.response.name);
assert.equal('This is a appliance group.', data.response.description);
assert.equal(990, data.response.organization_id);