kryptheon 0.1.48 → 0.1.50
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/README.md +435 -333
- package/bin/kryptheon.js +231 -16
- package/kryptheon-code.js +158 -2
- package/kryptheon-dashboard-page.js +78 -6
- package/kryptheon-dashboard.html +9 -0
- package/kryptheon-dashboard.js +241 -13
- package/kryptheon-edge.js +83 -14
- package/kryptheon-heal.js +57 -0
- package/kryptheon-payments-run.js +501 -0
- package/kryptheon-payments.js +626 -0
- package/kryptheon-probe-fixture.js +175 -8
- package/kryptheon-probe.js +368 -317
- package/kryptheon-reliability.js +430 -40
- package/kryptheon-replay.js +0 -0
- package/kryptheon-secrets.js +14 -3
- package/package.json +12 -5
package/kryptheon-edge.js
CHANGED
|
@@ -152,14 +152,21 @@ function candidateFields(source) {
|
|
|
152
152
|
lines.forEach((line, i) => {
|
|
153
153
|
if (/\.fill\(/.test(line) && (replay.isSecretField(replay.nameInLine(line)) || /process\.env\./.test(line))) signInEnd = i + 1;
|
|
154
154
|
});
|
|
155
|
-
|
|
155
|
+
// Each field once, by its last fill: that is the value the form sent. Found
|
|
156
|
+
// on blind round 20: "Duration" typed 6, then 62, then 60 - the first was
|
|
157
|
+
// taken as what was recorded, no request carried it, and no value past
|
|
158
|
+
// the form was ever sent.
|
|
159
|
+
const fills = fillSteps(text).filter((step) => step.line > signInEnd && !replay.isSecretField(step.name));
|
|
160
|
+
const last = new Map();
|
|
161
|
+
for (const step of fills) last.set(step.locator.replace(/\s+/g, ' '), step);
|
|
162
|
+
// In the order the fields were first typed into; each its last fill.
|
|
156
163
|
const out = [];
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const key = step.locator.replace(/\s+/g, ' ');
|
|
164
|
+
const seen = new Set();
|
|
165
|
+
for (const first of fills) {
|
|
166
|
+
const key = first.locator.replace(/\s+/g, ' ');
|
|
161
167
|
if (seen.has(key)) continue;
|
|
162
168
|
seen.add(key);
|
|
169
|
+
const step = last.get(key);
|
|
163
170
|
// Saved by a click on Save/Add/Create... or an Enter, before the flow
|
|
164
171
|
// goes anywhere else.
|
|
165
172
|
let saves = false;
|
|
@@ -342,12 +349,26 @@ function flatten(value, prefix, out) {
|
|
|
342
349
|
return into;
|
|
343
350
|
}
|
|
344
351
|
|
|
345
|
-
|
|
352
|
+
// Taken by the app: a 2xx, or a form's redirect after it saved (probe.accepted).
|
|
353
|
+
const ok = (w) => probe.accepted(w);
|
|
346
354
|
const writesOf = (r) => ((r && r.events) || []).filter((e) => e.kind === 'write');
|
|
347
355
|
const routeOf = (w) => w.method + ' ' + w.host + w.path;
|
|
348
356
|
// A write the app accepted and keeps: not the sign-in, not a delete.
|
|
349
357
|
const leftBehind = (w) => ok(w) && w.method !== 'DELETE' && !w.signIn;
|
|
350
358
|
|
|
359
|
+
/**
|
|
360
|
+
* The kind of record an address saves: its ids, and a trailing edit or new,
|
|
361
|
+
* taken off - POST /pets and POST /pets/7/edit both save a pet, and POST
|
|
362
|
+
* /settings saves something else. Found on blind round 20: a pet's "name"
|
|
363
|
+
* and the studio's "name" were said as one problem.
|
|
364
|
+
*/
|
|
365
|
+
function recordStem(p) {
|
|
366
|
+
return String(p || '')
|
|
367
|
+
.replace(/\/(\d+|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{24})(?=\/|$)/gi, '/:id')
|
|
368
|
+
.replace(/\/(edit|new|create|update)$/i, '')
|
|
369
|
+
.replace(/\/:id$/, '');
|
|
370
|
+
}
|
|
371
|
+
|
|
351
372
|
/** Writes of the plain replay and of a variant, paired by where they went, in order. */
|
|
352
373
|
function pairWrites(clean, variant) {
|
|
353
374
|
const left = {};
|
|
@@ -490,7 +511,21 @@ function judgeVariant(clean, variant, plan) {
|
|
|
490
511
|
}));
|
|
491
512
|
}
|
|
492
513
|
|
|
493
|
-
|
|
514
|
+
// Sent back to the form, where the recorded save went on to another page:
|
|
515
|
+
// the form was sent back to be filled in again - the value was refused.
|
|
516
|
+
// Back to it by a redirect, or the form drawn again in a 200 with no record
|
|
517
|
+
// in it - the way a server-rendered form shows its errors.
|
|
518
|
+
const movedOn = (w) => w && ok(w) && w.status >= 300 && w.status < 400 && !probe.backToForm(w);
|
|
519
|
+
// Or both went back to the form, but with another message than the
|
|
520
|
+
// recorded save's (blind round 21: /settings?notice=Settings saved for the
|
|
521
|
+
// save, /settings?notice=Check the settings and try again for the value).
|
|
522
|
+
const answeredOtherwise = (s) => s.cleanWrite && ok(s.cleanWrite) && probe.backToForm(s.cleanWrite) && probe.backToForm(s.write) &&
|
|
523
|
+
probe.answerShape(s.cleanWrite) !== probe.answerShape(s.write);
|
|
524
|
+
const sentBack = (s) => s.write.shownAfter !== true && (answeredOtherwise(s) || (movedOn(s.cleanWrite) &&
|
|
525
|
+
(probe.backToForm(s.write) || (s.write.status >= 200 && s.write.status < 300 && s.write.answer == null))));
|
|
526
|
+
const allSaved = savedValues(clean, variant, field, plan.value);
|
|
527
|
+
const saved = allSaved.filter((s) => !sentBack(s));
|
|
528
|
+
const sentBackWrites = allSaved.filter(sentBack).map((s) => s.write);
|
|
494
529
|
if (saved.length) {
|
|
495
530
|
// What the server says it kept decides, when it says: a -5 it turned
|
|
496
531
|
// into 0 was not saved as -5. Without an answer, the request decides.
|
|
@@ -521,19 +556,40 @@ function judgeVariant(clean, variant, plan) {
|
|
|
521
556
|
: kind === 'long' && info.maxLength != null ? 'The field allows ' + info.maxLength + ' characters, but the server stored ' + LONG_LENGTH + '.'
|
|
522
557
|
: kind === 'over' ? 'The page allows at most ' + info.maxLength + ' characters, but the server stored ' + String(plan.value).length + '.'
|
|
523
558
|
: null;
|
|
559
|
+
// A form that redirects sends no record back. A redirect on to another
|
|
560
|
+
// page is the save going through (Post, Redirect, Get); one straight back
|
|
561
|
+
// to the form may be the form sent back to be filled in again - unless
|
|
562
|
+
// the page it went to shows the value.
|
|
563
|
+
const w0 = saved[0].write;
|
|
564
|
+
const redirected = w0.status >= 300 && w0.status < 400;
|
|
565
|
+
// Back to the form with the very answer the recorded save got - "Settings
|
|
566
|
+
// saved" for both - is the save going through.
|
|
567
|
+
const c0 = saved[0].cleanWrite;
|
|
568
|
+
const asSaved = redirected && c0 && ok(c0) && probe.backToForm(c0) && probe.backToForm(w0) && probe.answerShape(c0) === probe.answerShape(w0);
|
|
569
|
+
const weak = redirected && probe.backToForm(w0) && w0.shownAfter !== true && !asSaved;
|
|
570
|
+
const pageLine = redirected && w0.shownAfter === true ? ['The page it went to after saving, ' + w0.to + ', shows ' + show(plan.value) + '.']
|
|
571
|
+
: asSaved ? ['It answered as your recorded save did (' + w0.to + ') - the value was taken.']
|
|
572
|
+
: weak ? ['It answered with a redirect back to the form (' + w0.to + '), which does not say whether it kept the value.'] : [];
|
|
524
573
|
if (problem || toCheck) {
|
|
574
|
+
const sure = problem && !weak;
|
|
525
575
|
findings.push(Object.assign({}, base, {
|
|
526
|
-
|
|
527
|
-
|
|
576
|
+
// The same value taken into the same field by the same app, whichever
|
|
577
|
+
// flow sent it - a create and an edit of the same record.
|
|
578
|
+
same: saved[0].key ? kind + '|' + (w0.origin || w0.host || '') + recordStem(w0.path) + '|' + saved[0].key : null,
|
|
579
|
+
sameRequest: probe.writeWords(w0),
|
|
580
|
+
type: 'accepted', severity: sure ? 'MEDIUM' : 'LOW', status: sure ? 'confirmed' : 'verification required',
|
|
581
|
+
headline: sure ? '"' + name + '" accepts ' + words + ', and the app saved it.'
|
|
582
|
+
: problem ? '"' + name + '" was sent ' + words + ' and the app did not refuse it - check whether it kept it.'
|
|
528
583
|
: '"' + name + '" took ' + words + ' and the app ' + savedWords + ' - check that this is allowed.',
|
|
529
584
|
proof: ['Flow: ' + plan.flow.title + ' (' + where + ')', 'Typed into "' + name + '": ' + show(plan.value)]
|
|
530
|
-
.concat(proofLines(saved), why ? [why] : []),
|
|
585
|
+
.concat(proofLines(saved), pageLine, why && !weak ? [why] : []),
|
|
531
586
|
}));
|
|
532
587
|
}
|
|
533
588
|
}
|
|
534
589
|
|
|
535
590
|
if (findings.length) return { outcome: 'found', findings: findings };
|
|
536
|
-
|
|
591
|
+
// Refused: a 4xx, or a form's redirect to the sign-in page or with an error.
|
|
592
|
+
const refused = writesOf(variant).filter((w) => (w.status >= 400 && w.status < 500) || (w.status >= 300 && w.status < 400 && !ok(w)) || sentBackWrites.includes(w));
|
|
537
593
|
// The form's own checks (required, min, max, type) stopped the submit:
|
|
538
594
|
// nothing reached the server, so the server was not tested - which is not
|
|
539
595
|
// the same as the app handling it. Found on blind round 17: an empty
|
|
@@ -545,7 +601,7 @@ function judgeVariant(clean, variant, plan) {
|
|
|
545
601
|
}
|
|
546
602
|
return {
|
|
547
603
|
outcome: 'held',
|
|
548
|
-
why: refused.length ? 'the app refused it (' + probe.writeWords(refused[0]) + ')'
|
|
604
|
+
why: refused.length ? (sentBackWrites.includes(refused[0]) ? 'the app sent the form back instead of saving it (' : 'the app refused it (') + probe.writeWords(refused[0]) + ')'
|
|
549
605
|
: saved.length ? 'saved, and nothing broke' : 'nothing was saved and nothing broke',
|
|
550
606
|
findings: [],
|
|
551
607
|
};
|
|
@@ -677,7 +733,7 @@ async function run(root, flows, options) {
|
|
|
677
733
|
|
|
678
734
|
const report = {
|
|
679
735
|
check: 'edge', runId: runId, startedAt: new Date().toISOString(), endedAt: null,
|
|
680
|
-
stopped: false, runsPlanned: 0, runsDone: 0, flows: [], findings: [], held: [], notTested: [], testData: [], writeHosts: [],
|
|
736
|
+
stopped: false, runsPlanned: 0, runsDone: 0, flows: [], findings: [], held: [], notTested: [], testData: [], writeHosts: [], writeHostsFrom: 'page+vendor',
|
|
681
737
|
};
|
|
682
738
|
|
|
683
739
|
// 1. The plain replay of every flow that has a field to try.
|
|
@@ -925,7 +981,19 @@ async function run(root, flows, options) {
|
|
|
925
981
|
report.notTested.push(Object.assign(label, { why: !results[p.id] && stopped ? 'stopped before it finished' : v.verdict.why }));
|
|
926
982
|
}
|
|
927
983
|
else if (v.verdict.outcome === 'held') report.held.push(Object.assign(label, { why: v.verdict.why }));
|
|
928
|
-
for (const f of v.verdict.findings)
|
|
984
|
+
for (const f of v.verdict.findings) {
|
|
985
|
+
// A create flow and an edit flow posting to the same address with the
|
|
986
|
+
// same field are one problem in the server, said once (blind round 17:
|
|
987
|
+
// each value was reported twice).
|
|
988
|
+
const first = f.same && report.findings.find((g) => g.same === f.same && g.status === f.status);
|
|
989
|
+
if (first) {
|
|
990
|
+
first.alsoIn = (first.alsoIn || 0) + 1;
|
|
991
|
+
if (first.alsoIn <= 3) first.proof.push('The same in "' + f.flow + '" (' + f.where + '): ' + f.sameRequest + '.');
|
|
992
|
+
report.held.push(Object.assign({}, label, { why: 'the same as in "' + first.flow + '" (' + first.where + ') - said once, there' }));
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
report.findings.push(f);
|
|
996
|
+
}
|
|
929
997
|
for (const w of writesOf(results[p.id])) if (leftBehind(w)) report.testData.push({ flow: p.flow.title, value: KINDS[p.kind].words, request: probe.writeWords(w) });
|
|
930
998
|
}
|
|
931
999
|
// Markup, judged across every run of this press.
|
|
@@ -1102,6 +1170,7 @@ module.exports = { formStops: formStops, straightManySource: straightManySource,
|
|
|
1102
1170
|
straightSource: straightSource,
|
|
1103
1171
|
judgeMarkers: judgeMarkers,
|
|
1104
1172
|
fixPrompt: fixPrompt,
|
|
1173
|
+
recordStem: recordStem,
|
|
1105
1174
|
run: run,
|
|
1106
1175
|
recheck: recheck,
|
|
1107
1176
|
save: save,
|
package/kryptheon-heal.js
CHANGED
|
@@ -203,6 +203,46 @@ function watch(page, options) {
|
|
|
203
203
|
return real.apply(locator, args);
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
// A text step whose words hold a count: "Projects3", "Shared Launch room 0".
|
|
207
|
+
// Found on blind round 19: three recordings clicked such text, each replay
|
|
208
|
+
// added a record, the count moved, and they never passed again - so none of
|
|
209
|
+
// the checks that replay them ever ran. Followed only when the same words
|
|
210
|
+
// with other numbers are on the page exactly once.
|
|
211
|
+
const byText = page.getByText.bind(page);
|
|
212
|
+
async function textAct(locator, real, method, args, text) {
|
|
213
|
+
const there = await locator
|
|
214
|
+
.first()
|
|
215
|
+
.waitFor({ state: 'attached', timeout: probeMs })
|
|
216
|
+
.then(() => true, () => false);
|
|
217
|
+
if (!there) {
|
|
218
|
+
const pattern = countPattern(text);
|
|
219
|
+
if (pattern) {
|
|
220
|
+
const replacement = byText(pattern);
|
|
221
|
+
const count = await replacement.count().catch(() => 0);
|
|
222
|
+
if (count === 1) {
|
|
223
|
+
const now = String(await replacement.innerText({ timeout: 2000 }).catch(() => '')).replace(/\s+/g, ' ').trim().slice(0, 120);
|
|
224
|
+
if (now) {
|
|
225
|
+
renamed.push({ role: 'text', was: text, now: now, counted: true });
|
|
226
|
+
return replacement[method].apply(replacement, args);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return real.apply(locator, args);
|
|
232
|
+
}
|
|
233
|
+
page.getByText = function (text, textOptions) {
|
|
234
|
+
const locator = byText(text, textOptions);
|
|
235
|
+
if (typeof text !== 'string' || !countPattern(text)) return locator;
|
|
236
|
+
for (const method of ACTIONS) {
|
|
237
|
+
const real = locator[method];
|
|
238
|
+
if (typeof real !== 'function') continue;
|
|
239
|
+
locator[method] = function () {
|
|
240
|
+
return textAct(locator, real, method, Array.prototype.slice.call(arguments), text);
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
return locator;
|
|
244
|
+
};
|
|
245
|
+
|
|
206
246
|
page.getByRole = function (role, roleOptions) {
|
|
207
247
|
const locator = byRole(role, roleOptions);
|
|
208
248
|
const name = roleOptions && typeof roleOptions.name === 'string' ? roleOptions.name : null;
|
|
@@ -236,8 +276,24 @@ function mergeMemory(previous, learned) {
|
|
|
236
276
|
return out;
|
|
237
277
|
}
|
|
238
278
|
|
|
279
|
+
/**
|
|
280
|
+
* The same words with any number in them: a regular expression for text whose
|
|
281
|
+
* numbers are a count, or null when the words without their numbers are too
|
|
282
|
+
* few to say which text it is (at least four letters must be left).
|
|
283
|
+
*/
|
|
284
|
+
function countPattern(text) {
|
|
285
|
+
const value = String(text == null ? '' : text);
|
|
286
|
+
if (!/\d/.test(value)) return null;
|
|
287
|
+
if (value.replace(/[^\p{L}]/gu, '').length < 4) return null;
|
|
288
|
+
const parts = value.split(/\d+/).map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/\s+/g, '\\s*'));
|
|
289
|
+
return new RegExp(parts.join('\\s*\\d+\\s*'), 'i');
|
|
290
|
+
}
|
|
291
|
+
|
|
239
292
|
/** The report line, shared by the terminal and the history. */
|
|
240
293
|
function describeRename(entry) {
|
|
294
|
+
if (entry.role === 'text' && entry.counted) {
|
|
295
|
+
return 'The text "' + entry.was + '" now reads "' + entry.now + '" - only its number changed, so I clicked it and carried on.';
|
|
296
|
+
}
|
|
241
297
|
const what = entry.role === 'link' ? 'link' : entry.role === 'button' ? 'button' : entry.role;
|
|
242
298
|
return 'The ' + what + ' "' + entry.was + '" is now called "' + entry.now + '" - I used "' + entry.now + '" and carried on.';
|
|
243
299
|
}
|
|
@@ -246,6 +302,7 @@ module.exports = {
|
|
|
246
302
|
PROBE_MS: PROBE_MS,
|
|
247
303
|
namesByRole: namesByRole,
|
|
248
304
|
decideRename: decideRename,
|
|
305
|
+
countPattern: countPattern,
|
|
249
306
|
samePage: samePage,
|
|
250
307
|
pageNames: pageNames,
|
|
251
308
|
watch: watch,
|