@itentialopensource/adapter-webex_teams 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.js +12 -12
  3. package/AUTH.md +39 -0
  4. package/BROKER.md +199 -0
  5. package/CALLS.md +169 -0
  6. package/CHANGELOG.md +41 -18
  7. package/CODE_OF_CONDUCT.md +12 -17
  8. package/CONTRIBUTING.md +88 -74
  9. package/ENHANCE.md +69 -0
  10. package/PROPERTIES.md +641 -0
  11. package/README.md +247 -395
  12. package/SUMMARY.md +9 -0
  13. package/SYSTEMINFO.md +11 -0
  14. package/TROUBLESHOOT.md +47 -0
  15. package/adapter.js +898 -35
  16. package/adapterBase.js +1331 -50
  17. package/entities/.generic/action.json +214 -0
  18. package/entities/.generic/schema.json +28 -0
  19. package/entities/.system/action.json +3 -3
  20. package/entities/.system/schemaTokenReq.json +24 -0
  21. package/entities/.system/schemaTokenResp.json +1 -1
  22. package/error.json +12 -0
  23. package/package.json +47 -23
  24. package/pronghorn.json +642 -0
  25. package/propertiesDecorators.json +14 -0
  26. package/propertiesSchema.json +507 -13
  27. package/refs?service=git-upload-pack +0 -0
  28. package/report/adapterInfo.json +10 -0
  29. package/report/updateReport1594310783472.json +95 -0
  30. package/report/updateReport1615908902547.json +95 -0
  31. package/report/updateReport1653575821854.json +120 -0
  32. package/sampleProperties.json +115 -11
  33. package/storage/metrics.json +692 -0
  34. package/test/integration/adapterTestBasicGet.js +85 -0
  35. package/test/integration/adapterTestConnectivity.js +93 -0
  36. package/test/integration/adapterTestIntegration.js +42 -105
  37. package/test/unit/adapterBaseTestUnit.js +949 -0
  38. package/test/unit/adapterTestUnit.js +683 -144
  39. package/utils/adapterInfo.js +206 -0
  40. package/utils/addAuth.js +94 -0
  41. package/utils/artifactize.js +9 -14
  42. package/utils/basicGet.js +50 -0
  43. package/utils/checkMigrate.js +63 -0
  44. package/utils/entitiesToDB.js +179 -0
  45. package/utils/findPath.js +74 -0
  46. package/utils/modify.js +154 -0
  47. package/utils/packModificationScript.js +1 -1
  48. package/utils/patches2bundledDeps.js +90 -0
  49. package/utils/pre-commit.sh +4 -1
  50. package/utils/removeHooks.js +20 -0
  51. package/utils/tbScript.js +184 -0
  52. package/utils/tbUtils.js +469 -0
  53. package/utils/testRunner.js +16 -16
  54. package/utils/troubleshootingAdapter.js +190 -0
  55. package/gl-code-quality-report.json +0 -1
@@ -0,0 +1,85 @@
1
+ /* @copyright Itential, LLC 2020 */
2
+
3
+ /* global describe context before after */
4
+ /* eslint global-require: warn */
5
+ /* eslint no-unused-vars: warn */
6
+ /* eslint import/no-extraneous-dependencies: warn */
7
+ /* eslint import/no-dynamic-require: warn */
8
+ /* eslint import/no-unresolved: warn */
9
+
10
+ const mocha = require('mocha');
11
+ const path = require('path');
12
+ const assert = require('assert');
13
+ const itParam = require('mocha-param');
14
+
15
+ const utils = require('../../utils/tbUtils');
16
+ const basicGet = require('../../utils/basicGet');
17
+ const { name } = require('../../package.json');
18
+ const { methods } = require('../../pronghorn.json');
19
+
20
+ const getPronghornProps = (iapDir) => {
21
+ const { Discovery } = require('@itential/itential-utils');
22
+ console.log('Retrieving properties.json file...');
23
+ const rawProps = require(path.join(iapDir, 'properties.json'));
24
+ console.log('Decrypting properties...');
25
+ const discovery = new Discovery();
26
+ const pronghornProps = utils.decryptProperties(rawProps, path.join(__dirname, '..'), discovery);
27
+ console.log('Found properties.\n');
28
+ return pronghornProps;
29
+ };
30
+
31
+ let a;
32
+
33
+ describe('[integration] Adapter BasicGET Test', () => {
34
+ context('Testing GET calls without query parameters', () => {
35
+ before(async () => {
36
+ const iapDir = path.join(__dirname, '../../../../../');
37
+ if (!utils.areWeUnderIAPinstallationDirectory()) {
38
+ const sampleProperties = require('../../sampleProperties.json');
39
+ const adapter = { properties: sampleProperties };
40
+ a = basicGet.getAdapterInstance(adapter);
41
+ } else {
42
+ const pronghornProps = getPronghornProps(iapDir);
43
+ console.log('Connecting to Database...');
44
+ const database = await basicGet.connect(pronghornProps);
45
+ console.log('Connection established.');
46
+ const adapter = await database.collection(utils.SERVICE_CONFIGS_COLLECTION).findOne(
47
+ { model: name }
48
+ );
49
+ a = basicGet.getAdapterInstance(adapter);
50
+ }
51
+ });
52
+
53
+ after((done) => {
54
+ done();
55
+ });
56
+
57
+ const basicGets = methods.filter((method) => (method.route.verb === 'GET' && method.input.length === 0));
58
+ if (basicGets.length === 0) {
59
+ console.log('No non-parameter GET calls found.');
60
+ process.exit(0);
61
+ }
62
+ const functionNames = basicGets.map((g) => g.name);
63
+ const request = function request(f, ad) {
64
+ return new Promise((resolve, reject) => {
65
+ const getRespCode = (resp) => {
66
+ if (resp) {
67
+ if (resp.metrics.code !== 200) {
68
+ console.log('\x1b[31m', `Testing ${f} \nResponseCode: ${resp.metrics.code}`);
69
+ }
70
+ resolve(resp.metrics.code);
71
+ } else {
72
+ console.log('\x1b[31m', `call ${f} results in failure`);
73
+ reject(new Error(`${f} failed`));
74
+ }
75
+ };
76
+ ad[f](getRespCode, console.log);
77
+ });
78
+ };
79
+
80
+ itParam('GET call should return 200', functionNames, (fname) => {
81
+ console.log(`\t ${fname}`);
82
+ return request(fname, a).then((result) => assert.equal(result, 200));
83
+ });
84
+ });
85
+ });
@@ -0,0 +1,93 @@
1
+ /* @copyright Itential, LLC 2020 */
2
+
3
+ /* global describe it context before after */
4
+ /* eslint no-unused-vars: warn */
5
+
6
+ const mocha = require('mocha');
7
+ const assert = require('assert');
8
+ const diagnostics = require('network-diagnostics');
9
+
10
+ let host;
11
+ process.argv.forEach((val) => {
12
+ if (val.indexOf('--HOST') === 0) {
13
+ [, host] = val.split('=');
14
+ }
15
+ });
16
+
17
+ describe('[integration] Adapter Test', () => {
18
+ context(`Testing network connection on ${host}`, () => {
19
+ before(() => {
20
+ diagnostics.setTestURL(host);
21
+ });
22
+
23
+ after((done) => {
24
+ done();
25
+ });
26
+
27
+ it('DNS resolve', (done) => {
28
+ diagnostics.haveDNS((result) => {
29
+ try {
30
+ assert.equal(result, true);
31
+ done();
32
+ } catch (error) {
33
+ done(error);
34
+ }
35
+ });
36
+ });
37
+
38
+ it('Responds to ping', (done) => {
39
+ diagnostics.havePing((result) => {
40
+ try {
41
+ assert.equal(result, true);
42
+ done();
43
+ } catch (error) {
44
+ done(error);
45
+ }
46
+ });
47
+ });
48
+
49
+ it('Support HTTP on port 80', (done) => {
50
+ diagnostics.haveHTTP((result) => {
51
+ try {
52
+ assert.equal(result, true);
53
+ done();
54
+ } catch (error) {
55
+ done(error);
56
+ }
57
+ });
58
+ });
59
+
60
+ it('Support HTTPS on port 443', (done) => {
61
+ diagnostics.haveHTTPS((result) => {
62
+ try {
63
+ assert.equal(result, true);
64
+ done();
65
+ } catch (error) {
66
+ done(error);
67
+ }
68
+ });
69
+ });
70
+
71
+ it('Support IPv4', (done) => {
72
+ diagnostics.haveIPv4Async((result) => {
73
+ try {
74
+ assert.equal(result, true);
75
+ done();
76
+ } catch (error) {
77
+ done(error);
78
+ }
79
+ });
80
+ });
81
+
82
+ it('Support IPv6', (done) => {
83
+ diagnostics.haveIPv6Async((result) => {
84
+ try {
85
+ assert.equal(result, true);
86
+ done();
87
+ } catch (error) {
88
+ done(error);
89
+ }
90
+ });
91
+ });
92
+ });
93
+ });
@@ -3,6 +3,8 @@
3
3
  // Set globals
4
4
  /* global describe it log pronghornProps */
5
5
  /* eslint no-unused-vars: warn */
6
+ /* eslint no-underscore-dangle: warn */
7
+ /* eslint import/no-dynamic-require:warn */
6
8
 
7
9
  // include required items for testing & logging
8
10
  const assert = require('assert');
@@ -13,25 +15,39 @@ const winston = require('winston');
13
15
  const { expect } = require('chai');
14
16
  const { use } = require('chai');
15
17
  const td = require('testdouble');
18
+ const util = require('util');
16
19
 
17
20
  const anything = td.matchers.anything();
18
21
 
19
22
  // stub and attemptTimeout are used throughout the code so set them here
20
23
  let logLevel = 'none';
21
- const stub = true;
22
24
  const isRapidFail = false;
23
25
  const isSaveMockData = false;
24
- const attemptTimeout = 5000;
26
+
27
+ // read in the properties from the sampleProperties files
28
+ let adaptdir = __dirname;
29
+ if (adaptdir.endsWith('/test/integration')) {
30
+ adaptdir = adaptdir.substring(0, adaptdir.length - 17);
31
+ } else if (adaptdir.endsWith('/test/unit')) {
32
+ adaptdir = adaptdir.substring(0, adaptdir.length - 10);
33
+ }
34
+ const samProps = require(`${adaptdir}/sampleProperties.json`).properties;
25
35
 
26
36
  // these variables can be changed to run in integrated mode so easier to set them here
27
37
  // always check these in with bogus data!!!
28
- const host = 'replace.hostorip.here';
29
- const username = 'username';
30
- const password = 'password';
31
- const protocol = 'http';
32
- const port = 80;
33
- const sslenable = false;
34
- const sslinvalid = false;
38
+ samProps.stub = true;
39
+ samProps.host = 'replace.hostorip.here';
40
+ samProps.authentication.username = 'username';
41
+ samProps.authentication.password = 'password';
42
+ samProps.protocol = 'http';
43
+ samProps.port = 80;
44
+ samProps.ssl.enabled = false;
45
+ samProps.ssl.accept_invalid_cert = false;
46
+ if (samProps.request.attempt_timeout < 30000) {
47
+ samProps.request.attempt_timeout = 30000;
48
+ }
49
+ const attemptTimeout = samProps.request.attempt_timeout;
50
+ const { stub } = samProps;
35
51
 
36
52
  // these are the adapter properties. You generally should not need to alter
37
53
  // any of these after they are initially set up
@@ -41,89 +57,9 @@ global.pronghornProps = {
41
57
  },
42
58
  adapterProps: {
43
59
  adapters: [{
44
- id: 'Test-WebexTeams',
60
+ id: 'Test-webex_teams',
45
61
  type: 'WebexTeams',
46
- properties: {
47
- host,
48
- port,
49
- base_path: '//api',
50
- version: 'v1.3.1',
51
- cache_location: 'none',
52
- save_metric: false,
53
- stub,
54
- protocol,
55
- authentication: {
56
- auth_method: 'no_authentication',
57
- username,
58
- password,
59
- token: '',
60
- token_timeout: -1,
61
- token_cache: 'local',
62
- invalid_token_error: 401,
63
- auth_field: 'header.headers.Authorization',
64
- auth_field_format: 'Basic {b64}{username}:{password}{/b64}'
65
- },
66
- healthcheck: {
67
- type: 'none',
68
- frequency: 60000
69
- },
70
- throttle: {
71
- throttle_enabled: false,
72
- number_pronghorns: 1,
73
- sync_async: 'sync',
74
- max_in_queue: 1000,
75
- concurrent_max: 1,
76
- expire_timeout: 0,
77
- avg_runtime: 200
78
- },
79
- request: {
80
- number_redirects: 0,
81
- number_retries: 3,
82
- limit_retry_error: 0,
83
- failover_codes: [],
84
- attempt_timeout: attemptTimeout,
85
- global_request: {
86
- payload: {},
87
- uriOptions: {},
88
- addlHeaders: {},
89
- authData: {}
90
- },
91
- healthcheck_on_timeout: true,
92
- return_raw: true,
93
- archiving: false
94
- },
95
- proxy: {
96
- enabled: false,
97
- host: '',
98
- port: 1,
99
- protocol: 'http'
100
- },
101
- ssl: {
102
- ecdhCurve: '',
103
- enabled: sslenable,
104
- accept_invalid_cert: sslinvalid,
105
- ca_file: '',
106
- key_file: '',
107
- cert_file: '',
108
- secure_protocol: '',
109
- ciphers: ''
110
- },
111
- mongo: {
112
- host: '',
113
- port: 0,
114
- database: '',
115
- username,
116
- password: '',
117
- replSet: '',
118
- db_ssl: {
119
- enabled: false,
120
- accept_invalid_cert: false,
121
- ca_file: '',
122
- key_file: '',
123
- cert_file: ''
124
- }
125
- }
126
- }
62
+ properties: samProps
127
63
  }]
128
64
  }
129
65
  };
@@ -159,7 +95,7 @@ process.argv.forEach((val) => {
159
95
  });
160
96
 
161
97
  // need to set global logging
162
- global.log = new (winston.Logger)({
98
+ global.log = winston.createLogger({
163
99
  level: logLevel,
164
100
  levels: myCustomLevels.levels,
165
101
  transports: [
@@ -253,7 +189,7 @@ function saveMockData(entityName, actionName, descriptor, responseData) {
253
189
  };
254
190
 
255
191
  // get the object for method we're trying to change.
256
- const currentMethodAction = parsedJson.actions.find(obj => obj.name === actionName);
192
+ const currentMethodAction = parsedJson.actions.find((obj) => obj.name === actionName);
257
193
 
258
194
  // if the method was not found - should never happen but...
259
195
  if (!currentMethodAction) {
@@ -261,12 +197,12 @@ function saveMockData(entityName, actionName, descriptor, responseData) {
261
197
  }
262
198
 
263
199
  // if there is a response object, we want to replace the Response object. Otherwise we'll create one.
264
- const actionResponseObj = currentMethodAction.responseObjects.find(obj => obj.type === descriptor);
200
+ const actionResponseObj = currentMethodAction.responseObjects.find((obj) => obj.type === descriptor);
265
201
 
266
202
  // Add the action responseObj back into the array of response objects.
267
203
  if (!actionResponseObj) {
268
204
  // if there is a default response object, we want to get the key.
269
- const defaultResponseObj = currentMethodAction.responseObjects.find(obj => obj.type === 'default');
205
+ const defaultResponseObj = currentMethodAction.responseObjects.find((obj) => obj.type === 'default');
270
206
 
271
207
  // save the default key into the new response object
272
208
  if (defaultResponseObj) {
@@ -297,9 +233,8 @@ function saveMockData(entityName, actionName, descriptor, responseData) {
297
233
  return false;
298
234
  }
299
235
 
300
-
301
236
  // require the adapter that we are going to be using
302
- const WebexTeams = require('../../adapter.js');
237
+ const WebexTeams = require('../../adapter');
303
238
 
304
239
  // begin the testing - these should be pretty well defined between the describe and the it!
305
240
  describe('[integration] WebexTeams Adapter Test', () => {
@@ -330,6 +265,8 @@ describe('[integration] WebexTeams Adapter Test', () => {
330
265
  try {
331
266
  assert.notEqual(null, a);
332
267
  assert.notEqual(undefined, a);
268
+ const checkId = global.pronghornProps.adapterProps.adapters[0].id;
269
+ assert.equal(checkId, a.id);
333
270
  assert.notEqual(null, a.allProps);
334
271
  const check = global.pronghornProps.adapterProps.adapters[0].properties.healthcheck.type;
335
272
  assert.equal(check, a.healthcheckType);
@@ -564,7 +501,7 @@ describe('[integration] WebexTeams Adapter Test', () => {
564
501
  try {
565
502
  if (stub) {
566
503
  const displayE = 'Error 400 received on request';
567
- runErrorAsserts(data, error, 'AD.500', 'Test-WebexTeams-connectorRest-handleEndResponse', displayE);
504
+ runErrorAsserts(data, error, 'AD.500', 'Test-webex_teams-connectorRest-handleEndResponse', displayE);
568
505
  } else {
569
506
  runCommonAsserts(data, error);
570
507
  }
@@ -760,7 +697,7 @@ describe('[integration] WebexTeams Adapter Test', () => {
760
697
  try {
761
698
  if (stub) {
762
699
  const displayE = 'Error 400 received on request';
763
- runErrorAsserts(data, error, 'AD.500', 'Test-WebexTeams-connectorRest-handleEndResponse', displayE);
700
+ runErrorAsserts(data, error, 'AD.500', 'Test-webex_teams-connectorRest-handleEndResponse', displayE);
764
701
  } else {
765
702
  runCommonAsserts(data, error);
766
703
  }
@@ -915,7 +852,7 @@ describe('[integration] WebexTeams Adapter Test', () => {
915
852
  try {
916
853
  if (stub) {
917
854
  const displayE = 'Error 400 received on request';
918
- runErrorAsserts(data, error, 'AD.500', 'Test-WebexTeams-connectorRest-handleEndResponse', displayE);
855
+ runErrorAsserts(data, error, 'AD.500', 'Test-webex_teams-connectorRest-handleEndResponse', displayE);
919
856
  } else {
920
857
  runCommonAsserts(data, error);
921
858
  }
@@ -1046,7 +983,7 @@ describe('[integration] WebexTeams Adapter Test', () => {
1046
983
  try {
1047
984
  if (stub) {
1048
985
  const displayE = 'Error 400 received on request';
1049
- runErrorAsserts(data, error, 'AD.500', 'Test-WebexTeams-connectorRest-handleEndResponse', displayE);
986
+ runErrorAsserts(data, error, 'AD.500', 'Test-webex_teams-connectorRest-handleEndResponse', displayE);
1050
987
  } else {
1051
988
  runCommonAsserts(data, error);
1052
989
  }
@@ -1189,7 +1126,7 @@ describe('[integration] WebexTeams Adapter Test', () => {
1189
1126
  try {
1190
1127
  if (stub) {
1191
1128
  const displayE = 'Error 400 received on request';
1192
- runErrorAsserts(data, error, 'AD.500', 'Test-WebexTeams-connectorRest-handleEndResponse', displayE);
1129
+ runErrorAsserts(data, error, 'AD.500', 'Test-webex_teams-connectorRest-handleEndResponse', displayE);
1193
1130
  } else {
1194
1131
  runCommonAsserts(data, error);
1195
1132
  }
@@ -1341,7 +1278,7 @@ describe('[integration] WebexTeams Adapter Test', () => {
1341
1278
  try {
1342
1279
  if (stub) {
1343
1280
  const displayE = 'Error 400 received on request';
1344
- runErrorAsserts(data, error, 'AD.500', 'Test-WebexTeams-connectorRest-handleEndResponse', displayE);
1281
+ runErrorAsserts(data, error, 'AD.500', 'Test-webex_teams-connectorRest-handleEndResponse', displayE);
1345
1282
  } else {
1346
1283
  runCommonAsserts(data, error);
1347
1284
  }
@@ -1511,7 +1448,7 @@ describe('[integration] WebexTeams Adapter Test', () => {
1511
1448
  try {
1512
1449
  if (stub) {
1513
1450
  const displayE = 'Error 400 received on request';
1514
- runErrorAsserts(data, error, 'AD.500', 'Test-WebexTeams-connectorRest-handleEndResponse', displayE);
1451
+ runErrorAsserts(data, error, 'AD.500', 'Test-webex_teams-connectorRest-handleEndResponse', displayE);
1515
1452
  } else {
1516
1453
  runCommonAsserts(data, error);
1517
1454
  }
@@ -1705,7 +1642,7 @@ describe('[integration] WebexTeams Adapter Test', () => {
1705
1642
  try {
1706
1643
  if (stub) {
1707
1644
  const displayE = 'Error 400 received on request';
1708
- runErrorAsserts(data, error, 'AD.500', 'Test-WebexTeams-connectorRest-handleEndResponse', displayE);
1645
+ runErrorAsserts(data, error, 'AD.500', 'Test-webex_teams-connectorRest-handleEndResponse', displayE);
1709
1646
  } else {
1710
1647
  runCommonAsserts(data, error);
1711
1648
  }