@itentialopensource/adapter-slack 2.5.2 → 2.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.
- package/.eslintignore +1 -0
- package/AUTH.md +39 -0
- package/BROKER.md +199 -0
- package/CALLS.md +169 -0
- package/CHANGELOG.md +53 -50
- package/CODE_OF_CONDUCT.md +12 -17
- package/CONTRIBUTING.md +88 -74
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +641 -0
- package/README.md +228 -420
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +47 -0
- package/adapter.js +1417 -37
- package/adapterBase.js +1270 -238
- package/entities/.generic/action.json +214 -0
- package/entities/.generic/schema.json +28 -0
- package/entities/Files/action.json +1 -1
- package/error.json +12 -0
- package/package.json +40 -20
- package/pronghorn.json +642 -74
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +472 -4
- package/refs?service=git-upload-pack +0 -0
- package/report/adapterInfo.json +10 -0
- package/report/updateReport1615828031315.json +95 -0
- package/report/updateReport1653493672906.json +120 -0
- package/sampleProperties.json +103 -6
- package/storage/metrics.json +2228 -0
- package/test/integration/adapterTestBasicGet.js +85 -0
- package/test/integration/adapterTestConnectivity.js +93 -0
- package/test/integration/adapterTestIntegration.js +33 -103
- package/test/unit/adapterBaseTestUnit.js +949 -0
- package/test/unit/adapterTestUnit.js +644 -111
- package/utils/adapterInfo.js +206 -0
- package/utils/addAuth.js +94 -0
- package/utils/basicGet.js +50 -0
- package/utils/checkMigrate.js +63 -0
- package/utils/entitiesToDB.js +179 -0
- package/utils/findPath.js +74 -0
- package/utils/modify.js +154 -0
- package/utils/packModificationScript.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/pre-commit.sh +3 -0
- package/utils/removeHooks.js +20 -0
- package/utils/tbScript.js +184 -0
- package/utils/tbUtils.js +469 -0
- package/utils/testRunner.js +16 -16
- package/utils/troubleshootingAdapter.js +190 -0
- package/img/adapter.png +0 -0
|
@@ -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
|
+
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/* @copyright Itential, LLC 2019 (pre-modifications) */
|
|
2
2
|
|
|
3
3
|
// Set globals
|
|
4
|
-
/* global describe it log pronghornProps
|
|
4
|
+
/* global describe it log pronghornProps */
|
|
5
5
|
/* eslint no-unused-vars: warn */
|
|
6
|
-
/* eslint
|
|
6
|
+
/* eslint no-underscore-dangle: warn */
|
|
7
|
+
/* eslint import/no-dynamic-require:warn */
|
|
7
8
|
|
|
8
9
|
// include required items for testing & logging
|
|
9
10
|
const assert = require('assert');
|
|
@@ -14,25 +15,39 @@ const winston = require('winston');
|
|
|
14
15
|
const { expect } = require('chai');
|
|
15
16
|
const { use } = require('chai');
|
|
16
17
|
const td = require('testdouble');
|
|
18
|
+
const util = require('util');
|
|
17
19
|
|
|
18
20
|
const anything = td.matchers.anything();
|
|
19
21
|
|
|
20
22
|
// stub and attemptTimeout are used throughout the code so set them here
|
|
21
23
|
let logLevel = 'none';
|
|
22
|
-
const stub = true;
|
|
23
24
|
const isRapidFail = false;
|
|
24
25
|
const isSaveMockData = false;
|
|
25
|
-
|
|
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;
|
|
26
35
|
|
|
27
36
|
// these variables can be changed to run in integrated mode so easier to set them here
|
|
28
37
|
// always check these in with bogus data!!!
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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;
|
|
36
51
|
|
|
37
52
|
// these are the adapter properties. You generally should not need to alter
|
|
38
53
|
// any of these after they are initially set up
|
|
@@ -43,95 +58,8 @@ global.pronghornProps = {
|
|
|
43
58
|
adapterProps: {
|
|
44
59
|
adapters: [{
|
|
45
60
|
id: 'Test-slack',
|
|
46
|
-
type: '
|
|
47
|
-
properties:
|
|
48
|
-
host,
|
|
49
|
-
port,
|
|
50
|
-
base_path: '/api',
|
|
51
|
-
version: '',
|
|
52
|
-
cache_location: 'none',
|
|
53
|
-
encode_pathvars: true,
|
|
54
|
-
save_metric: false,
|
|
55
|
-
stub,
|
|
56
|
-
protocol,
|
|
57
|
-
authentication: {
|
|
58
|
-
auth_method: 'static_token',
|
|
59
|
-
username,
|
|
60
|
-
password,
|
|
61
|
-
token: 'xoxp-XXXXX-XXXXXXX',
|
|
62
|
-
invalid_token_error: 401,
|
|
63
|
-
token_timeout: -1,
|
|
64
|
-
token_cache: 'local',
|
|
65
|
-
auth_field: 'header.headers.Authorization',
|
|
66
|
-
auth_field_format: 'Bearer {token}'
|
|
67
|
-
},
|
|
68
|
-
healthcheck: {
|
|
69
|
-
type: 'intermittent',
|
|
70
|
-
frequency: 300000
|
|
71
|
-
},
|
|
72
|
-
throttle: {
|
|
73
|
-
throttle_enabled: false,
|
|
74
|
-
number_pronghorns: 1,
|
|
75
|
-
sync_async: 'sync',
|
|
76
|
-
max_in_queue: 1000,
|
|
77
|
-
concurrent_max: 1,
|
|
78
|
-
expire_timeout: 0,
|
|
79
|
-
avg_runtime: 200,
|
|
80
|
-
priorities: [
|
|
81
|
-
{
|
|
82
|
-
value: 0,
|
|
83
|
-
percent: 100
|
|
84
|
-
}
|
|
85
|
-
]
|
|
86
|
-
},
|
|
87
|
-
request: {
|
|
88
|
-
number_redirects: 0,
|
|
89
|
-
number_retries: 3,
|
|
90
|
-
limit_retry_error: 0,
|
|
91
|
-
failover_codes: [],
|
|
92
|
-
attempt_timeout: attemptTimeout,
|
|
93
|
-
global_request: {
|
|
94
|
-
payload: {},
|
|
95
|
-
uriOptions: {},
|
|
96
|
-
addlHeaders: {},
|
|
97
|
-
authData: {}
|
|
98
|
-
},
|
|
99
|
-
healthcheck_on_timeout: true,
|
|
100
|
-
return_raw: true,
|
|
101
|
-
archiving: false
|
|
102
|
-
},
|
|
103
|
-
proxy: {
|
|
104
|
-
enabled: false,
|
|
105
|
-
host: '',
|
|
106
|
-
port: 1,
|
|
107
|
-
protocol: 'http'
|
|
108
|
-
},
|
|
109
|
-
ssl: {
|
|
110
|
-
ecdhCurve: '',
|
|
111
|
-
enabled: sslenable,
|
|
112
|
-
accept_invalid_cert: sslinvalid,
|
|
113
|
-
ca_file: '',
|
|
114
|
-
key_file: '',
|
|
115
|
-
cert_file: '',
|
|
116
|
-
secure_protocol: '',
|
|
117
|
-
ciphers: ''
|
|
118
|
-
},
|
|
119
|
-
mongo: {
|
|
120
|
-
host: '',
|
|
121
|
-
port: 0,
|
|
122
|
-
database: '',
|
|
123
|
-
username: '',
|
|
124
|
-
password: '',
|
|
125
|
-
replSet: '',
|
|
126
|
-
db_ssl: {
|
|
127
|
-
enabled: false,
|
|
128
|
-
accept_invalid_cert: false,
|
|
129
|
-
ca_file: '',
|
|
130
|
-
key_file: '',
|
|
131
|
-
cert_file: ''
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
61
|
+
type: 'Slacktest',
|
|
62
|
+
properties: samProps
|
|
135
63
|
}]
|
|
136
64
|
}
|
|
137
65
|
};
|
|
@@ -306,7 +234,7 @@ function saveMockData(entityName, actionName, descriptor, responseData) {
|
|
|
306
234
|
}
|
|
307
235
|
|
|
308
236
|
// require the adapter that we are going to be using
|
|
309
|
-
const Slacktest = require('../../adapter
|
|
237
|
+
const Slacktest = require('../../adapter');
|
|
310
238
|
|
|
311
239
|
// begin the testing - these should be pretty well defined between the describe and the it!
|
|
312
240
|
describe('[integration] Slack Adapter Test', () => {
|
|
@@ -337,6 +265,8 @@ describe('[integration] Slack Adapter Test', () => {
|
|
|
337
265
|
try {
|
|
338
266
|
assert.notEqual(null, a);
|
|
339
267
|
assert.notEqual(undefined, a);
|
|
268
|
+
const checkId = global.pronghornProps.adapterProps.adapters[0].id;
|
|
269
|
+
assert.equal(checkId, a.id);
|
|
340
270
|
assert.notEqual(null, a.allProps);
|
|
341
271
|
const check = global.pronghornProps.adapterProps.adapters[0].properties.healthcheck.type;
|
|
342
272
|
assert.equal(check, a.healthcheckType);
|
|
@@ -579,7 +509,7 @@ describe('[integration] Slack Adapter Test', () => {
|
|
|
579
509
|
assert.equal(true, data.response.ok);
|
|
580
510
|
assert.equal('object', typeof data.response.response_metadata);
|
|
581
511
|
} else {
|
|
582
|
-
const channelIds = data.response.channels.map(c => c.id);
|
|
512
|
+
const channelIds = data.response.channels.map((c) => c.id);
|
|
583
513
|
assert.equal(undefined, error);
|
|
584
514
|
assert.notEqual(undefined, data);
|
|
585
515
|
assert.notEqual(null, data);
|
|
@@ -939,7 +869,7 @@ describe('[integration] Slack Adapter Test', () => {
|
|
|
939
869
|
describe('Chat Entity', () => {
|
|
940
870
|
let channelId;
|
|
941
871
|
let messageTs;
|
|
942
|
-
before(() => {
|
|
872
|
+
mocha.before(() => {
|
|
943
873
|
let getChannelPromise;
|
|
944
874
|
if (!stub) {
|
|
945
875
|
getChannelPromise = new Promise((resolve) => {
|