@itentialopensource/adapter-adtran_mosaic_cloud_platform
Version:
This adapter integrates with system described as: ADTRAN® Mosaic Cloud Platform (Mosaic CP).
1,360 lines (1,286 loc) • 206 kB
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-adtran_mosaic_cloud_platform',
type: 'AdtranMosaicCloudPlatform',
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 AdtranMosaicCloudPlatform = require('../../adapter');
// begin the testing - these should be pretty well defined between the describe and the it!
describe('[integration] Adtran_mosaic_cloud_platform Adapter Test', () => {
describe('AdtranMosaicCloudPlatform Class Tests', () => {
const a = new AdtranMosaicCloudPlatform(
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-adtran_mosaic_cloud_platform-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-adtran_mosaic_cloud_platform-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 tokenManagementReleaseaSessionTokenBodyParam = {
token: 'string'
};
describe('#releaseaSessionToken - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.releaseaSessionToken(tokenManagementReleaseaSessionTokenBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('TokenManagement', 'releaseaSessionToken', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const tokenManagementRequestaSessionTokenBodyParam = {
username: 'string',
password: 'string'
};
describe('#requestaSessionToken - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.requestaSessionToken(tokenManagementRequestaSessionTokenBodyParam, (data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal('832e64d6097515d558464ec0f776149645812ac8ffeaf63a04d130fadb117f91', data.response.token);
} else {
runCommonAsserts(data, error);
}
saveMockData('TokenManagement', 'requestaSessionToken', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aAAConfigModifyingPasswordSecuritySettingBodyParam = {
'password-expiry-days': 2,
'expiration-mode': 'string'
};
describe('#modifyingPasswordSecuritySetting - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.modifyingPasswordSecuritySetting(aAAConfigModifyingPasswordSecuritySettingBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAConfig', 'modifyingPasswordSecuritySetting', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#retrievePasswordSecuritySetting - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.retrievePasswordSecuritySetting((data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal('expire-now', data.response['expiration-mode']);
assert.equal(1, data.response['password-uppercase-min-len']);
assert.equal(180, data.response['password-history-days']);
assert.equal(8, data.response['password-min-len']);
assert.equal(90, data.response['password-expiry-days']);
assert.equal(128, data.response['password-max-len']);
assert.equal(5, data.response['max-failed-logins']);
assert.equal(1, data.response['password-min-digits']);
assert.equal(5, data.response['password-notice-days']);
assert.equal(5, data.response['password-history-length']);
assert.equal(5, data.response['account-lock-period']);
assert.equal(true, Array.isArray(data.response['authorization-mode']));
assert.equal(false, data.response['password-username-allowed']);
assert.equal(1, data.response['password-min-special-char']);
assert.equal('[0-9a-zA-Z!@#$%^&*]', data.response['password-valid-char-set']);
assert.equal(true, Array.isArray(data.response['authentication-mode']));
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAConfig', 'retrievePasswordSecuritySetting', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aAAPermissionGroupsCreateGroupBodyParam = {
name: 'string',
permissions: [
'string'
],
domains: [
'string'
]
};
describe('#createGroup - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.createGroup('g1', aAAPermissionGroupsCreateGroupBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAPermissionGroups', 'createGroup', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#getAllGroups - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.getAllGroups((data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal('object', typeof data.response[0]);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAPermissionGroups', 'getAllGroups', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#getGroup - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.getGroup('group1', (data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal(true, Array.isArray(data.response.domains));
assert.equal('read-only-user', data.response.name);
assert.equal(true, Array.isArray(data.response.permissions));
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAPermissionGroups', 'getGroup', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#retrieveModulePermissions - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.retrieveModulePermissions((data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal(true, Array.isArray(data.response.module));
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAPermissionGroups', 'retrieveModulePermissions', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aAAUsersCreateVendorSpecificAttributeMappingforRadiusBodyParam = {
'vendor-id': 3,
'vendor-type': 2,
'vendor-value': 'string',
group: [
'string'
]
};
describe('#createVendorSpecificAttributeMappingforRadius - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.createVendorSpecificAttributeMappingforRadius(aAAUsersCreateVendorSpecificAttributeMappingforRadiusBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'createVendorSpecificAttributeMappingforRadius', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aAAUsersCreateUserAccountBodyParam = {
username: 'string',
password: 'string'
};
describe('#createUserAccount - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.createUserAccount(aAAUsersCreateUserAccountBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'createUserAccount', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aAAUsersDeleteUserBodyParam = {
username: 'string'
};
describe('#deleteUser - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.deleteUser(aAAUsersDeleteUserBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'deleteUser', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aAAUsersExpirePasswordBodyParam = {
username: 'string'
};
describe('#expirePassword - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.expirePassword(aAAUsersExpirePasswordBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'expirePassword', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#logoutAllUsers - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.logoutAllUsers((data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'logoutAllUsers', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aAAUsersLogoutUserBodyParam = {
username: 'string'
};
describe('#logoutUser - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.logoutUser(aAAUsersLogoutUserBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'logoutUser', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aAAUsersOverridePasswordBodyParam = {
username: 'string',
password: 'string'
};
describe('#overridePassword - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.overridePassword(aAAUsersOverridePasswordBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'overridePassword', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aAAUsersResetPasswordBodyParam = {
username: 'string',
'old-password': 'string',
'new-password': 'string'
};
describe('#resetPassword - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.resetPassword(aAAUsersResetPasswordBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'resetPassword', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aAAUsersUsername = 'fakedata';
const aAAUsersSetPasswordBodyParam = {
password: 'string'
};
describe('#setPassword - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.setPassword(aAAUsersUsername, aAAUsersSetPasswordBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'setPassword', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#getVendorSpecificAttributeMappingforRadius - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.getVendorSpecificAttributeMappingforRadius((data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'getVendorSpecificAttributeMappingforRadius', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aAAUsersModifyVendorSpecificAttributeMappingforRadiusBodyParam = {
'vendor-id': 4,
'vendor-type': 2,
'vendor-value': 'string',
group: [
'string'
]
};
describe('#modifyVendorSpecificAttributeMappingforRadius - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.modifyVendorSpecificAttributeMappingforRadius('group1', aAAUsersModifyVendorSpecificAttributeMappingforRadiusBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'modifyVendorSpecificAttributeMappingforRadius', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#getAllUsers - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.getAllUsers((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('AAAUsers', 'getAllUsers', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aAAUsersAssignUsertoUserGroupBodyParam = {
group: [
'string'
]
};
describe('#assignUsertoUserGroup - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.assignUsertoUserGroup('user1', aAAUsersAssignUsertoUserGroupBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'assignUsertoUserGroup', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const aAAUsersModifyUserAAAModesBodyParam = {
'authentication-mode': [
'string'
],
'authorization-mode': [
'string'
],
'accounting-mode': [
'string'
]
};
describe('#modifyUserAAAModes - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.modifyUserAAAModes('user1', aAAUsersModifyUserAAAModesBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'modifyUserAAAModes', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#getUser - errors', () => {
it('should work if integrated or standalone with mockdata', (done) => {
try {
a.getUser('user1', (data, error) => {
try {
if (stub) {
runCommonAsserts(data, error);
assert.equal('internal', data.response['user-type']);
assert.equal('2020-05-05T09:25:19.807Z', data.response['last-login-time']);
assert.equal('Test-Account', data.response.username);
assert.equal('active', data.response['account-status']);
assert.equal('2020-08-03T09:25:19.850Z', data.response['password-expiration-date']);
assert.equal(0, data.response['failed-login-attempts']);
assert.equal(90, data.response['password-expiry-days']);
assert.equal('', data.response['account-expiration-date']);
assert.equal(5, data.response['max-failed-logins']);
assert.equal(false, data.response['logged-in']);
assert.equal(5, data.response['password-notice-days']);
assert.equal(5, data.response['account-lock-period']);
assert.equal(true, Array.isArray(data.response['authorization-mode']));
assert.equal(true, Array.isArray(data.response['authentication-mode']));
assert.equal(true, Array.isArray(data.response.group));
} else {
runCommonAsserts(data, error);
}
saveMockData('AAAUsers', 'getUser', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const accountingLogsGetAccountLogsBetweenDatesandTimeBodyParam = {
'time-period': {
'from-time': '2020-01-02T00:00:00.000Z',
'to-time': '2020-04-02T12:00:00.000Z'
}
};
describe('#getAccountLogsBetweenDatesandTime - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.getAccountLogsBetweenDatesandTime(accountingLogsGetAccountLogsBetweenDatesandTimeBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('AccountingLogs', 'getAccountLogsBetweenDatesandTime', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const credentialsCreateCredentialBodyParam = {
name: 'string',
'key-authentication': {
username: 'root',
key: '{{basic-auth-password}}'
}
};
describe('#createCredential - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.createCredential(credentialsCreateCredentialBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('Credentials', 'createCredential', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#getAllCredentials - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.getAllCredentials((data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('Credentials', 'getAllCredentials', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
describe('#getCredentialsByName - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.getCredentialsByName((data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('Credentials', 'getCredentialsByName', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const credentialsUpdateCredentialPasswordOnlyAuthenticationBodyParam = {
name: 'string',
'password-only-authentication': {
password: '{{basic-auth-password}}'
}
};
describe('#updateCredentialPasswordOnlyAuthentication - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.updateCredentialPasswordOnlyAuthentication('cred1', credentialsUpdateCredentialPasswordOnlyAuthenticationBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('Credentials', 'updateCredentialPasswordOnlyAuthentication', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const policyCreateExternalPolicyRADIUSBodyParam = {
name: 'string',
'retry-times': 4,
'use-for-non-local-users': true,
radius: {
host: '10.2.1.1',
'auth-port': 1812,
timeout: 200,
'shared-secret-credential': 'credential_2',
'accounting-port': 1813
}
};
describe('#createExternalPolicyRADIUS - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.createExternalPolicyRADIUS(policyCreateExternalPolicyRADIUSBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('Policy', 'createExternalPolicyRADIUS', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const policyUpdateExternalPolicyRADIUSBodyParam = {
name: 'string',
'retry-times': 6,
'use-for-non-local-users': false,
radius: {
host: '10.2.1.1',
'auth-port': 1812,
timeout: 200,
'shared-secret-credential': 'credential_2',
'accounting-port': 1813
}
};
describe('#updateExternalPolicyRADIUS - errors', () => {
it('should work if integrated but since no mockdata should error when run standalone', (done) => {
try {
a.updateExternalPolicyRADIUS('auth1', policyUpdateExternalPolicyRADIUSBodyParam, (data, error) => {
try {
if (stub) {
const displayE = 'Error 400 received on request';
runErrorAsserts(data, error, 'AD.500', 'Test-adtran_mosaic_cloud_platform-connectorRest-handleEndResponse', displayE);
} else {
runCommonAsserts(data, error);
}
saveMockData('Policy', 'updateExternalPolicyRADIUS', 'default', data);
done();
} catch (err) {
log.error(`Test Failure: ${err}`);
done(err);
}
});
} catch (error) {
log.error(`Adapter Exception: ${error}`);
done(error);
}
}).timeout(attemptTimeout);
});
const policyUpdateExternalPolicyTACACSBodyParam = {
name: 'string',
'retry-times': 4,
'use-for-non-local-users': false,
tacacsplus: {
host: '10.27.28.44',
'auth-port': 49,
timeout: 6000,
'shared-secret-credential': 'credential_2',
'single-connect': true
}
};
describe('#updateExternalPolicyTACACS - errors', () => {
it('should work if integrated but since no mockdata should error