@coffre/conformance 0.6.0 → 0.6.1

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/dist/main.js CHANGED
@@ -4166,6 +4166,48 @@ const pasteInto = (steps) => `(async () => {
4166
4166
  return answer;
4167
4167
  })()`;
4168
4168
  /**
4169
+ * A new secret's value typed as a person would: `first`, Shift+Enter while composing (which does nothing), Shift+Enter, then
4170
+ * `second` into whichever field the page has by then; then the row saved.
4171
+ * Answers which field has the focus after the line break, and where its caret is.
4172
+ */
4173
+ const typeLines = (steps) => `(async () => {
4174
+ const { name, field, first, second, save } = ${JSON.stringify(steps)};
4175
+ const wait = (ms = 100) => new Promise((resolve) => setTimeout(resolve, ms));
4176
+ const shown = async (label) => {
4177
+ for (let tries = 0; tries < 50; tries++, await wait()) {
4178
+ const found = document.querySelector(\`[aria-label="\${label}"]\`);
4179
+ if (found !== null) return found;
4180
+ }
4181
+ return null;
4182
+ };
4183
+ const button = (words) => [...document.querySelectorAll('button')].find((each) => each.getAttribute('aria-label') === words || each.textContent.trim() === words);
4184
+ const typed = (node, text) => {
4185
+ Object.getOwnPropertyDescriptor(Object.getPrototypeOf(node), 'value').set.call(node, text);
4186
+ node.dispatchEvent(new Event('input', { bubbles: true }));
4187
+ node.setSelectionRange(text.length, text.length);
4188
+ };
4189
+ button('New secret')?.click();
4190
+ const named = await shown('Name of the new secret');
4191
+ if (named === null) return { field: null };
4192
+ typed(named, name);
4193
+ const input = await shown(field);
4194
+ if (input === null) return { field: null };
4195
+ input.focus();
4196
+ typed(input, first);
4197
+ // Shift+Enter that confirms an input method's composition is not a line break.
4198
+ input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', shiftKey: true, isComposing: true, bubbles: true, cancelable: true }));
4199
+ await wait(300);
4200
+ if (document.activeElement !== input || input.value !== first) return { field: 'composing', value: document.activeElement.value };
4201
+ input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', shiftKey: true, bubbles: true, cancelable: true }));
4202
+ await wait(300);
4203
+ const focused = document.activeElement;
4204
+ const answer = { field: focused.tagName.toLowerCase(), label: focused.getAttribute('aria-label'), value: focused.value, caret: [focused.selectionStart, focused.selectionEnd] };
4205
+ typed(focused, focused.value + second);
4206
+ await wait(100);
4207
+ button(save)?.click();
4208
+ return answer;
4209
+ })()`;
4210
+ /**
4169
4211
  * A multi-line value pasted into a secret's value field keeps its line
4170
4212
  * breaks. A text input drops them, so the page puts the paste into the
4171
4213
  * value itself and turns the field into a textarea, the caret after the
@@ -4213,14 +4255,29 @@ async function pastedValues(deployment, admin, browser) {
4213
4255
  label: "New value for EDITED_KEY",
4214
4256
  caret: [after, after]
4215
4257
  }), "a PEM key pasted into an edited value did not leave a textarea focused, its caret after the paste", editing.answer);
4258
+ const typing = await chrome.load(page, admin.browser.cookies(), void 0, typeLines({
4259
+ name: "TYPED_KEY",
4260
+ field: "Value for TYPED_KEY",
4261
+ first: "abc",
4262
+ second: "def",
4263
+ save: "Save TYPED_KEY now"
4264
+ }));
4265
+ expect(typing.errors.length === 0, `${page} reported errors in the browser`, typing.errors.join("\n"));
4266
+ expect(JSON.stringify(typing.answer) === JSON.stringify({
4267
+ field: "textarea",
4268
+ label: "Value for TYPED_KEY",
4269
+ value: "abc\n",
4270
+ caret: [4, 4]
4271
+ }), "Shift+Enter typed in a new secret's value did not leave a textarea focused holding the line break, its caret after it", typing.answer);
4216
4272
  } finally {
4217
4273
  await chrome.close();
4218
4274
  }
4219
4275
  const { values } = await admin.api.secrets.reveal(PASTED);
4276
+ expect(values.TYPED_KEY === "abc\ndef", `the typed secret saved ${shape(values.TYPED_KEY)}, not two lines, abc and def`);
4220
4277
  expect(values.PASTED_KEY === added, `the new secret saved ${shape(values.PASTED_KEY)}, not the ${shape(added)} pasted`);
4221
4278
  const edited = before.slice(0, 8) + edit + before.slice(20);
4222
4279
  expect(values.EDITED_KEY === edited, `the edited secret saved ${shape(values.EDITED_KEY)}, not the ${shape(edited)} of its value with the paste in characters 8 to 20`);
4223
- return `in Chrome, a ${added.split("\n").length - 1}-line PEM key pasted into a new secret's value and into part of an edited one: each field a textarea after, focused, its caret after the paste; the new value saved byte for byte, the edited one with the paste in place and its \r\n as \n`;
4280
+ return `in Chrome, a ${added.split("\n").length - 1}-line PEM key pasted into a new secret's value and into part of an edited one: each field a textarea after, focused, its caret after the paste; the new value saved byte for byte, the edited one with the paste in place and its \r\n as \n; and a value typed with Shift+Enter between two words saved as two lines`;
4224
4281
  }
4225
4282
  /**
4226
4283
  * A refused sign-in, said once: the page coffre sends the browser back to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffre/conformance",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Checks a coffre deployment from outside: what it must never do, whatever code it runs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -31,8 +31,8 @@
31
31
  "dependencies": {
32
32
  "jose": "6.2.3",
33
33
  "pg": "8.16.3",
34
- "@coffre/cli": "0.6.0",
35
- "@coffre/db": "0.6.0"
34
+ "@coffre/db": "0.6.1",
35
+ "@coffre/cli": "0.6.1"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "26.1.1",
@@ -41,7 +41,7 @@
41
41
  "tsdown": "0.23.0",
42
42
  "typescript": "5.9.3",
43
43
  "vite": "8.1.5",
44
- "@coffre/client": "0.6.0"
44
+ "@coffre/client": "0.6.1"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "tsdown",
@@ -214,6 +214,49 @@ const pasteInto = (steps: { open: string; name?: string; field: string; select?:
214
214
  return answer;
215
215
  })()`;
216
216
 
217
+ /**
218
+ * A new secret's value typed as a person would: `first`, Shift+Enter while composing (which does nothing), Shift+Enter, then
219
+ * `second` into whichever field the page has by then; then the row saved.
220
+ * Answers which field has the focus after the line break, and where its caret is.
221
+ */
222
+ const typeLines = (steps: { name: string; field: string; first: string; second: string; save: string }) => `(async () => {
223
+ const { name, field, first, second, save } = ${JSON.stringify(steps)};
224
+ const wait = (ms = 100) => new Promise((resolve) => setTimeout(resolve, ms));
225
+ const shown = async (label) => {
226
+ for (let tries = 0; tries < 50; tries++, await wait()) {
227
+ const found = document.querySelector(\`[aria-label="\${label}"]\`);
228
+ if (found !== null) return found;
229
+ }
230
+ return null;
231
+ };
232
+ const button = (words) => [...document.querySelectorAll('button')].find((each) => each.getAttribute('aria-label') === words || each.textContent.trim() === words);
233
+ const typed = (node, text) => {
234
+ Object.getOwnPropertyDescriptor(Object.getPrototypeOf(node), 'value').set.call(node, text);
235
+ node.dispatchEvent(new Event('input', { bubbles: true }));
236
+ node.setSelectionRange(text.length, text.length);
237
+ };
238
+ button('New secret')?.click();
239
+ const named = await shown('Name of the new secret');
240
+ if (named === null) return { field: null };
241
+ typed(named, name);
242
+ const input = await shown(field);
243
+ if (input === null) return { field: null };
244
+ input.focus();
245
+ typed(input, first);
246
+ // Shift+Enter that confirms an input method's composition is not a line break.
247
+ input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', shiftKey: true, isComposing: true, bubbles: true, cancelable: true }));
248
+ await wait(300);
249
+ if (document.activeElement !== input || input.value !== first) return { field: 'composing', value: document.activeElement.value };
250
+ input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', shiftKey: true, bubbles: true, cancelable: true }));
251
+ await wait(300);
252
+ const focused = document.activeElement;
253
+ const answer = { field: focused.tagName.toLowerCase(), label: focused.getAttribute('aria-label'), value: focused.value, caret: [focused.selectionStart, focused.selectionEnd] };
254
+ typed(focused, focused.value + second);
255
+ await wait(100);
256
+ button(save)?.click();
257
+ return answer;
258
+ })()`;
259
+
217
260
  /**
218
261
  * A multi-line value pasted into a secret's value field keeps its line
219
262
  * breaks. A text input drops them, so the page puts the paste into the
@@ -250,14 +293,22 @@ export async function pastedValues(deployment: Deployment, admin: Person, browse
250
293
  "a PEM key pasted into an edited value did not leave a textarea focused, its caret after the paste",
251
294
  editing.answer,
252
295
  );
296
+ const typing = await chrome.load(page, admin.browser.cookies(), undefined, typeLines({ name: 'TYPED_KEY', field: 'Value for TYPED_KEY', first: 'abc', second: 'def', save: 'Save TYPED_KEY now' }));
297
+ expect(typing.errors.length === 0, `${page} reported errors in the browser`, typing.errors.join('\n'));
298
+ expect(
299
+ JSON.stringify(typing.answer) === JSON.stringify({ field: 'textarea', label: 'Value for TYPED_KEY', value: 'abc\n', caret: [4, 4] }),
300
+ "Shift+Enter typed in a new secret's value did not leave a textarea focused holding the line break, its caret after it",
301
+ typing.answer,
302
+ );
253
303
  } finally {
254
304
  await chrome.close();
255
305
  }
256
306
  const { values } = await admin.api.secrets.reveal(PASTED);
307
+ expect(values.TYPED_KEY === 'abc\ndef', `the typed secret saved ${shape(values.TYPED_KEY)}, not two lines, abc and def`);
257
308
  expect(values.PASTED_KEY === added, `the new secret saved ${shape(values.PASTED_KEY)}, not the ${shape(added)} pasted`);
258
309
  const edited = before.slice(0, 8) + edit + before.slice(20);
259
310
  expect(values.EDITED_KEY === edited, `the edited secret saved ${shape(values.EDITED_KEY)}, not the ${shape(edited)} of its value with the paste in characters 8 to 20`);
260
- return `in Chrome, a ${added.split('\n').length - 1}-line PEM key pasted into a new secret's value and into part of an edited one: each field a textarea after, focused, its caret after the paste; the new value saved byte for byte, the edited one with the paste in place and its \r\n as \n`;
311
+ return `in Chrome, a ${added.split('\n').length - 1}-line PEM key pasted into a new secret's value and into part of an edited one: each field a textarea after, focused, its caret after the paste; the new value saved byte for byte, the edited one with the paste in place and its \r\n as \n; and a value typed with Shift+Enter between two words saved as two lines`;
261
312
  }
262
313
 
263
314
  /**