@itentialopensource/adapter-utils 4.44.9

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.
@@ -0,0 +1,26 @@
1
+ #!/bin/sh
2
+
3
+ #exit on any failure in the pipeline
4
+ set -e
5
+
6
+ # --------------------------------------------------
7
+ # pre-commit
8
+ # --------------------------------------------------
9
+ # Contains the standard set of tasks to runbefore
10
+ # committing changes to the repo. If any tasks fail
11
+ # then the commit will be aborted.
12
+ # --------------------------------------------------
13
+
14
+ printf "%b" "Running pre-commit hooks...\\n"
15
+
16
+ # verify testing script is stubbed and no credentials
17
+ node utils/testRunner.js -r
18
+
19
+ # security audit on the code
20
+ npm audit --registry=https://registry.npmjs.org
21
+
22
+ # lint the code
23
+ npm run lint
24
+
25
+ # test the code
26
+ npm run test
package/utils/setup.js ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+
5
+ /**
6
+ * This script will execute before an npm install command. The purpose is to
7
+ * write out some standard git hooks that will enable folks working on this
8
+ * project to benefit from the protections that the hooks provide.
9
+ */
10
+
11
+ const precommit = fs.readFileSync('utils/pre-commit.sh', 'utf8');
12
+
13
+ fs.stat('.git', (err) => {
14
+ if (err == null) {
15
+ // git repo, not an npm repo.
16
+ // add pre-commit hook if it doesn't exist
17
+ fs.stat('.git/hooks/pre-commit', (statErr) => {
18
+ if (statErr == null || statErr.code === 'ENOENT') {
19
+ fs.writeFile('.git/hooks/pre-commit', precommit, {
20
+ mode: 0o755
21
+ }, (writeErr) => {
22
+ if (writeErr) {
23
+ return console.log(writeErr.message);
24
+ }
25
+ return null;
26
+ });
27
+ } else {
28
+ console.log(statErr.message);
29
+ }
30
+ });
31
+ }
32
+ });
@@ -0,0 +1,259 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs-extra');
4
+ const rl = require('readline-sync');
5
+ const execute = require('child_process').exec;
6
+
7
+ /**
8
+ * This script will determine the type of integration test to run
9
+ * based on input. If other information is needed, it will solicit
10
+ * that input and then edit the integration test accordingly.
11
+ */
12
+
13
+ let stub = true;
14
+ let host = 'replace.hostorip.here';
15
+ let username = 'username';
16
+ let password = 'password';
17
+ let protocol = 'http';
18
+ let port = 80;
19
+ let sslenable = false;
20
+ let sslinvalid = false;
21
+ const dstub = true;
22
+ const dhost = 'replace.hostorip.here';
23
+ const dusername = 'username';
24
+ const dpassword = 'password';
25
+ const dprotocol = 'http';
26
+ const dport = 80;
27
+ const dsslenable = false;
28
+ const dsslinvalid = false;
29
+
30
+ let stderror = false;
31
+ let running = false;
32
+
33
+ /**
34
+ * Updates the integration test file with the proper vars
35
+ */
36
+ function replaceTestVars(test) {
37
+ if (!fs.existsSync(test)) {
38
+ console.log(`Could not find ${test}`);
39
+ return 'error';
40
+ }
41
+
42
+ let intTest = fs.readFileSync(test, 'utf8');
43
+
44
+ // replace stub variable
45
+ let sindex = intTest.indexOf('const stub');
46
+ let eindex = intTest.indexOf(';', sindex);
47
+ let replStr = intTest.substring(sindex, eindex + 1);
48
+ intTest = intTest.replace(replStr, `const stub = ${stub};`);
49
+
50
+ // replace host variable
51
+ sindex = intTest.indexOf('const host');
52
+ eindex = intTest.indexOf(';', sindex);
53
+ replStr = intTest.substring(sindex, eindex + 1);
54
+ intTest = intTest.replace(replStr, `const host = '${host}';`);
55
+
56
+ // replace username variable
57
+ sindex = intTest.indexOf('const username');
58
+ eindex = intTest.indexOf(';', sindex);
59
+ replStr = intTest.substring(sindex, eindex + 1);
60
+ intTest = intTest.replace(replStr, `const username = '${username}';`);
61
+
62
+ // replace password variable
63
+ sindex = intTest.indexOf('const password');
64
+ eindex = intTest.indexOf(';', sindex);
65
+ replStr = intTest.substring(sindex, eindex + 1);
66
+ intTest = intTest.replace(replStr, `const password = '${password}';`);
67
+
68
+ // replace protocol variable
69
+ sindex = intTest.indexOf('const protocol');
70
+ eindex = intTest.indexOf(';', sindex);
71
+ replStr = intTest.substring(sindex, eindex + 1);
72
+ intTest = intTest.replace(replStr, `const protocol = '${protocol}';`);
73
+
74
+ // replace port variable
75
+ sindex = intTest.indexOf('const port');
76
+ eindex = intTest.indexOf(';', sindex);
77
+ replStr = intTest.substring(sindex, eindex + 1);
78
+ intTest = intTest.replace(replStr, `const port = ${port};`);
79
+
80
+ // replace sslenable variable
81
+ sindex = intTest.indexOf('const sslenable');
82
+ eindex = intTest.indexOf(';', sindex);
83
+ replStr = intTest.substring(sindex, eindex + 1);
84
+ intTest = intTest.replace(replStr, `const sslenable = ${sslenable};`);
85
+
86
+ // replace sslinvalid variable
87
+ sindex = intTest.indexOf('const sslinvalid');
88
+ eindex = intTest.indexOf(';', sindex);
89
+ replStr = intTest.substring(sindex, eindex + 1);
90
+ intTest = intTest.replace(replStr, `const sslinvalid = ${sslinvalid};`);
91
+
92
+ console.log(`Updates to ${test} complete`);
93
+ fs.writeFileSync(test, intTest);
94
+ return 'success';
95
+ }
96
+
97
+ /**
98
+ * Updates the integration test file and runs the script
99
+ */
100
+ function runTest(callback) {
101
+ replaceTestVars('test/integration/adapterTestIntegration.js');
102
+
103
+ const cmdPath = 'npm run test:integration';
104
+ console.log('\nRUNNING INTEGRATION TESTS - THIS WILL TAKE SOME TIME AND WILL NOT PRINT UNTIL TEST IS COMPLETE!\n');
105
+ return execute(cmdPath, (cerror, stdout, stderr) => {
106
+ console.log('executed tests:\n');
107
+ console.log(`${stdout}\n`);
108
+
109
+ if (stderror) {
110
+ console.log('\nstandard error from tests - unless test failed, these may be expected errors:\n');
111
+ console.log(`${stderr}\n`);
112
+ }
113
+
114
+ if (cerror) {
115
+ console.log('\nexec error:\n');
116
+ console.log(`${cerror}\n`);
117
+ }
118
+
119
+ // reset the defaults
120
+ stub = dstub;
121
+ host = dhost;
122
+ username = dusername;
123
+ password = dpassword;
124
+ protocol = dprotocol;
125
+ port = dport;
126
+ sslenable = dsslenable;
127
+ sslinvalid = dsslinvalid;
128
+ replaceTestVars('test/integration/adapterTestIntegration.js');
129
+ return callback('done');
130
+ });
131
+ }
132
+
133
+ /**
134
+ * Updates the unit test file and runs the script
135
+ */
136
+ function runUnitTest(callback) {
137
+ const cmdPath = 'npm run test:unit';
138
+ console.log('\nRUNNING UNIT TESTS - THIS WILL TAKE SOME TIME AND WILL NOT PRINT UNTIL TEST IS COMPLETE!\n');
139
+ return execute(cmdPath, (cerror, stdout, stderr) => {
140
+ console.log('executed tests:\n');
141
+ console.log(`${stdout}\n`);
142
+
143
+ if (stderror) {
144
+ console.log('\nstandard error from tests - unless test failed, these may be expected errors:\n');
145
+ console.log(`${stderr}\n`);
146
+ }
147
+
148
+ if (cerror) {
149
+ console.log('\nexec error:\n');
150
+ console.log(`${cerror}\n`);
151
+ }
152
+
153
+ return callback('done');
154
+ });
155
+ }
156
+
157
+ // print process.argv
158
+ const args = process.argv.slice(2);
159
+
160
+ // go through the arguments that where provided
161
+ for (let a = 0; a < args.length; a += 1) {
162
+ if (args[a].toUpperCase() === '-H' || args[a].toUpperCase() === '--HELP') {
163
+ let message = '\nThis tool is used to make it easier to run integration tests.\n';
164
+ message += '\n';
165
+ message += 'Options:\n';
166
+ message += '-h, --help: Prints this message\n';
167
+ message += '-r, --reset: Resets the variables back to stub settings and removes credentials\n';
168
+ message += '-s, --stderror: Displays the standard error from the run, this can have data even if all the tests pass\n';
169
+ message += '-u, --unit: Runs just the unit tests as well\n';
170
+ console.log(message);
171
+ running = true;
172
+ }
173
+
174
+ if (args[a].toUpperCase() === '-R' || args[a].toUpperCase() === '--RESET') {
175
+ running = true;
176
+ replaceTestVars('test/integration/adapterTestIntegration.js');
177
+ replaceTestVars('test/unit/adapterTestUnit.js');
178
+ console.log('test reset complete');
179
+ }
180
+ if (args[a].toUpperCase() === '-S' || args[a].toUpperCase() === '--STDERROR') {
181
+ stderror = true;
182
+ }
183
+ if (args[a].toUpperCase() === '-U' || args[a].toUpperCase() === '--UNIT') {
184
+ running = true;
185
+ runUnitTest((status) => {
186
+ console.log(status);
187
+ process.exit(1);
188
+ });
189
+ }
190
+ }
191
+
192
+ if (!running) {
193
+ // how are we running the test?
194
+ let answer = rl.question('\nDo you want to run the integration test integrated with the other system? (no): ');
195
+ if (answer && (answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y')) {
196
+ stub = false;
197
+ console.log('Need more information about the integration!');
198
+ } else {
199
+ running = true;
200
+ runTest((status) => {
201
+ console.log(status);
202
+ process.exit(1);
203
+ });
204
+ }
205
+
206
+ if (!running) {
207
+ // how are we running the test?
208
+ answer = rl.question('\nWhat is the dns or ip of the system you want to test with? (localhost): ');
209
+ if (answer) {
210
+ host = answer;
211
+ } else {
212
+ host = 'localhost';
213
+ }
214
+
215
+ // need the username to authenticate with
216
+ answer = rl.question('\nWhat is the username to authenticate, if no authentication just return? (username): ');
217
+ if (answer) {
218
+ username = answer;
219
+ }
220
+
221
+ // need the password to authenticate with
222
+ answer = rl.question('\nWhat is the password to authenticate, if no authentication just return? (password): ', { hideEchoBack: true });
223
+ if (answer) {
224
+ password = answer;
225
+ }
226
+
227
+ // need the protocol used with other system
228
+ answer = rl.question('\nWhat is the protocol used to communicate with the system? (http): ');
229
+ if (answer) {
230
+ protocol = answer;
231
+ }
232
+
233
+ if (protocol === 'https') {
234
+ // need the port used with other system
235
+ answer = rl.question('\nWhat is the port used to communicate with the system? (443): ');
236
+ if (answer) {
237
+ port = Number(answer);
238
+ }
239
+
240
+ // turn on ssl and accept invalid certs
241
+ sslenable = true;
242
+ sslinvalid = true;
243
+ runTest((status) => {
244
+ console.log(status);
245
+ process.exit(1);
246
+ });
247
+ } else {
248
+ // need the port used with other system
249
+ answer = rl.question('\nWhat is the port used to communicate with the system? (80): ');
250
+ if (answer) {
251
+ port = Number(answer);
252
+ }
253
+ runTest((status) => {
254
+ console.log(status);
255
+ process.exit(1);
256
+ });
257
+ }
258
+ }
259
+ }