testaro 52.0.5 → 53.0.2

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 (3) hide show
  1. package/README.md +20 -3
  2. package/netWatch.js +20 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -761,13 +761,30 @@ The arguments and behaviors described above for execution by a module apply here
761
761
 
762
762
  An instance of Testaro, an _agent_, can poll servers for jobs to be performed.
763
763
 
764
- Network watching is governed by environment variables of the form `NETWATCH_URL_0_JOB`, `NETWATCH_URL_0_OBSERVE`, and `NETWATCH_URL_0_REPORT`, and by an environment variable `NETWATCH_URLS`.
764
+ Network watching is governed by environment variables of the form `NETWATCH_URL_0_JOB`, `NETWATCH_URL_0_OBSERVE`, `NETWATCH_URL_0_REPORT`, and `NETWATCH_URL_0_AUTH`, and by an environment variable `NETWATCH_URLS`.
765
765
 
766
- You can create as many triples of `…JOB`, `OBSERVE`, and `…REPORT` variables as you want, one triple for each server that the agent may get jobs from. Each triple has a different number inside the variable name. The `…JOB` variable is the URL that the agent needs to send a job request to. The `…OBSERVE` variable is the URL that the agent needs to send granular job progress messages to. The `…REPORT` variable is the URL that the agent needs to send a completed report to. Each URL can contain segments and/or query parameters that identify the purpose of the request, the identity and authorization of the agent, etc.
766
+ You can create as many quadruples of `…JOB`, `OBSERVE`, `…REPORT`, and `AUTH` variables as you want, one quadruple for each server that the agent may get jobs from. Each quadruple has a different number inside the variable name. The `…JOB` variable is the URL that the agent needs to send a job request to. The `…OBSERVE` variable is the URL that the agent needs to send granular job progress messages to. The `…REPORT` variable is the URL that the agent needs to send a completed report to. The `…AUTH` variable is the password of the agent that will be recognized by the server. Each URL can contain segments and/or query parameters that identify the purpose of the request, the identity and authorization of the agent, etc.
767
+
768
+ In each quadruple, the `…AUTH` variable is optional. If it is truthy (i.e. it exists and has a non-empty value), then the job request sent to the server will be a `POST` request and the payload will be the password stored as the value of the variable. Otherwise, i.e. if the variable has an empty string as its value or does not exist, the request will be a `GET` request, and any agent password will need to be provided in the URL.
767
769
 
768
770
  The `NETWATCH_URLS` variable has a value of the form `0,3,4`. This is a comma-delimited list of the numbers of the servers to be polled.
769
771
 
770
- Once a Testaro instance obtains a network job from one of the servers, Testaro performs it and adds the result data to the job, which then becomes a report. Testaro also makes its `AGENT` value the value of the `sources.agent` property of the report. Testaro then sends the report in a `POST` request to the report URL with the same server number. If granular reporting is desired, Testaro sends progress messages to the observation URL.
772
+ Once a Testaro instance obtains a network job from one of the servers, Testaro performs it and adds the result data to the job, which then becomes a report. Testaro also makes its `AGENT` value the value of the `sources.agent` property of the report. Testaro then sends the report in a `POST` request to the report URL with the same server number. If there is a truthy `…AUTH` variable for the server, the request payload has this format:
773
+
774
+ ```json
775
+ {
776
+ "agentPW": "abcdef",
777
+ "report": {
778
+
779
+ }
780
+ }
781
+ ```
782
+
783
+ If there is no truthy `…AUTH` variable for the server, the request payload is simply the report in JSON format.
784
+
785
+ Thus, the `…AUTH` variables allow Testaro to comply with servers that object to agent passwords being visible in job request URLs and report-submission URLs and in any log messages that reproduce such URLs.
786
+
787
+ If granular reporting is desired, Testaro sends progress messages to the observation URL.
771
788
 
772
789
  Network watching can be repeated or 1-job. 1-job watching stops after 1 job has been performed.
773
790
 
package/netWatch.js CHANGED
@@ -44,6 +44,7 @@ const {doJob} = require('./run');
44
44
  const netWatchURLIDs = process.env.NETWATCH_URLS.split(/,/);
45
45
  const jobURLs = netWatchURLIDs.map(id => process.env[`NETWATCH_URL_${id}_JOB`]);
46
46
  const reportURLs = netWatchURLIDs.map(id => process.env[`NETWATCH_URL_${id}_REPORT`]);
47
+ const auths = netWatchURLIDs.map(id => process.env[`NETWATCH_URL_${id}_AUTH`]);
47
48
 
48
49
  // FUNCTIONS
49
50
 
@@ -62,7 +63,7 @@ const serveObject = (object, response) => {
62
63
  response.setHeader('Content-Type', 'application/json; charset=utf-8');
63
64
  response.end(JSON.stringify(object));
64
65
  };
65
- // Removes secrets from a URL.
66
+ // Removes the query if any, or otherwise the final segment, from a URL.
66
67
  const getURLBase = url => url.replace(/[?/][^?/.]+$/, '');
67
68
  /*
68
69
  Requests a network job and, when found, performs and reports it.
@@ -92,7 +93,6 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
92
93
  let urlIndex = -1;
93
94
  let noJobYet = true;
94
95
  let abort = false;
95
- const certOpt = isCertTolerant ? {rejectUnauthorized: false} : {};
96
96
  const certInfo = `Certificate-${isCertTolerant ? '' : 'in'}tolerant`;
97
97
  const foreverInfo = isForever ? 'repeating' : 'one-job';
98
98
  const intervalInfo = `with ${intervalInSeconds}-second intervals`;
@@ -117,14 +117,18 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
117
117
  cycleIndex = ++cycleIndex % urlCount;
118
118
  urlIndex = ++urlIndex % urlCount;
119
119
  const jobURL = jobURLs[urlIndex];
120
- const publicURL = getURLBase(jobURL);
120
+ const publicURL = auths[urlIndex] ? jobURL : getURLBase(jobURL);
121
121
  const logStart = `Requested job from ${publicURL} and got `;
122
122
  // Perform it.
123
123
  await new Promise(resolve => {
124
124
  try {
125
125
  const client = jobURL.startsWith('https://') ? httpsClient : httpClient;
126
126
  // Request a job.
127
- client.request(jobURL, certOpt, response => {
127
+ const requestOptions = isCertTolerant ? {rejectUnauthorized: false} : {};
128
+ if (auths[urlIndex]) {
129
+ requestOptions.method = 'POST';
130
+ }
131
+ client.request(jobURL, requestOptions, response => {
128
132
  const chunks = [];
129
133
  response
130
134
  // If the response throws an error:
@@ -175,10 +179,14 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
175
179
  // Perform the job and create a report.
176
180
  console.log(`${logStart}job ${id} for server ${urlIndex} (${nowString()})`);
177
181
  const report = await doJob(contentObj);
178
- let reportJSON = JSON.stringify(report, null, 2);
182
+ const responseObj = auths[urlIndex] ? {
183
+ agentPW: auths[urlIndex],
184
+ report
185
+ } : report;
186
+ let responseJSON = JSON.stringify(responseObj, null, 2);
179
187
  console.log(`Job ${id} finished (${nowString()})`);
180
188
  const reportURL = reportURLs[urlIndex];
181
- const publicReportURL = getURLBase(reportURL);
189
+ const publicReportURL = auths[urlIndex] ? reportURL : getURLBase(reportURL);
182
190
  const reportClient = reportURL.startsWith('https://')
183
191
  ? httpsClient
184
192
  : httpClient;
@@ -218,7 +226,7 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
218
226
  }
219
227
  // Free the memory used by the job and the report.
220
228
  contentObj = {};
221
- reportJSON = '';
229
+ responseJSON = '';
222
230
  resolve(true);
223
231
  });
224
232
  })
@@ -233,7 +241,7 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
233
241
  resolve(true);
234
242
  })
235
243
  // Finish submitting the report.
236
- .end(reportJSON);
244
+ .end(responseJSON);
237
245
  }
238
246
  }
239
247
  // Otherwise, i.e. if it is a message:
@@ -281,8 +289,10 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
281
289
  }
282
290
  resolve(true);
283
291
  })
284
- // Finish sending the job request.
285
- .end();
292
+ // Finish sending the job request, with a password if a POST request.
293
+ .end(auths[urlIndex] ? JSON.stringify({
294
+ agentPW: auths[urlIndex]
295
+ }) : '');
286
296
  }
287
297
  // If requesting a job throws an error:
288
298
  catch(error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "52.0.5",
3
+ "version": "53.0.2",
4
4
  "description": "Run 1000 web accessibility tests from 11 tools and get a standardized report",
5
5
  "main": "index.js",
6
6
  "scripts": {