@suffolklitlab/alkiln 4.11.1 → 4.11.3

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/CHANGELOG.md CHANGED
@@ -40,6 +40,20 @@ Format:
40
40
  -->
41
41
  <!-- ## [Unreleased] -->
42
42
 
43
+ ## [4.11.3] - 2023-04-06
44
+ ### Changed
45
+ - Project name prefix now includes ALKiln in it for clarity
46
+
47
+ ### Fixed
48
+ - Projects created in da each have a unique name. https://github.com/SuffolkLITLab/ALKiln/issues/663
49
+
50
+ ## [4.11.2] - 2023-03-22
51
+ ### Security
52
+ - Pass docassemble API keys through HTTP headers instead of as parameters.
53
+ - ACTION: all users should delete any uWSGI logs that show their API keys.
54
+ - Parameters to certain HTTP requests are printed directly in docassemble's
55
+ uWSGI log, leaking API keys to actors with log access on your docassemble
56
+ server.
43
57
 
44
58
  ## [4.11.1] - 2023-03-21
45
59
  ### Changed
@@ -19,8 +19,8 @@ da.get_dev_id = async function ( timeout ) {
19
19
  /* Get docassemble developer id. */
20
20
  let options = {
21
21
  method: 'GET',
22
+ headers: {'X-API-Key': session_vars.get_dev_api_key()},
22
23
  url: `${ session_vars.get_da_server_url() }/api/user`,
23
- params: { key: session_vars.get_dev_api_key(), },
24
24
  timeout: timeout,
25
25
  };
26
26
 
@@ -37,9 +37,9 @@ da.create_project = async function ( project_name, timeout ) {
37
37
  /* Create a new project on the user's da server. */
38
38
  let options = {
39
39
  method: 'POST',
40
+ headers: {'X-API-Key': session_vars.get_dev_api_key()},
40
41
  url: `${ session_vars.get_da_server_url() }/api/playground/project`,
41
42
  data: qs.stringify({
42
- key: session_vars.get_dev_api_key(),
43
43
  project: project_name,
44
44
  }),
45
45
  timeout: timeout,
@@ -58,9 +58,9 @@ da.pull = async function ( timeout ) {
58
58
  /* Pull github code into an existing Project. */
59
59
  let options = {
60
60
  method: 'POST',
61
+ headers: {'X-API-Key': session_vars.get_dev_api_key()},
61
62
  url: `${ session_vars.get_da_server_url() }/api/playground_pull`,
62
63
  data: qs.stringify({
63
- key: session_vars.get_dev_api_key(),
64
64
  project: session_vars.get_project_name(),
65
65
  github_url: session_vars.get_repo_url(),
66
66
  branch: session_vars.get_branch_name(),
@@ -81,9 +81,9 @@ da.has_task_finished = async function ( task_id, timeout ) {
81
81
  /* Check task status based on `task_id`. */
82
82
  let options = {
83
83
  method: 'GET',
84
+ headers: {'X-API-Key': session_vars.get_dev_api_key()},
84
85
  url: `${ session_vars.get_da_server_url() }/api/restart_status`,
85
86
  params: {
86
- key: session_vars.get_dev_api_key(),
87
87
  task_id: task_id,
88
88
  },
89
89
  timeout: timeout,
@@ -102,9 +102,9 @@ da.delete_project = async function ( timeout ) {
102
102
  /* Delete a project on the user's da server. */
103
103
  let options = {
104
104
  method: 'DELETE',
105
+ headers: {'X-API-Key': session_vars.get_dev_api_key()},
105
106
  url: `${ session_vars.get_da_server_url() }/api/playground/project`,
106
107
  params: {
107
- key: session_vars.get_dev_api_key(),
108
108
  project: session_vars.get_project_name(),
109
109
  },
110
110
  timeout: timeout,
@@ -132,9 +132,9 @@ da.__delete_projects_starting_with = async function ( base_name, starting_num=1,
132
132
 
133
133
  let options = {
134
134
  method: 'DELETE',
135
+ headers: {'X-API-Key': session_vars.get_dev_api_key()},
135
136
  url: `${ session_vars.get_da_server_url() }/api/playground/project`,
136
137
  params: {
137
- key: session_vars.get_dev_api_key(),
138
138
  project: project_name,
139
139
  },
140
140
  timeout: 30 * 1000,
@@ -204,16 +204,17 @@ da_i.loop_to_create_project = async function( creation_options ) {
204
204
  let wait_seconds = creation_options.wait_seconds || 5;
205
205
 
206
206
  let project_name = null;
207
- let name_incrementor = 0;
207
+ // Unlikely, but 2 devs could run locally and create the same Project name
208
+ let num_tries = 0;
208
209
 
209
210
  // Try to create a project. If the project name is already taken, increment and loop again.
210
- while ( name_incrementor <= max_tries ) {
211
- name_incrementor++;
211
+ while ( num_tries <= max_tries ) {
212
+ num_tries++;
212
213
  try {
213
214
 
214
215
  // Try next name that could be unique. Must remove all non-valid characters
215
216
  // TODO: This sanitization is already done in session_vars, so remove it from here
216
- project_name = session_vars.get_project_base_name().replace(/[^A-Za-z0-9]/g, '') + name_incrementor;
217
+ project_name = session_vars.get_project_base_name().replace(/[^A-Za-z0-9]/g, '') + `${Date.now()}`;
217
218
  log.info({ pre: `Trying to create a docassemble Project with the name ${ project_name }` });
218
219
  let response = await _da_REST.create_project( project_name, timeout );
219
220
  log.info({ pre: `The docassemble server is ready. Created a Project named ${ project_name }` });
@@ -222,11 +223,11 @@ da_i.loop_to_create_project = async function( creation_options ) {
222
223
 
223
224
  } catch ( error ) {
224
225
  // TODO: Make a `normalize_ajax_responses_and_errors()`?
225
- let response = error.response;
226
+ let response = error;
226
227
 
227
228
  if ( response && response.data ) {
228
229
  if ( response.data.includes( `Invalid project` ) ) {
229
- if ( name_incrementor < max_tries ) {
230
+ if ( num_tries < max_tries ) {
230
231
  // A non-unique project name. Try the next project name.
231
232
  continue;
232
233
 
@@ -254,11 +255,11 @@ da_i.loop_to_create_project = async function( creation_options ) {
254
255
 
255
256
  // If it's a timeout error, server is busy. Try again after waiting.
256
257
  // Why are we using `max_tries` for timeout error as well?
257
- if ( is_timeout_error( error ) && name_incrementor < max_tries ) {
258
+ if ( is_timeout_error( error ) && num_tries < max_tries ) {
258
259
  log.info({ pre: `The docassemble server was busy when we tried to `
259
- + `create the Project. Attempt ${ name_incrementor } of `
260
+ + `create the Project. Attempt ${ num_tries } of `
260
261
  + `${ max_tries }. Will try again in ${ wait_seconds } seconds.` });
261
- name_incrementor--; // Try this name again next time
262
+ num_tries--; // Don't count this try
262
263
  await time.waitForTimeout( wait_seconds * 1000 );
263
264
  continue;
264
265
 
@@ -25,6 +25,7 @@ const setup = async () => {
25
25
  // avoids showing confusing node errors to users that they shouldn't have to fix
26
26
  try {
27
27
  project_name = await da_i.loop_to_create_project();
28
+ log.info({type: `setup`, pre: `Created a Project named ${ project_name }`});
28
29
  } catch (error) {
29
30
  log.error({type: `setup`, pre: `an unexpected error occurred while trying to create a docassemble project in the user's account`, data: JSON.stringify(error, null, 4)})
30
31
  // we don't re-throw the exception, so make sure to exit with 1 to let Github Actions know the script failed
@@ -75,7 +75,7 @@ session_vars.get_package_name = function () {
75
75
  };
76
76
 
77
77
  session_vars.get_project_base_name = function () {
78
- let name = `testing${ session_vars.get_package_name() }${ session_vars.get_branch_name() }`;
78
+ let name = `ALKilnTest${ session_vars.get_package_name() }${ session_vars.get_branch_name() }`;
79
79
  let sanitized_name = name.replace( /[^A-Za-z0-9]/g, '' );
80
80
  return sanitized_name;
81
81
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suffolklitlab/alkiln",
3
- "version": "4.11.1",
3
+ "version": "4.11.3",
4
4
  "description": "Integrated automated end-to-end testing with docassemble, puppeteer, and cucumber.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {