@itentialopensource/adapter-bitbucket 0.3.7 → 0.5.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 (56) hide show
  1. package/AUTH.md +35 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +1741 -0
  4. package/CHANGELOG.md +72 -10
  5. package/CODE_OF_CONDUCT.md +12 -17
  6. package/CONTRIBUTING.md +3 -148
  7. package/ENHANCE.md +69 -0
  8. package/PROPERTIES.md +641 -0
  9. package/README.md +235 -576
  10. package/SUMMARY.md +9 -0
  11. package/SYSTEMINFO.md +20 -0
  12. package/TROUBLESHOOT.md +47 -0
  13. package/adapter.js +471 -819
  14. package/adapterBase.js +843 -419
  15. package/changelogs/CHANGELOG.md +134 -0
  16. package/entities/.generic/action.json +105 -0
  17. package/entities/.generic/schema.json +6 -1
  18. package/error.json +6 -0
  19. package/metadata.json +75 -0
  20. package/package.json +27 -26
  21. package/pronghorn.json +527 -116
  22. package/propertiesDecorators.json +14 -0
  23. package/propertiesSchema.json +827 -6
  24. package/refs?service=git-upload-pack +0 -0
  25. package/report/adapter-openapi.json +15713 -0
  26. package/report/adapter-openapi.yaml +13295 -0
  27. package/report/adapterInfo.json +10 -0
  28. package/report/updateReport1652978796126.json +120 -0
  29. package/report/updateReport1691507757454.json +120 -0
  30. package/report/updateReport1692202749809.json +120 -0
  31. package/report/updateReport1694455448924.json +120 -0
  32. package/report/updateReport1694457678311.json +120 -0
  33. package/report/updateReport1694463179777.json +120 -0
  34. package/report/updateReport1698421384524.json +120 -0
  35. package/sampleProperties.json +153 -3
  36. package/test/integration/adapterTestBasicGet.js +3 -5
  37. package/test/integration/adapterTestConnectivity.js +91 -42
  38. package/test/integration/adapterTestIntegration.js +155 -109
  39. package/test/unit/adapterBaseTestUnit.js +388 -308
  40. package/test/unit/adapterTestUnit.js +399 -260
  41. package/utils/adapterInfo.js +206 -0
  42. package/utils/addAuth.js +1 -1
  43. package/utils/artifactize.js +1 -1
  44. package/utils/checkMigrate.js +1 -1
  45. package/utils/entitiesToDB.js +12 -57
  46. package/utils/findPath.js +1 -1
  47. package/utils/methodDocumentor.js +273 -0
  48. package/utils/modify.js +13 -15
  49. package/utils/packModificationScript.js +1 -1
  50. package/utils/pre-commit.sh +5 -0
  51. package/utils/taskMover.js +309 -0
  52. package/utils/tbScript.js +123 -53
  53. package/utils/tbUtils.js +87 -49
  54. package/utils/testRunner.js +17 -17
  55. package/utils/troubleshootingAdapter.js +9 -6
  56. package/workflows/README.md +0 -3
@@ -3,38 +3,51 @@
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');
9
11
  const fs = require('fs');
10
- const mocha = require('mocha');
11
12
  const path = require('path');
13
+ const util = require('util');
14
+ const mocha = require('mocha');
12
15
  const winston = require('winston');
13
16
  const { expect } = require('chai');
14
17
  const { use } = require('chai');
15
18
  const td = require('testdouble');
16
- const util = require('util');
17
- const pronghorn = require('../../pronghorn.json');
18
19
 
19
- pronghorn.methodsByName = pronghorn.methods.reduce((result, meth) => ({ ...result, [meth.name]: meth }), {});
20
20
  const anything = td.matchers.anything();
21
21
 
22
22
  // stub and attemptTimeout are used throughout the code so set them here
23
23
  let logLevel = 'none';
24
- const stub = true;
25
24
  const isRapidFail = false;
26
25
  const isSaveMockData = false;
27
- 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;
28
35
 
29
36
  // these variables can be changed to run in integrated mode so easier to set them here
30
37
  // always check these in with bogus data!!!
31
- const host = 'replace.hostorip.here';
32
- const username = 'username';
33
- const password = 'password';
34
- const protocol = 'http';
35
- const port = 80;
36
- const sslenable = false;
37
- 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;
38
51
 
39
52
  // these are the adapter properties. You generally should not need to alter
40
53
  // any of these after they are initially set up
@@ -46,102 +59,7 @@ global.pronghornProps = {
46
59
  adapters: [{
47
60
  id: 'Test-bitbucket',
48
61
  type: 'Bitbucket',
49
- properties: {
50
- host,
51
- port,
52
- base_path: '/api',
53
- version: 'v2.0',
54
- cache_location: 'none',
55
- encode_pathvars: true,
56
- save_metric: false,
57
- stub,
58
- protocol,
59
- authentication: {
60
- auth_method: 'no_authentication',
61
- username,
62
- password,
63
- token: '',
64
- invalid_token_error: 401,
65
- token_timeout: -1,
66
- token_cache: 'local',
67
- auth_field: 'header.headers.Authorization',
68
- auth_field_format: 'Basic {b64}{username}:{password}{/b64}',
69
- auth_logging: false,
70
- client_id: '',
71
- client_secret: '',
72
- grant_type: ''
73
- },
74
- healthcheck: {
75
- type: 'none',
76
- frequency: 60000,
77
- query_object: {}
78
- },
79
- throttle: {
80
- throttle_enabled: false,
81
- number_pronghorns: 1,
82
- sync_async: 'sync',
83
- max_in_queue: 1000,
84
- concurrent_max: 1,
85
- expire_timeout: 0,
86
- avg_runtime: 200,
87
- priorities: [
88
- {
89
- value: 0,
90
- percent: 100
91
- }
92
- ]
93
- },
94
- request: {
95
- number_redirects: 0,
96
- number_retries: 3,
97
- limit_retry_error: 0,
98
- failover_codes: [],
99
- attempt_timeout: attemptTimeout,
100
- global_request: {
101
- payload: {},
102
- uriOptions: {},
103
- addlHeaders: {},
104
- authData: {}
105
- },
106
- healthcheck_on_timeout: true,
107
- return_raw: true,
108
- archiving: false,
109
- return_request: false
110
- },
111
- proxy: {
112
- enabled: false,
113
- host: '',
114
- port: 1,
115
- protocol: 'http',
116
- username: '',
117
- password: ''
118
- },
119
- ssl: {
120
- ecdhCurve: '',
121
- enabled: sslenable,
122
- accept_invalid_cert: sslinvalid,
123
- ca_file: '',
124
- key_file: '',
125
- cert_file: '',
126
- secure_protocol: '',
127
- ciphers: ''
128
- },
129
- mongo: {
130
- host: '',
131
- port: 0,
132
- database: '',
133
- username: '',
134
- password: '',
135
- replSet: '',
136
- db_ssl: {
137
- enabled: false,
138
- accept_invalid_cert: false,
139
- ca_file: '',
140
- key_file: '',
141
- cert_file: ''
142
- }
143
- }
144
- }
62
+ properties: samProps
145
63
  }]
146
64
  }
147
65
  };
@@ -417,6 +335,134 @@ describe('[integration] Bitbucket Adapter Test', () => {
417
335
  }).timeout(attemptTimeout);
418
336
  });
419
337
 
338
+ // broker tests
339
+ describe('#getDevicesFiltered - errors', () => {
340
+ it('should work if integrated but since no mockdata should error when run standalone', (done) => {
341
+ try {
342
+ const opts = {
343
+ filter: {
344
+ name: 'deviceName'
345
+ }
346
+ };
347
+ a.getDevicesFiltered(opts, (data, error) => {
348
+ try {
349
+ if (stub) {
350
+ if (samProps.devicebroker.getDevicesFiltered[0].handleFailure === 'ignore') {
351
+ assert.equal(null, error);
352
+ assert.notEqual(undefined, data);
353
+ assert.notEqual(null, data);
354
+ assert.equal(0, data.total);
355
+ assert.equal(0, data.list.length);
356
+ } else {
357
+ const displayE = 'Error 400 received on request';
358
+ runErrorAsserts(data, error, 'AD.500', 'Test-bitbucket-connectorRest-handleEndResponse', displayE);
359
+ }
360
+ } else {
361
+ runCommonAsserts(data, error);
362
+ }
363
+ done();
364
+ } catch (err) {
365
+ log.error(`Test Failure: ${err}`);
366
+ done(err);
367
+ }
368
+ });
369
+ } catch (error) {
370
+ log.error(`Adapter Exception: ${error}`);
371
+ done(error);
372
+ }
373
+ }).timeout(attemptTimeout);
374
+ });
375
+
376
+ describe('#iapGetDeviceCount - errors', () => {
377
+ it('should work if integrated but since no mockdata should error when run standalone', (done) => {
378
+ try {
379
+ const opts = {
380
+ filter: {
381
+ name: 'deviceName'
382
+ }
383
+ };
384
+ a.iapGetDeviceCount((data, error) => {
385
+ try {
386
+ if (stub) {
387
+ if (samProps.devicebroker.getDevicesFiltered[0].handleFailure === 'ignore') {
388
+ assert.equal(null, error);
389
+ assert.notEqual(undefined, data);
390
+ assert.notEqual(null, data);
391
+ assert.equal(0, data.count);
392
+ } else {
393
+ const displayE = 'Error 400 received on request';
394
+ runErrorAsserts(data, error, 'AD.500', 'Test-bitbucket-connectorRest-handleEndResponse', displayE);
395
+ }
396
+ } else {
397
+ runCommonAsserts(data, error);
398
+ }
399
+ done();
400
+ } catch (err) {
401
+ log.error(`Test Failure: ${err}`);
402
+ done(err);
403
+ }
404
+ });
405
+ } catch (error) {
406
+ log.error(`Adapter Exception: ${error}`);
407
+ done(error);
408
+ }
409
+ }).timeout(attemptTimeout);
410
+ });
411
+
412
+ // exposed cache tests
413
+ describe('#iapPopulateEntityCache - errors', () => {
414
+ it('should work if integrated but since no mockdata should error when run standalone', (done) => {
415
+ try {
416
+ a.iapPopulateEntityCache('Device', (data, error) => {
417
+ try {
418
+ if (stub) {
419
+ assert.equal(null, data);
420
+ assert.notEqual(undefined, error);
421
+ assert.notEqual(null, error);
422
+ done();
423
+ } else {
424
+ assert.equal(undefined, error);
425
+ assert.equal('success', data[0]);
426
+ done();
427
+ }
428
+ } catch (err) {
429
+ log.error(`Test Failure: ${err}`);
430
+ done(err);
431
+ }
432
+ });
433
+ } catch (error) {
434
+ log.error(`Adapter Exception: ${error}`);
435
+ done(error);
436
+ }
437
+ }).timeout(attemptTimeout);
438
+ });
439
+
440
+ describe('#iapRetrieveEntitiesCache - errors', () => {
441
+ it('should work if integrated but since no mockdata should error when run standalone', (done) => {
442
+ try {
443
+ a.iapRetrieveEntitiesCache('Device', {}, (data, error) => {
444
+ try {
445
+ if (stub) {
446
+ assert.equal(null, data);
447
+ assert.notEqual(null, error);
448
+ assert.notEqual(undefined, error);
449
+ } else {
450
+ assert.equal(undefined, error);
451
+ assert.notEqual(null, data);
452
+ assert.notEqual(undefined, data);
453
+ }
454
+ done();
455
+ } catch (err) {
456
+ log.error(`Test Failure: ${err}`);
457
+ done(err);
458
+ }
459
+ });
460
+ } catch (error) {
461
+ log.error(`Adapter Exception: ${error}`);
462
+ done(error);
463
+ }
464
+ }).timeout(attemptTimeout);
465
+ });
420
466
  /*
421
467
  -----------------------------------------------------------------------
422
468
  -----------------------------------------------------------------------