@itentialopensource/adapter-microsoft_graph 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. package/.eslintignore +6 -0
  2. package/.eslintrc.js +18 -0
  3. package/.gitlab/.gitkeep +0 -0
  4. package/.gitlab/issue_templates/.gitkeep +0 -0
  5. package/.gitlab/issue_templates/Default.md +17 -0
  6. package/.gitlab/issue_templates/bugReportTemplate.md +42 -0
  7. package/.gitlab/issue_templates/featureRequestTemplate.md +14 -0
  8. package/.jshintrc +0 -0
  9. package/AUTH.md +39 -0
  10. package/BROKER.md +199 -0
  11. package/CALLS.md +170 -0
  12. package/CHANGELOG.md +9 -0
  13. package/CODE_OF_CONDUCT.md +43 -0
  14. package/CONTRIBUTING.md +172 -0
  15. package/ENHANCE.md +69 -0
  16. package/LICENSE +201 -0
  17. package/PROPERTIES.md +641 -0
  18. package/README.md +337 -0
  19. package/SUMMARY.md +9 -0
  20. package/SYSTEMINFO.md +11 -0
  21. package/TROUBLESHOOT.md +47 -0
  22. package/adapter.js +18798 -0
  23. package/adapterBase.js +1787 -0
  24. package/entities/.generic/action.json +214 -0
  25. package/entities/.generic/schema.json +28 -0
  26. package/entities/.system/action.json +50 -0
  27. package/entities/.system/mockdatafiles/getToken-default.json +3 -0
  28. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  29. package/entities/.system/schema.json +19 -0
  30. package/entities/.system/schemaTokenReq.json +53 -0
  31. package/entities/.system/schemaTokenResp.json +53 -0
  32. package/entities/Applications/action.json +127 -0
  33. package/entities/Applications/schema.json +35 -0
  34. package/entities/AzureADDevice/action.json +106 -0
  35. package/entities/AzureADDevice/schema.json +45 -0
  36. package/entities/Batch/action.json +24 -0
  37. package/entities/Batch/schema.json +19 -0
  38. package/entities/CaseCreation/action.json +249 -0
  39. package/entities/CaseCreation/schema.json +30 -0
  40. package/entities/Catalog/action.json +25 -0
  41. package/entities/Catalog/schema.json +19 -0
  42. package/entities/ConnectionSetup/action.json +148 -0
  43. package/entities/ConnectionSetup/schema.json +25 -0
  44. package/entities/ContentSync/action.json +65 -0
  45. package/entities/ContentSync/schema.json +21 -0
  46. package/entities/CreateDSR/action.json +45 -0
  47. package/entities/CreateDSR/schema.json +20 -0
  48. package/entities/Deployment/action.json +106 -0
  49. package/entities/Deployment/schema.json +34 -0
  50. package/entities/DeploymentAudience/action.json +66 -0
  51. package/entities/DeploymentAudience/schema.json +32 -0
  52. package/entities/Events/action.json +108 -0
  53. package/entities/Events/schema.json +34 -0
  54. package/entities/Files/action.json +108 -0
  55. package/entities/Files/schema.json +23 -0
  56. package/entities/Groups/action.json +25 -0
  57. package/entities/Groups/schema.json +19 -0
  58. package/entities/IdentitySync/action.json +105 -0
  59. package/entities/IdentitySync/schema.json +23 -0
  60. package/entities/Insights/action.json +46 -0
  61. package/entities/Insights/schema.json +20 -0
  62. package/entities/LabelManagement/action.json +106 -0
  63. package/entities/LabelManagement/schema.json +23 -0
  64. package/entities/Mail/action.json +212 -0
  65. package/entities/Mail/schema.json +72 -0
  66. package/entities/Memberships/action.json +167 -0
  67. package/entities/Memberships/schema.json +70 -0
  68. package/entities/Misc/action.json +66 -0
  69. package/entities/Misc/schema.json +21 -0
  70. package/entities/Notebooks/action.json +107 -0
  71. package/entities/Notebooks/schema.json +34 -0
  72. package/entities/OpenExtensions/action.json +65 -0
  73. package/entities/OpenExtensions/schema.json +54 -0
  74. package/entities/People/action.json +46 -0
  75. package/entities/People/schema.json +31 -0
  76. package/entities/SchemaExtensions/action.json +65 -0
  77. package/entities/SchemaExtensions/schema.json +32 -0
  78. package/entities/Search/action.json +24 -0
  79. package/entities/Search/schema.json +19 -0
  80. package/entities/Security/action.json +151 -0
  81. package/entities/Security/schema.json +58 -0
  82. package/entities/SharePoint/action.json +214 -0
  83. package/entities/SharePoint/schema.json +39 -0
  84. package/entities/Subscriptions/action.json +65 -0
  85. package/entities/Subscriptions/schema.json +32 -0
  86. package/entities/TasksPlanner/action.json +272 -0
  87. package/entities/TasksPlanner/schema.json +86 -0
  88. package/entities/TasksTodo/action.json +187 -0
  89. package/entities/TasksTodo/schema.json +49 -0
  90. package/entities/Teams/action.json +519 -0
  91. package/entities/Teams/schema.json +120 -0
  92. package/entities/TrackDSRStatus/action.json +108 -0
  93. package/entities/TrackDSRStatus/schema.json +23 -0
  94. package/entities/TriggerEventForExistingLabel/action.json +108 -0
  95. package/entities/TriggerEventForExistingLabel/schema.json +23 -0
  96. package/entities/Users/action.json +213 -0
  97. package/entities/Users/schema.json +50 -0
  98. package/entities/WorkflowAutomation/action.json +249 -0
  99. package/entities/WorkflowAutomation/schema.json +30 -0
  100. package/error.json +190 -0
  101. package/package.json +87 -0
  102. package/pronghorn.json +8654 -0
  103. package/propertiesDecorators.json +14 -0
  104. package/propertiesSchema.json +1248 -0
  105. package/refs?service=git-upload-pack +0 -0
  106. package/report/creationReport.json +1715 -0
  107. package/report/graph.json +14709 -0
  108. package/sampleProperties.json +195 -0
  109. package/test/integration/adapterTestBasicGet.js +83 -0
  110. package/test/integration/adapterTestConnectivity.js +93 -0
  111. package/test/integration/adapterTestIntegration.js +6059 -0
  112. package/test/unit/adapterBaseTestUnit.js +949 -0
  113. package/test/unit/adapterTestUnit.js +7492 -0
  114. package/utils/adapterInfo.js +206 -0
  115. package/utils/addAuth.js +94 -0
  116. package/utils/artifactize.js +146 -0
  117. package/utils/basicGet.js +50 -0
  118. package/utils/checkMigrate.js +63 -0
  119. package/utils/entitiesToDB.js +178 -0
  120. package/utils/findPath.js +74 -0
  121. package/utils/methodDocumentor.js +225 -0
  122. package/utils/modify.js +154 -0
  123. package/utils/packModificationScript.js +35 -0
  124. package/utils/patches2bundledDeps.js +90 -0
  125. package/utils/pre-commit.sh +32 -0
  126. package/utils/removeHooks.js +20 -0
  127. package/utils/setup.js +33 -0
  128. package/utils/tbScript.js +246 -0
  129. package/utils/tbUtils.js +490 -0
  130. package/utils/testRunner.js +298 -0
  131. package/utils/troubleshootingAdapter.js +195 -0
  132. package/workflows/README.md +3 -0
@@ -0,0 +1,949 @@
1
+ // Set globals
2
+ /* global describe it log pronghornProps */
3
+ /* eslint global-require: warn */
4
+ /* eslint no-unused-vars: warn */
5
+
6
+ // include required items for testing & logging
7
+ const assert = require('assert');
8
+ const fs = require('fs-extra');
9
+ const mocha = require('mocha');
10
+ const path = require('path');
11
+ const winston = require('winston');
12
+ const { expect } = require('chai');
13
+ const { use } = require('chai');
14
+ const td = require('testdouble');
15
+
16
+ const anything = td.matchers.anything();
17
+
18
+ // stub and attemptTimeout are used throughout the code so set them here
19
+ let logLevel = 'none';
20
+ const stub = true;
21
+ const isRapidFail = false;
22
+ const attemptTimeout = 120000;
23
+
24
+ // these variables can be changed to run in integrated mode so easier to set them here
25
+ // always check these in with bogus data!!!
26
+ const host = 'replace.hostorip.here';
27
+ const username = 'username';
28
+ const password = 'password';
29
+ const protocol = 'http';
30
+ const port = 80;
31
+ const sslenable = false;
32
+ const sslinvalid = false;
33
+
34
+ // these are the adapter properties. You generally should not need to alter
35
+ // any of these after they are initially set up
36
+ global.pronghornProps = {
37
+ pathProps: {
38
+ encrypted: false
39
+ },
40
+ adapterProps: {
41
+ adapters: [{
42
+ id: 'Test-Base',
43
+ type: 'ABase',
44
+ properties: {
45
+ host,
46
+ port,
47
+ base_path: '/',
48
+ version: '',
49
+ cache_location: 'local',
50
+ encode_pathvars: true,
51
+ save_metric: false,
52
+ stub,
53
+ protocol,
54
+ authentication: {
55
+ auth_method: 'basic user_password',
56
+ username,
57
+ password,
58
+ token: '',
59
+ invalid_token_error: 401,
60
+ token_timeout: -1,
61
+ token_cache: 'local',
62
+ auth_field: 'header.headers.Authorization',
63
+ auth_field_format: 'Basic {b64}{username}:{password}{/b64}',
64
+ auth_logging: false,
65
+ client_id: '',
66
+ client_secret: '',
67
+ grant_type: ''
68
+ },
69
+ healthcheck: {
70
+ type: 'none',
71
+ frequency: 60000,
72
+ query_object: {}
73
+ },
74
+ throttle: {
75
+ throttle_enabled: false,
76
+ number_pronghorns: 1,
77
+ sync_async: 'sync',
78
+ max_in_queue: 1000,
79
+ concurrent_max: 1,
80
+ expire_timeout: 0,
81
+ avg_runtime: 200,
82
+ priorities: [
83
+ {
84
+ value: 0,
85
+ percent: 100
86
+ }
87
+ ]
88
+ },
89
+ request: {
90
+ number_redirects: 0,
91
+ number_retries: 3,
92
+ limit_retry_error: [0],
93
+ failover_codes: [],
94
+ attempt_timeout: attemptTimeout,
95
+ global_request: {
96
+ payload: {},
97
+ uriOptions: {},
98
+ addlHeaders: {},
99
+ authData: {}
100
+ },
101
+ healthcheck_on_timeout: true,
102
+ return_raw: true,
103
+ archiving: false,
104
+ return_request: false
105
+ },
106
+ proxy: {
107
+ enabled: false,
108
+ host: '',
109
+ port: 1,
110
+ protocol: 'http',
111
+ username: '',
112
+ password: ''
113
+ },
114
+ ssl: {
115
+ ecdhCurve: '',
116
+ enabled: sslenable,
117
+ accept_invalid_cert: sslinvalid,
118
+ ca_file: '',
119
+ key_file: '',
120
+ cert_file: '',
121
+ secure_protocol: '',
122
+ ciphers: ''
123
+ },
124
+ mongo: {
125
+ host: '',
126
+ port: 0,
127
+ database: '',
128
+ username: '',
129
+ password: '',
130
+ replSet: '',
131
+ db_ssl: {
132
+ enabled: false,
133
+ accept_invalid_cert: false,
134
+ ca_file: '',
135
+ key_file: '',
136
+ cert_file: ''
137
+ }
138
+ }
139
+ }
140
+ }]
141
+ }
142
+ };
143
+
144
+ global.$HOME = `${__dirname}/../..`;
145
+
146
+ // set the log levels that Pronghorn uses, spam and trace are not defaulted in so without
147
+ // this you may error on log.trace calls.
148
+ const myCustomLevels = {
149
+ levels: {
150
+ spam: 6,
151
+ trace: 5,
152
+ debug: 4,
153
+ info: 3,
154
+ warn: 2,
155
+ error: 1,
156
+ none: 0
157
+ }
158
+ };
159
+
160
+ // need to see if there is a log level passed in
161
+ process.argv.forEach((val) => {
162
+ // is there a log level defined to be passed in?
163
+ if (val.indexOf('--LOG') === 0) {
164
+ // get the desired log level
165
+ const inputVal = val.split('=')[1];
166
+
167
+ // validate the log level is supported, if so set it
168
+ if (Object.hasOwnProperty.call(myCustomLevels.levels, inputVal)) {
169
+ logLevel = inputVal;
170
+ }
171
+ }
172
+ });
173
+
174
+ // need to set global logging
175
+ global.log = winston.createLogger({
176
+ level: logLevel,
177
+ levels: myCustomLevels.levels,
178
+ transports: [
179
+ new winston.transports.Console()
180
+ ]
181
+ });
182
+
183
+ /**
184
+ * Runs the error asserts for the test
185
+ */
186
+ function runErrorAsserts(data, error, code, origin, displayStr) {
187
+ assert.equal(null, data);
188
+ assert.notEqual(undefined, error);
189
+ assert.notEqual(null, error);
190
+ assert.notEqual(undefined, error.IAPerror);
191
+ assert.notEqual(null, error.IAPerror);
192
+ assert.notEqual(undefined, error.IAPerror.displayString);
193
+ assert.notEqual(null, error.IAPerror.displayString);
194
+ assert.equal(code, error.icode);
195
+ assert.equal(origin, error.IAPerror.origin);
196
+ assert.equal(displayStr, error.IAPerror.displayString);
197
+ }
198
+
199
+ // require the adapter that we are going to be using
200
+ const AdapterBase = require('../../adapterBase');
201
+
202
+ // delete the .DS_Store directory in entities -- otherwise this will cause errors
203
+ const dirPath = path.join(__dirname, '../../entities/.DS_Store');
204
+ if (fs.existsSync(dirPath)) {
205
+ try {
206
+ fs.removeSync(dirPath);
207
+ console.log('.DS_Store deleted');
208
+ } catch (e) {
209
+ console.log('Error when deleting .DS_Store:', e);
210
+ }
211
+ }
212
+
213
+ describe('[unit] Adapter Base Test', () => {
214
+ describe('Adapter Base Class Tests', () => {
215
+ // Define constants we will use below
216
+ const a = new AdapterBase(
217
+ pronghornProps.adapterProps.adapters[0].id,
218
+ pronghornProps.adapterProps.adapters[0].properties
219
+ );
220
+
221
+ if (isRapidFail) {
222
+ const state = {};
223
+ state.passed = true;
224
+
225
+ mocha.afterEach(function x() {
226
+ state.passed = state.passed
227
+ && (this.currentTest.state === 'passed');
228
+ });
229
+ mocha.beforeEach(function x() {
230
+ if (!state.passed) {
231
+ return this.currentTest.skip();
232
+ }
233
+ return true;
234
+ });
235
+ }
236
+
237
+ describe('#class instance created', () => {
238
+ it('should be a class with properties', (done) => {
239
+ try {
240
+ assert.notEqual(null, a);
241
+ assert.notEqual(undefined, a);
242
+ assert.notEqual(null, a.allProps);
243
+ const check = global.pronghornProps.adapterProps.adapters[0].properties.healthcheck.type;
244
+ assert.equal(check, a.healthcheckType);
245
+ done();
246
+ } catch (error) {
247
+ log.error(`Test Failure: ${error}`);
248
+ done(error);
249
+ }
250
+ }).timeout(attemptTimeout);
251
+ });
252
+
253
+ describe('adapterBase.js', () => {
254
+ it('should have an adapterBase.js', (done) => {
255
+ try {
256
+ fs.exists('adapterBase.js', (val) => {
257
+ assert.equal(true, val);
258
+ done();
259
+ });
260
+ } catch (error) {
261
+ log.error(`Test Failure: ${error}`);
262
+ done(error);
263
+ }
264
+ });
265
+ });
266
+
267
+ describe('#refreshProperties', () => {
268
+ it('should have a refreshProperties function', (done) => {
269
+ try {
270
+ assert.equal(true, typeof a.refreshProperties === 'function');
271
+ done();
272
+ } catch (error) {
273
+ log.error(`Test Failure: ${error}`);
274
+ done(error);
275
+ }
276
+ });
277
+ it('should update the properties file', (done) => {
278
+ try {
279
+ // Mock connections
280
+ a.requestHandlerInst.refreshProperties = td.func();
281
+ a.refreshProperties({ foo: 'bar' });
282
+ // Run assert to verify we have updated a
283
+ try {
284
+ assert.equal(true, a.allProps.foo === 'bar');
285
+ done();
286
+ } catch (err) {
287
+ log.error(`Test Failure: ${err}`);
288
+ done(err);
289
+ }
290
+ } catch (error) {
291
+ log.error(`Adapter Exception: ${error}`);
292
+ done(error);
293
+ }
294
+ }).timeout(attemptTimeout);
295
+ it('should fail if the validation does not match the schema', (done) => {
296
+ try {
297
+ // Mock connections
298
+ a.propUtilInst.mergeProperties = td.func();
299
+ a.refreshProperties('tacos');
300
+ done();
301
+ } catch (error) {
302
+ log.error(`Adapter Exception: ${error}`);
303
+ done(error);
304
+ }
305
+ }).timeout(attemptTimeout);
306
+ });
307
+
308
+ describe('#getAllFunctions', () => {
309
+ it('should have a getAllFunctions function', (done) => {
310
+ try {
311
+ assert.equal(true, typeof a.getAllFunctions === 'function');
312
+ done();
313
+ } catch (error) {
314
+ log.error(`Test Failure: ${error}`);
315
+ done(error);
316
+ }
317
+ });
318
+ it('should return a list of functions', (done) => {
319
+ const returnedFunctions = ['addEntityCache', 'capabilityResults', 'checkActionFiles', 'checkProperties', 'connect', 'encryptProperty',
320
+ 'entityInList', 'getAllCapabilities', 'getAllFunctions', 'getConfig', 'getDevice', 'getDevicesFiltered', 'hasDevices', 'hasEntities',
321
+ 'healthCheck', 'iapFindAdapterPath', 'iapGetAdapterQueue', 'iapGetAdapterWorkflowFunctions', 'iapGetDeviceCount', 'iapMakeBrokerCall',
322
+ 'iapMoveAdapterEntitiesToDB', 'iapRunAdapterBasicGet', 'iapRunAdapterConnectivity', 'iapRunAdapterHealthcheck', 'iapSuspendAdapter',
323
+ 'iapTroubleshootAdapter', 'iapUnsuspendAdapter', 'iapUpdateAdapterConfiguration', 'isAlive', 'refreshProperties', 'addListener',
324
+ 'emit', 'eventNames', 'getMaxListeners', 'listenerCount', 'listeners', 'off', 'on', 'once', 'prependListener',
325
+ 'prependOnceListener', 'rawListeners', 'removeAllListeners', 'removeListener', 'setMaxListeners'];
326
+ try {
327
+ const expectedFunctions = a.getAllFunctions();
328
+ try {
329
+ assert.equal(JSON.stringify(expectedFunctions), JSON.stringify(returnedFunctions));
330
+ done();
331
+ } catch (err) {
332
+ log.error(`Test Failure: ${err}`);
333
+ done(err);
334
+ }
335
+ } catch (error) {
336
+ log.error(`Adapter Exception: ${error}`);
337
+ done(error);
338
+ }
339
+ }).timeout(attemptTimeout);
340
+ });
341
+
342
+ describe('#iapGetAdapterWorkflowFunctions', () => {
343
+ it('should have a iapGetAdapterWorkflowFunctions function', (done) => {
344
+ try {
345
+ assert.equal(true, typeof a.iapGetAdapterWorkflowFunctions === 'function');
346
+ done();
347
+ } catch (error) {
348
+ log.error(`Test Failure: ${error}`);
349
+ done(error);
350
+ }
351
+ });
352
+ it('should retrieve workflow functions', (done) => {
353
+ try {
354
+ const expectedFunctions = a.iapGetAdapterWorkflowFunctions([]);
355
+ try {
356
+ assert.equal(0, expectedFunctions.length);
357
+ done();
358
+ } catch (err) {
359
+ log.error(`Test Failure: ${err}`);
360
+ done(err);
361
+ }
362
+ } catch (error) {
363
+ log.error(`Adapter Exception: ${error}`);
364
+ done(error);
365
+ }
366
+ }).timeout(attemptTimeout);
367
+ });
368
+
369
+ describe('#checkProperties', () => {
370
+ it('should have a checkProperties function', (done) => {
371
+ try {
372
+ assert.equal(true, typeof a.checkProperties === 'function');
373
+ done();
374
+ } catch (error) {
375
+ log.error(`Test Failure: ${error}`);
376
+ done(error);
377
+ }
378
+ });
379
+ it('the sample properties should be good - if failure change the log level', (done) => {
380
+ try {
381
+ const samplePropsJson = require('../../sampleProperties.json');
382
+ const clean = a.checkProperties(samplePropsJson.properties);
383
+ try {
384
+ assert.notEqual(0, Object.keys(clean));
385
+ assert.equal(undefined, clean.exception);
386
+ assert.notEqual(undefined, clean.host);
387
+ assert.notEqual(null, clean.host);
388
+ assert.notEqual('', clean.host);
389
+ done();
390
+ } catch (err) {
391
+ log.error(`Test Failure: ${err}`);
392
+ done(err);
393
+ }
394
+ } catch (error) {
395
+ log.error(`Adapter Exception: ${error}`);
396
+ done(error);
397
+ }
398
+ }).timeout(attemptTimeout);
399
+ });
400
+
401
+ describe('#checkActionFiles', () => {
402
+ it('should have a checkActionFiles function', (done) => {
403
+ try {
404
+ assert.equal(true, typeof a.checkActionFiles === 'function');
405
+ done();
406
+ } catch (error) {
407
+ log.error(`Test Failure: ${error}`);
408
+ done(error);
409
+ }
410
+ });
411
+ it('the action files should be good - if failure change the log level as most issues are warnings', (done) => {
412
+ try {
413
+ const clean = a.checkActionFiles();
414
+ try {
415
+ for (let c = 0; c < clean.length; c += 1) {
416
+ log.error(clean[c]);
417
+ }
418
+ assert.equal(0, clean.length);
419
+ done();
420
+ } catch (err) {
421
+ log.error(`Test Failure: ${err}`);
422
+ done(err);
423
+ }
424
+ } catch (error) {
425
+ log.error(`Adapter Exception: ${error}`);
426
+ done(error);
427
+ }
428
+ }).timeout(attemptTimeout);
429
+ });
430
+
431
+ describe('#iapGetAdapterQueue', () => {
432
+ it('should have a iapGetAdapterQueue function', (done) => {
433
+ try {
434
+ assert.equal(true, typeof a.iapGetAdapterQueue === 'function');
435
+ done();
436
+ } catch (error) {
437
+ log.error(`Test Failure: ${error}`);
438
+ done(error);
439
+ }
440
+ });
441
+ it('should get information for all of the requests currently in the queue', (done) => {
442
+ try {
443
+ const expectedFunctions = a.iapGetAdapterQueue();
444
+ try {
445
+ assert.equal(0, expectedFunctions.length);
446
+ done();
447
+ } catch (err) {
448
+ log.error(`Test Failure: ${err}`);
449
+ done(err);
450
+ }
451
+ } catch (error) {
452
+ log.error(`Adapter Exception: ${error}`);
453
+ done(error);
454
+ }
455
+ }).timeout(attemptTimeout);
456
+ });
457
+
458
+ describe('#connect', () => {
459
+ it('should have a connect function', (done) => {
460
+ try {
461
+ assert.equal(true, typeof a.connect === 'function');
462
+ done();
463
+ } catch (error) {
464
+ log.error(`Test Failure: ${error}`);
465
+ done(error);
466
+ }
467
+ });
468
+ it('should get connected - no healthcheck', (done) => {
469
+ try {
470
+ a.healthcheckType = 'none';
471
+ a.connect();
472
+
473
+ try {
474
+ assert.equal(true, a.alive);
475
+ done();
476
+ } catch (error) {
477
+ log.error(`Test Failure: ${error}`);
478
+ done(error);
479
+ }
480
+ } catch (error) {
481
+ log.error(`Adapter Exception: ${error}`);
482
+ done(error);
483
+ }
484
+ });
485
+ it('should get connected - startup healthcheck', (done) => {
486
+ try {
487
+ a.healthcheckType = 'startup';
488
+ a.connect();
489
+
490
+ try {
491
+ assert.equal(true, a.alive);
492
+ done();
493
+ } catch (error) {
494
+ log.error(`Test Failure: ${error}`);
495
+ done(error);
496
+ }
497
+ } catch (error) {
498
+ log.error(`Adapter Exception: ${error}`);
499
+ done(error);
500
+ }
501
+ });
502
+ });
503
+
504
+ describe('#healthCheck', () => {
505
+ it('should have a healthCheck function', (done) => {
506
+ try {
507
+ assert.equal(true, typeof a.healthCheck === 'function');
508
+ done();
509
+ } catch (error) {
510
+ log.error(`Test Failure: ${error}`);
511
+ done(error);
512
+ }
513
+ });
514
+ it('should be healthy', (done) => {
515
+ try {
516
+ a.healthCheck(null, (data) => {
517
+ try {
518
+ assert.equal(true, a.healthy);
519
+ done();
520
+ } catch (err) {
521
+ log.error(`Test Failure: ${err}`);
522
+ done(err);
523
+ }
524
+ });
525
+ } catch (error) {
526
+ log.error(`Adapter Exception: ${error}`);
527
+ done(error);
528
+ }
529
+ }).timeout(attemptTimeout);
530
+ });
531
+
532
+ describe('#encryptProperty', () => {
533
+ it('should have a encryptProperty function', (done) => {
534
+ try {
535
+ assert.equal(true, typeof a.encryptProperty === 'function');
536
+ done();
537
+ } catch (error) {
538
+ log.error(`Test Failure: ${error}`);
539
+ done(error);
540
+ }
541
+ });
542
+ it('should get base64 encoded property', (done) => {
543
+ try {
544
+ a.encryptProperty('testing', 'base64', (data, error) => {
545
+ try {
546
+ assert.equal(undefined, error);
547
+ assert.notEqual(undefined, data);
548
+ assert.notEqual(null, data);
549
+ assert.notEqual(undefined, data.response);
550
+ assert.notEqual(null, data.response);
551
+ assert.equal(0, data.response.indexOf('{code}'));
552
+ done();
553
+ } catch (err) {
554
+ log.error(`Test Failure: ${err}`);
555
+ done(err);
556
+ }
557
+ });
558
+ } catch (error) {
559
+ log.error(`Adapter Exception: ${error}`);
560
+ done(error);
561
+ }
562
+ }).timeout(attemptTimeout);
563
+ it('should get encrypted property', (done) => {
564
+ try {
565
+ a.encryptProperty('testing', 'encrypt', (data, error) => {
566
+ try {
567
+ assert.equal(undefined, error);
568
+ assert.notEqual(undefined, data);
569
+ assert.notEqual(null, data);
570
+ assert.notEqual(undefined, data.response);
571
+ assert.notEqual(null, data.response);
572
+ assert.equal(0, data.response.indexOf('{crypt}'));
573
+ done();
574
+ } catch (err) {
575
+ log.error(`Test Failure: ${err}`);
576
+ done(err);
577
+ }
578
+ });
579
+ } catch (error) {
580
+ log.error(`Adapter Exception: ${error}`);
581
+ done(error);
582
+ }
583
+ }).timeout(attemptTimeout);
584
+ });
585
+
586
+ const entityType = 'mockType';
587
+ const entities = {
588
+ response: [
589
+ {
590
+ name: 'Godric Gryffindor'
591
+ }, {
592
+ name: 'Salazar Slytherin'
593
+ }
594
+ ]
595
+ };
596
+ const key = 'name';
597
+ describe('#addEntityCache', () => {
598
+ it('should have a addEntityCache function', (done) => {
599
+ try {
600
+ assert.equal(true, typeof a.addEntityCache === 'function');
601
+ done();
602
+ } catch (error) {
603
+ log.error(`Test Failure: ${error}`);
604
+ done(error);
605
+ }
606
+ });
607
+ it('should take the entities and add them to the cache', (done) => {
608
+ // Run the promise and verify the results match what we were expecting.
609
+ try {
610
+ a.addEntityCache(entityType, entities, key, (data, error) => {
611
+ try {
612
+ assert.equal(true, data);
613
+ done();
614
+ } catch (err) {
615
+ log.error(`Test Failure: ${err}`);
616
+ done(err);
617
+ }
618
+ });
619
+ } catch (error) {
620
+ log.error(`Adapter Exception: ${error}`);
621
+ done(error);
622
+ }
623
+ }).timeout(attemptTimeout);
624
+ });
625
+
626
+ const cache = [
627
+ 'Godric Gryffindor',
628
+ 'Salazar Slytherin'
629
+ ];
630
+ describe('#entityInList', () => {
631
+ it('should have a entityInList function', (done) => {
632
+ try {
633
+ assert.equal(true, typeof a.entityInList === 'function');
634
+ done();
635
+ } catch (error) {
636
+ log.error(`Test Failure: ${error}`);
637
+ done(error);
638
+ }
639
+ });
640
+ it('should return true if the entity is in the list of entities for this adapter', (done) => {
641
+ try {
642
+ const entityExist = a.entityInList('Godric Gryffindor', cache);
643
+ try {
644
+ assert.equal(true, entityExist[0]);
645
+ done();
646
+ } catch (err) {
647
+ log.error(`Test Failure: ${err}`);
648
+ done(err);
649
+ }
650
+ } catch (error) {
651
+ log.error(`Adapter Exception: ${error}`);
652
+ done(error);
653
+ }
654
+ }).timeout(attemptTimeout);
655
+ it('should return false if the entity is not in the list of entities for this adapter', (done) => {
656
+ try {
657
+ const entityExist = a.entityInList('XXXX', cache);
658
+ try {
659
+ assert.equal(false, entityExist[0]);
660
+ done();
661
+ } catch (err) {
662
+ log.error(`Test Failure: ${err}`);
663
+ done(err);
664
+ }
665
+ } catch (error) {
666
+ log.error(`Adapter Exception: ${error}`);
667
+ done(error);
668
+ }
669
+ }).timeout(attemptTimeout);
670
+ it('should return status of each item if an array is passed', (done) => {
671
+ try {
672
+ const entityExist = a.entityInList(['Godric Gryffindor', 'XXXX'], cache);
673
+ try {
674
+ assert.equal(true, entityExist[0]);
675
+ assert.equal(false, entityExist[1]);
676
+ done();
677
+ } catch (err) {
678
+ log.error(`Test Failure: ${err}`);
679
+ done(err);
680
+ }
681
+ } catch (error) {
682
+ log.error(`Adapter Exception: ${error}`);
683
+ done(error);
684
+ }
685
+ }).timeout(attemptTimeout);
686
+ });
687
+
688
+ describe('#capabilityResults', () => {
689
+ it('should have a capabilityResults function', (done) => {
690
+ try {
691
+ assert.equal(true, typeof a.capabilityResults === 'function');
692
+ done();
693
+ } catch (error) {
694
+ log.error(`Test Failure: ${error}`);
695
+ done(error);
696
+ }
697
+ });
698
+ it('should throw an error if needupdate is passed into the function', (done) => {
699
+ try {
700
+ const results = ['needupdate'];
701
+ a.capabilityResults(results, (data, error) => {
702
+ try {
703
+ const displayE = 'Could not load entity: unknown, into cache';
704
+ runErrorAsserts(data, error, 'AD.320', 'Test-Base-adapterBase-capabilityResults', displayE);
705
+ done();
706
+ } catch (err) {
707
+ log.error(`Test Failure: ${err}`);
708
+ done(err);
709
+ }
710
+ });
711
+ } catch (error) {
712
+ log.error(`Adapter Exception: ${error}`);
713
+ done(error);
714
+ }
715
+ }).timeout(attemptTimeout);
716
+ it('should throw an error if error is passed into the function', (done) => {
717
+ try {
718
+ const results = ['error'];
719
+ a.capabilityResults(results, (data, error) => {
720
+ try {
721
+ const displayE = 'Could not verify entity in cache';
722
+ runErrorAsserts(data, error, 'AD.321', 'Test-Base-adapterBase-capabilityResults', displayE);
723
+ done();
724
+ } catch (err) {
725
+ log.error(`Test Failure: ${err}`);
726
+ done(err);
727
+ }
728
+ });
729
+ } catch (error) {
730
+ log.error(`Adapter Exception: ${error}`);
731
+ done(error);
732
+ }
733
+ }).timeout(attemptTimeout);
734
+ it('should return null if nothing passed in', (done) => {
735
+ try {
736
+ const results = null;
737
+ a.capabilityResults(results, (data, error) => {
738
+ try {
739
+ assert.equal(null, data);
740
+ done();
741
+ } catch (err) {
742
+ log.error(`Test Failure: ${err}`);
743
+ done(err);
744
+ }
745
+ });
746
+ } catch (error) {
747
+ log.error(`Adapter Exception: ${error}`);
748
+ done(error);
749
+ }
750
+ }).timeout(attemptTimeout);
751
+ it('should return true if results is not an array and is "found"', (done) => {
752
+ try {
753
+ const results = 'found';
754
+ a.capabilityResults(results, (data, error) => {
755
+ try {
756
+ assert.equal(true, data[0]);
757
+ done();
758
+ } catch (err) {
759
+ log.error(`Test Failure: ${err}`);
760
+ done(err);
761
+ }
762
+ });
763
+ } catch (error) {
764
+ log.error(`Adapter Exception: ${error}`);
765
+ done(error);
766
+ }
767
+ }).timeout(attemptTimeout);
768
+ it('should return false if results is not an array and is not "found"', (done) => {
769
+ try {
770
+ const results = 'notfound';
771
+ a.capabilityResults(results, (data, error) => {
772
+ try {
773
+ assert.equal(false, data[0]);
774
+ done();
775
+ } catch (err) {
776
+ log.error(`Test Failure: ${err}`);
777
+ done(err);
778
+ }
779
+ });
780
+ } catch (error) {
781
+ log.error(`Adapter Exception: ${error}`);
782
+ done(error);
783
+ }
784
+ }).timeout(attemptTimeout);
785
+ it('should process an incoming array and return an array of values', (done) => {
786
+ try {
787
+ const results = ['found', 'notFound', 'found'];
788
+ a.capabilityResults(results, (data, error) => {
789
+ try {
790
+ assert.equal(true, data[0]);
791
+ assert.equal(false, data[1]);
792
+ assert.equal(true, data[2]);
793
+ done();
794
+ } catch (err) {
795
+ log.error(`Test Failure: ${err}`);
796
+ done(err);
797
+ }
798
+ });
799
+ } catch (error) {
800
+ log.error(`Adapter Exception: ${error}`);
801
+ done(error);
802
+ }
803
+ }).timeout(attemptTimeout);
804
+ });
805
+
806
+ describe('#getAllCapabilities', () => {
807
+ it('should have a getAllCapabilities function', (done) => {
808
+ try {
809
+ assert.equal(true, typeof a.getAllCapabilities === 'function');
810
+ done();
811
+ } catch (error) {
812
+ log.error(`Test Failure: ${error}`);
813
+ done(error);
814
+ }
815
+ });
816
+ it('should have capabilities returned', (done) => {
817
+ try {
818
+ const expectedCapabilities = a.getAllCapabilities();
819
+ try {
820
+ assert.notEqual(0, expectedCapabilities.length);
821
+ assert.equal('.generic', expectedCapabilities[0].entity);
822
+ assert.equal(10, expectedCapabilities[0].actions.length);
823
+ assert.equal('getGenerics', expectedCapabilities[0].actions[0]);
824
+ assert.equal('createGeneric', expectedCapabilities[0].actions[1]);
825
+ assert.equal('updateGeneric', expectedCapabilities[0].actions[2]);
826
+ assert.equal('patchGeneric', expectedCapabilities[0].actions[3]);
827
+ assert.equal('deleteGeneric', expectedCapabilities[0].actions[4]);
828
+ assert.equal('getGenericsNoBase', expectedCapabilities[0].actions[5]);
829
+ assert.equal('createGenericNoBase', expectedCapabilities[0].actions[6]);
830
+ assert.equal('updateGenericNoBase', expectedCapabilities[0].actions[7]);
831
+ assert.equal('patchGenericNoBase', expectedCapabilities[0].actions[8]);
832
+ assert.equal('deleteGenericNoBase', expectedCapabilities[0].actions[9]);
833
+ assert.equal('.system', expectedCapabilities[1].entity);
834
+ assert.equal(2, expectedCapabilities[1].actions.length);
835
+ assert.equal('getToken', expectedCapabilities[1].actions[0]);
836
+ assert.equal('healthcheck', expectedCapabilities[1].actions[1]);
837
+ for (let e = 1; e < expectedCapabilities.length; e += 1) {
838
+ assert.notEqual('', expectedCapabilities[e].entity);
839
+ assert.notEqual(null, expectedCapabilities[e].actions);
840
+ }
841
+ done();
842
+ } catch (err) {
843
+ log.error(`Test Failure: ${err}`);
844
+ done(err);
845
+ }
846
+ } catch (error) {
847
+ log.error(`Adapter Exception: ${error}`);
848
+ done(error);
849
+ }
850
+ }).timeout(attemptTimeout);
851
+ });
852
+
853
+ describe('#iapUpdateAdapterConfiguration', () => {
854
+ it('should have a iapUpdateAdapterConfiguration function', (done) => {
855
+ try {
856
+ assert.equal(true, typeof a.iapUpdateAdapterConfiguration === 'function');
857
+ done();
858
+ } catch (error) {
859
+ log.error(`Test Failure: ${error}`);
860
+ done(error);
861
+ }
862
+ });
863
+ it('should return no updated if no changes are provided', (done) => {
864
+ try {
865
+ a.iapUpdateAdapterConfiguration(null, null, null, null, null, (data, error) => {
866
+ try {
867
+ assert.equal('No configuration updates to make', data.response);
868
+ done();
869
+ } catch (err) {
870
+ log.error(`Test Failure: ${err}`);
871
+ done(err);
872
+ }
873
+ });
874
+ } catch (error) {
875
+ log.error(`Adapter Exception: ${error}`);
876
+ done(error);
877
+ }
878
+ }).timeout(attemptTimeout);
879
+ it('should throw an error if missing configuration file', (done) => {
880
+ try {
881
+ a.iapUpdateAdapterConfiguration(null, { name: 'fakeChange' }, null, null, null, (data, error) => {
882
+ try {
883
+ const displayE = 'configFile is required';
884
+ runErrorAsserts(data, error, 'AD.300', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
885
+ done();
886
+ } catch (err) {
887
+ log.error(`Test Failure: ${err}`);
888
+ done(err);
889
+ }
890
+ });
891
+ } catch (error) {
892
+ log.error(`Adapter Exception: ${error}`);
893
+ done(error);
894
+ }
895
+ }).timeout(attemptTimeout);
896
+ it('if not package.json, entity is required', (done) => {
897
+ try {
898
+ a.iapUpdateAdapterConfiguration('notPackage', { name: 'fakeChange' }, null, null, null, (data, error) => {
899
+ try {
900
+ const displayE = 'Unsupported Configuration Change or Missing Entity';
901
+ runErrorAsserts(data, error, 'AD.999', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
902
+ done();
903
+ } catch (err) {
904
+ log.error(`Test Failure: ${err}`);
905
+ done(err);
906
+ }
907
+ });
908
+ } catch (error) {
909
+ log.error(`Adapter Exception: ${error}`);
910
+ done(error);
911
+ }
912
+ }).timeout(attemptTimeout);
913
+ it('if not package.json, type is required', (done) => {
914
+ try {
915
+ a.iapUpdateAdapterConfiguration('notPackage', { name: 'fakeChange' }, 'entity', null, null, (data, error) => {
916
+ try {
917
+ const displayE = 'type is required';
918
+ runErrorAsserts(data, error, 'AD.300', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
919
+ done();
920
+ } catch (err) {
921
+ log.error(`Test Failure: ${err}`);
922
+ done(err);
923
+ }
924
+ });
925
+ } catch (error) {
926
+ log.error(`Adapter Exception: ${error}`);
927
+ done(error);
928
+ }
929
+ }).timeout(attemptTimeout);
930
+ it('if not package.json, entity must be valid', (done) => {
931
+ try {
932
+ a.iapUpdateAdapterConfiguration('notPackage', { name: 'fakeChange' }, 'fakeEntity', 'fakeType', null, (data, error) => {
933
+ try {
934
+ const displayE = 'Incomplete Configuration Change: Invalid Entity - fakeEntity';
935
+ runErrorAsserts(data, error, 'AD.999', 'Test-Base-adapterBase-iapUpdateAdapterConfiguration', displayE);
936
+ done();
937
+ } catch (err) {
938
+ log.error(`Test Failure: ${err}`);
939
+ done(err);
940
+ }
941
+ });
942
+ } catch (error) {
943
+ log.error(`Adapter Exception: ${error}`);
944
+ done(error);
945
+ }
946
+ }).timeout(attemptTimeout);
947
+ });
948
+ });
949
+ });