omniqa 0.8.0 → 0.9.0
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/.tsbuildinfo +1 -1
- package/dist/auth.d.ts +17 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +29 -1
- package/dist/auth.js.map +1 -1
- package/dist/cli.js +13 -3
- package/dist/cli.js.map +1 -1
- package/dist/commands/chat.js +1 -1
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/crawl.d.ts.map +1 -1
- package/dist/commands/crawl.js +17 -5
- package/dist/commands/crawl.js.map +1 -1
- package/dist/commands/doctor.d.ts +16 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +124 -4
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/generate.js +1 -1
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +137 -45
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/knowledge.d.ts +61 -1
- package/dist/commands/knowledge.d.ts.map +1 -1
- package/dist/commands/knowledge.js +232 -50
- package/dist/commands/knowledge.js.map +1 -1
- package/dist/commands/persist.d.ts +6 -0
- package/dist/commands/persist.d.ts.map +1 -1
- package/dist/commands/persist.js +9 -2
- package/dist/commands/persist.js.map +1 -1
- package/dist/commands/plan-add.d.ts.map +1 -1
- package/dist/commands/plan-add.js +13 -3
- package/dist/commands/plan-add.js.map +1 -1
- package/dist/commands/plan-review.d.ts +6 -2
- package/dist/commands/plan-review.d.ts.map +1 -1
- package/dist/commands/plan-review.js +16 -5
- package/dist/commands/plan-review.js.map +1 -1
- package/dist/commands/plan.d.ts +15 -0
- package/dist/commands/plan.d.ts.map +1 -1
- package/dist/commands/plan.js +100 -30
- package/dist/commands/plan.js.map +1 -1
- package/dist/commands/reindex.d.ts +1 -1
- package/dist/commands/reindex.d.ts.map +1 -1
- package/dist/commands/reindex.js +15 -1
- package/dist/commands/reindex.js.map +1 -1
- package/dist/commands/security.d.ts +2 -0
- package/dist/commands/security.d.ts.map +1 -1
- package/dist/commands/security.js +5 -1
- package/dist/commands/security.js.map +1 -1
- package/dist/commands/serve.d.ts +2 -0
- package/dist/commands/serve.d.ts.map +1 -1
- package/dist/commands/serve.js +126 -30
- package/dist/commands/serve.js.map +1 -1
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +19 -2
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/test.d.ts +0 -1
- package/dist/commands/test.d.ts.map +1 -1
- package/dist/commands/test.js +58 -5
- package/dist/commands/test.js.map +1 -1
- package/dist/commands/write.d.ts +8 -2
- package/dist/commands/write.d.ts.map +1 -1
- package/dist/commands/write.js +76 -19
- package/dist/commands/write.js.map +1 -1
- package/dist/devices.d.ts +3 -1
- package/dist/devices.d.ts.map +1 -1
- package/dist/devices.js +5 -3
- package/dist/devices.js.map +1 -1
- package/dist/fixer.d.ts.map +1 -1
- package/dist/fixer.js +19 -9
- package/dist/fixer.js.map +1 -1
- package/dist/jobs.d.ts +6 -0
- package/dist/jobs.d.ts.map +1 -1
- package/dist/jobs.js +10 -1
- package/dist/jobs.js.map +1 -1
- package/dist/mcp/server.d.ts +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +1 -1
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/session.d.ts.map +1 -1
- package/dist/mcp/session.js +7 -7
- package/dist/mcp/session.js.map +1 -1
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +8 -6
- package/dist/mcp/tools.js.map +1 -1
- package/dist/page.d.ts +1 -1
- package/dist/page.d.ts.map +1 -1
- package/dist/page.js +11 -0
- package/dist/page.js.map +1 -1
- package/dist/planner.d.ts.map +1 -1
- package/dist/planner.js +8 -4
- package/dist/planner.js.map +1 -1
- package/dist/prompt.d.ts +7 -1
- package/dist/prompt.d.ts.map +1 -1
- package/dist/prompt.js +23 -4
- package/dist/prompt.js.map +1 -1
- package/dist/qa.d.ts +7 -0
- package/dist/qa.d.ts.map +1 -1
- package/dist/qa.js +33 -9
- package/dist/qa.js.map +1 -1
- package/dist/runner.d.ts +7 -2
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +28 -8
- package/dist/runner.js.map +1 -1
- package/dist/security-checks.d.ts +46 -4
- package/dist/security-checks.d.ts.map +1 -1
- package/dist/security-checks.js +114 -39
- package/dist/security-checks.js.map +1 -1
- package/dist/security-gates.d.ts +52 -4
- package/dist/security-gates.d.ts.map +1 -1
- package/dist/security-gates.js +115 -12
- package/dist/security-gates.js.map +1 -1
- package/dist/security-report.d.ts +22 -0
- package/dist/security-report.d.ts.map +1 -1
- package/dist/security-report.js +22 -4
- package/dist/security-report.js.map +1 -1
- package/dist/security-request.d.ts +27 -4
- package/dist/security-request.d.ts.map +1 -1
- package/dist/security-request.js +56 -14
- package/dist/security-request.js.map +1 -1
- package/dist/security-research.d.ts +2 -1
- package/dist/security-research.d.ts.map +1 -1
- package/dist/security-research.js +33 -15
- package/dist/security-research.js.map +1 -1
- package/dist/security-scan.d.ts +7 -7
- package/dist/security-scan.d.ts.map +1 -1
- package/dist/security-scan.js +66 -18
- package/dist/security-scan.js.map +1 -1
- package/dist/security.d.ts +15 -3
- package/dist/security.d.ts.map +1 -1
- package/dist/security.js +180 -36
- package/dist/security.js.map +1 -1
- package/dist/sync.d.ts +55 -3
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +403 -54
- package/dist/sync.js.map +1 -1
- package/dist/test.d.ts +19 -2
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +143 -27
- package/dist/test.js.map +1 -1
- package/dist/writer.d.ts +29 -10
- package/dist/writer.d.ts.map +1 -1
- package/dist/writer.js +116 -36
- package/dist/writer.js.map +1 -1
- package/package.json +7 -7
- package/skills/knowledge.md +1 -1
- package/skills/onboarding.md +0 -5
package/dist/test.js
CHANGED
|
@@ -4,14 +4,14 @@ import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmdir
|
|
|
4
4
|
import { dirname, join, relative } from "node:path";
|
|
5
5
|
import { after, describe as nodeDescribe, test as nodeTest } from "node:test";
|
|
6
6
|
import { requestApi } from "@omniqa/browser";
|
|
7
|
-
import { createAgent, createMemory, createModels, fileKind, KIND_TAG, modelFor, openIndex, openRecording, parseProduct, PRODUCT_FILE, recordingPath, redactor, SPEC_FILE } from "@omniqa/core";
|
|
7
|
+
import { createAgent, createMemory, createModels, fileKind, KIND_TAG, modelFor, openIndex, openRecording, parseProduct, PRODUCT_FILE, recordingPath, redactor, SPEC_FILE, productSecrets } from "@omniqa/core";
|
|
8
8
|
import { browserOf, connectDevice, createDeviceEngine } from "@omniqa/device";
|
|
9
|
-
import { createWebEngine, expectLogin, hostPatterns, pageApi, requestRoute, seedContext, sendForm, startInterceptor } from "@omniqa/web";
|
|
10
|
-
import { parseSignUp, quoteAnswer, signUpRefusal, signUpWith, tearDown } from "./auth.js";
|
|
9
|
+
import { contextOptionsFor, createWebEngine, expectLogin, hostPatterns, linkedPatterns, pageApi, pressKeptBack, requestRoute, seedContext, sendForm, startInterceptor } from "@omniqa/web";
|
|
10
|
+
import { parseSignUp, quoteAnswer, readOnlyApi, signInRequests, signUpRefusal, signUpWith, tearDown } from "./auth.js";
|
|
11
11
|
import { browserFor, grepPattern, posix, webContextOptions } from "./devices.js";
|
|
12
|
-
import { checkNamed, CHECKS, NotHeld, Refused, SIGN_OUT } from "./security-checks.js";
|
|
13
|
-
import { CHECK_REQUESTS, gate } from "./security-gates.js";
|
|
14
|
-
import { ANTI_FORGERY, parametersOf, parseRequest, renderRequest, setCookies, withHeader } from "./security-request.js";
|
|
12
|
+
import { checkNamed, CHECKS, loginPagesOf, NotHeld, redirectsElsewhere, Refused, sameAnswer, SIGN_OUT } from "./security-checks.js";
|
|
13
|
+
import { CHECK_REQUESTS, gate, outgoing, sameCookie } from "./security-gates.js";
|
|
14
|
+
import { ANTI_FORGERY, cookiePairs, cookiesOf, guestGet, headerValues, parametersOf, parseRequest, renderRequest, setCookies, withCookies, withHeader } from "./security-request.js";
|
|
15
15
|
/** OMNIQA_RUN: the options file omniqa test writes for every test process (product.yaml and instructions.md ride in it, more than one environment string may hold). */
|
|
16
16
|
const run = process.env.OMNIQA_RUN === undefined ? undefined : JSON.parse(readFileSync(process.env.OMNIQA_RUN, "utf8"));
|
|
17
17
|
const options = () => {
|
|
@@ -76,7 +76,7 @@ function secretsRedactor(omniqa) {
|
|
|
76
76
|
const names = [...Object.values(omniqa.models).map((m) => m.apiKeyEnv), ...[...(omniqa.product ?? "").matchAll(/\$([A-Za-z_]\w*)/g)].map((m) => m[1])];
|
|
77
77
|
let accounts = [];
|
|
78
78
|
try {
|
|
79
|
-
accounts =
|
|
79
|
+
accounts = productSecrets(parseProduct(omniqa.product ?? "", process.env));
|
|
80
80
|
}
|
|
81
81
|
catch {
|
|
82
82
|
// an unset $VAR: its value is in no page either
|
|
@@ -118,16 +118,18 @@ function appFor(device, environment, project) {
|
|
|
118
118
|
async function openContext(s) {
|
|
119
119
|
const o = options();
|
|
120
120
|
const omniqa = o.omniqa;
|
|
121
|
+
const environment = omniqa.environment === undefined || omniqa.product === undefined ? undefined : parseProduct(omniqa.product, process.env).environments[omniqa.environment.name];
|
|
121
122
|
const context = await (await s.get("browser")).newContext({
|
|
122
123
|
...(urlFor(omniqa) === undefined ? {} : { baseURL: urlFor(omniqa) }),
|
|
123
124
|
...webContextOptions(o),
|
|
124
125
|
...uses.context,
|
|
125
126
|
testIdAttribute: omniqa.testIdAttribute,
|
|
127
|
+
// The environment's HTTP sign-in and its own certificate, where it says so: what a test's own `use` cannot take away.
|
|
128
|
+
...(environment === undefined || urlFor(omniqa) === undefined ? {} : contextOptionsFor(environment, urlFor(omniqa))),
|
|
126
129
|
});
|
|
127
130
|
// Playwright Test's defaults: an action or a navigation waits as long as the test may; the deadline closes the context and settles it.
|
|
128
131
|
context.setDefaultTimeout(0);
|
|
129
132
|
context.setDefaultNavigationTimeout(0);
|
|
130
|
-
const environment = omniqa.environment === undefined || omniqa.product === undefined ? undefined : parseProduct(omniqa.product, process.env).environments[omniqa.environment.name];
|
|
131
133
|
if (environment !== undefined && omniqa.environment !== undefined)
|
|
132
134
|
await seedContext(context, environment, urlFor(omniqa));
|
|
133
135
|
return context;
|
|
@@ -151,6 +153,11 @@ function runnable(name, target) {
|
|
|
151
153
|
}
|
|
152
154
|
/** The headers a session rides in: what `replay({ as })` swaps for the other account's. */
|
|
153
155
|
const sessionHeader = (name) => ["cookie", "authorization"].includes(name.toLowerCase()) || ANTI_FORGERY.test(name);
|
|
156
|
+
/** What a request was recorded with, as the gate of a request that was kept back takes it: its Cookie and its Authorization headers, each as one text. */
|
|
157
|
+
function recordedWith(was) {
|
|
158
|
+
const [cookie, authorization] = [headerValues(was, "cookie").join("; "), headerValues(was, "authorization").join(", ")];
|
|
159
|
+
return { ...(cookie === "" ? {} : { cookie }), ...(authorization === "" ? {} : { authorization }) };
|
|
160
|
+
}
|
|
154
161
|
const FIXTURES = {
|
|
155
162
|
omniqa: async () => options().omniqa,
|
|
156
163
|
models: async () => uses.models,
|
|
@@ -161,7 +168,7 @@ const FIXTURES = {
|
|
|
161
168
|
browser ??= (async () => {
|
|
162
169
|
// A security file's browser is behind the sidecar, which decrypts the environment's own hosts and no other.
|
|
163
170
|
if (securityFile)
|
|
164
|
-
sidecar ??= startInterceptor({ hosts: url === undefined ? [] : hostPatterns(url), env: process.env });
|
|
171
|
+
sidecar ??= startInterceptor({ hosts: url === undefined ? [] : [...hostPatterns(url), ...linkedPatterns(o.omniqa.environment?.linked ?? [])], env: process.env, ownCertificate: o.omniqa.environment !== undefined && o.omniqa.product !== undefined && parseProduct(o.omniqa.product, process.env).environments[o.omniqa.environment.name]?.ownCertificate === true });
|
|
165
172
|
const b = await browserFor({ android: o.android, descriptor: o.descriptor, headless: !o.headed, url, ...(sidecar === undefined ? {} : { args: (await sidecar).args }) });
|
|
166
173
|
pageUrl = b.url;
|
|
167
174
|
return b.browser;
|
|
@@ -196,7 +203,7 @@ const FIXTURES = {
|
|
|
196
203
|
throw new Error(`omniqa: account ${JSON.stringify(account)} is not in product.yaml`);
|
|
197
204
|
const page = await s.get("page");
|
|
198
205
|
try {
|
|
199
|
-
return await expectLogin(page, urlFor(omniqa), product.crawl.loginPath, fields, account, o);
|
|
206
|
+
return await expectLogin(page, urlFor(omniqa), product.crawl.loginPath, fields, account, { ...o, ...(product.crawl.signedIn === undefined ? {} : { signedIn: product.crawl.signedIn }) });
|
|
200
207
|
}
|
|
201
208
|
catch (err) {
|
|
202
209
|
throw new Error(`omniqa: ${err.message}`, { cause: err });
|
|
@@ -246,17 +253,20 @@ const FIXTURES = {
|
|
|
246
253
|
api: async (s, info) => {
|
|
247
254
|
const omniqa = options().omniqa;
|
|
248
255
|
const baseURL = omniqa.environment?.url;
|
|
249
|
-
const
|
|
256
|
+
const environment = omniqa.environment === undefined || omniqa.product === undefined ? undefined : parseProduct(omniqa.product, process.env).environments[omniqa.environment.name];
|
|
257
|
+
const mode = environment?.api.mode ?? "request";
|
|
258
|
+
// Where the environment takes no change, neither does the fixture: its own sign-in aside.
|
|
259
|
+
const gated = (api) => omniqa.environment?.mutations === false ? readOnlyApi(api, omniqa.environment.name, signInRequests(((file) => (existsSync(file) ? readFileSync(file, "utf8") : undefined))(join(options().testDir, "api", "_auth.ts")))) : api;
|
|
250
260
|
if (mode === "page" && baseURL !== undefined) {
|
|
251
261
|
// A host behind bot management or an Origin check answers browsers only: open the url once, then fetch from inside that page.
|
|
252
262
|
const page = await s.get("page");
|
|
253
263
|
const pageBase = urlFor(omniqa);
|
|
254
264
|
await page.goto(pageBase);
|
|
255
|
-
const api = pageApi(page, pageBase);
|
|
265
|
+
const api = gated(pageApi(page, pageBase));
|
|
256
266
|
s.cleanup(async () => reportTeardowns(info, await tearDown(api)));
|
|
257
267
|
return api;
|
|
258
268
|
}
|
|
259
|
-
const api = requestApi(baseURL);
|
|
269
|
+
const api = gated(requestApi(baseURL, environment?.httpAuth));
|
|
260
270
|
s.cleanup(async () => {
|
|
261
271
|
try {
|
|
262
272
|
// apiSignUp's throwaway accounts go before the context does.
|
|
@@ -276,18 +286,54 @@ const FIXTURES = {
|
|
|
276
286
|
// A test reads its own traffic: what an earlier test of the file raised is forgotten before this one's first page.
|
|
277
287
|
await interceptor.clear();
|
|
278
288
|
const omniqa = options().omniqa;
|
|
289
|
+
/** The requests a press of this test is known by (`keepBack`), by their flow. */
|
|
290
|
+
const keptBack = new Set();
|
|
291
|
+
/** The requests that were kept back before the test signed its account out (`signOut`). */
|
|
292
|
+
const signedOut = new Set();
|
|
293
|
+
/**
|
|
294
|
+
* Whether a request of the capture was kept back: the proxy answered it itself, and the product never got it. The one
|
|
295
|
+
* a press is known by, and whatever else the page sent under that press (a log line beside its action): each of them
|
|
296
|
+
* never left. Its status and its answer in the capture are the proxy's own, so nothing here reads them, and it leaves
|
|
297
|
+
* only as another visitor (the gate, which `send` hands what it was recorded with).
|
|
298
|
+
*/
|
|
299
|
+
const kept = (id) => keptBack.has(id) || interceptor.flows().some((flow) => flow.id === id && flow.ended);
|
|
279
300
|
/** The one way a request of the test's own leaves: the gates on what would be sent, then the repeater. `text` undefined sends the captured request as it was. `id` is the copy's flow. */
|
|
280
301
|
const send = async (captured, was, text, label) => {
|
|
281
302
|
if (omniqa.environment === undefined)
|
|
282
303
|
throw new Error("omniqa: a security request needs .omniqa/product.yaml in the project; run omniqa init");
|
|
283
304
|
const going = text ?? was;
|
|
284
305
|
const url = urlOf(captured, going);
|
|
285
|
-
const refusal = gate(omniqa.environment, { method: going.method, url: url.href, body: going.body, headers: going.headers.
|
|
306
|
+
const refusal = gate(omniqa.environment, { method: going.method, url: url.href, body: going.body, headers: going.headers }, interceptor.sent(), undefined, kept(captured.id) ? { ...recordedWith(was), signedOut: signedOut.has(captured.id) } : undefined);
|
|
286
307
|
if (refusal !== undefined)
|
|
287
308
|
throw new Refused(`omniqa: ${refusal}`);
|
|
288
|
-
|
|
289
|
-
|
|
309
|
+
// What leaves is what the gate read: the target is the judged url's own, never the text it was written as.
|
|
310
|
+
let raw;
|
|
311
|
+
if (text !== undefined) {
|
|
312
|
+
try {
|
|
313
|
+
raw = renderRequest({ ...text, target: outgoing(captured, text.target).target });
|
|
314
|
+
}
|
|
315
|
+
catch (err) {
|
|
316
|
+
throw new Refused(`omniqa: ${err.message}`, { cause: err });
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
const answer = await interceptor.replay(captured.id, { ...(raw === undefined ? {} : { raw }), label });
|
|
320
|
+
const to = answer.location === undefined ? undefined : URL.parse(answer.location, url)?.href;
|
|
321
|
+
return { id: answer.id, status: answer.status, ...(answer.location === undefined ? {} : { location: pointsTo(answer.location, url) }), ...(to === undefined ? {} : { to }) };
|
|
290
322
|
};
|
|
323
|
+
/**
|
|
324
|
+
* Where the login page itself sends a guest on to (loginPagesOf): asked once a test, and only when a reply is a redirect
|
|
325
|
+
* elsewhere than the login path. Each hop is a request of the test's own through the gates: a visitor's plain GET for
|
|
326
|
+
* that address (guestGet), never to another origin than the product's.
|
|
327
|
+
*/
|
|
328
|
+
let loginPages;
|
|
329
|
+
const loginPagesFrom = (captured, was, loginPath, by) => (loginPages ??= loginPagesOf(async (target) => {
|
|
330
|
+
const at = urlOf(captured, was);
|
|
331
|
+
const going = guestGet(was, target, at);
|
|
332
|
+
if (going === undefined)
|
|
333
|
+
throw new Refused(`omniqa: ${target.split("?")[0]} is not asked for: it is another origin's`);
|
|
334
|
+
const { status, location, to } = await send(captured, was, going, `${by}: where the login page leads (${routeOf(new URL(going.target, at).pathname)})`);
|
|
335
|
+
return { status, ...(location === undefined ? {} : { location }), ...(to === undefined ? {} : { next: to }) };
|
|
336
|
+
}, loginPath));
|
|
291
337
|
/** The requests of this test's capture that are no asset, read a few at a time: each answer comes on Interceptor's next tick. */
|
|
292
338
|
const eachFlow = async (pick, read) => {
|
|
293
339
|
const flows = interceptor.flows().filter((flow) => !flow.asset && pick(flow));
|
|
@@ -310,7 +356,7 @@ const FIXTURES = {
|
|
|
310
356
|
s.cleanup(() => context.close());
|
|
311
357
|
const page = await context.newPage();
|
|
312
358
|
try {
|
|
313
|
-
await expectLogin(page, urlFor(omniqa), product.crawl.loginPath, fields, account);
|
|
359
|
+
await expectLogin(page, urlFor(omniqa), product.crawl.loginPath, fields, account, product.crawl.signedIn === undefined ? {} : { signedIn: product.crawl.signedIn });
|
|
314
360
|
}
|
|
315
361
|
catch (err) {
|
|
316
362
|
throw new Error(`omniqa: ${err.message}`, { cause: err });
|
|
@@ -357,6 +403,10 @@ const FIXTURES = {
|
|
|
357
403
|
};
|
|
358
404
|
/** Runs a basic check on a request of the capture: what the check works with, and how its outcome is said. */
|
|
359
405
|
const runOn = async (captured, name, check) => {
|
|
406
|
+
// A request that was kept back gets the checks that send it as somebody who must be refused, and no other: any other
|
|
407
|
+
// would send it as the account it came from, and what it does would be done.
|
|
408
|
+
if (kept(captured.id) && check.keptBack !== true)
|
|
409
|
+
throw new Refused(`omniqa: ${name} is not sent: a request that was kept back leaves only as another visitor`);
|
|
360
410
|
const raw = await interceptor.raw(captured.id);
|
|
361
411
|
if (raw === undefined)
|
|
362
412
|
throw new Error(`omniqa: ${name} cannot be re-sent: Interceptor holds no editable text of it (streamed, or over 5 MB)`);
|
|
@@ -365,6 +415,9 @@ const FIXTURES = {
|
|
|
365
415
|
const passwords = Object.values(product.accounts).flatMap((fields) => (fields.password === undefined ? [] : [fields.password]));
|
|
366
416
|
/** An answer of the capture. One Interceptor does not hand over (it no longer holds the flow, or did not answer in time) is no empty answer: a check that read it as one would compare with nothing. */
|
|
367
417
|
const answerOf = async (id) => {
|
|
418
|
+
// What the capture has for a request that was kept back is the proxy's own answer: the product never answered it, and no check reads that as its answer.
|
|
419
|
+
if (kept(id))
|
|
420
|
+
throw new Error(`${id === captured.id ? name : "a request of this test"} was kept back: the product never answered it`);
|
|
368
421
|
const read = await interceptor.answer(id);
|
|
369
422
|
if (read === undefined)
|
|
370
423
|
throw new Error(`an answer to ${name} could not be read from Interceptor`);
|
|
@@ -395,9 +448,12 @@ const FIXTURES = {
|
|
|
395
448
|
console.log(message);
|
|
396
449
|
},
|
|
397
450
|
loginPath: product.crawl.loginPath,
|
|
451
|
+
loginPages: () => loginPagesFrom(captured, was, product.crawl.loginPath, check.name),
|
|
452
|
+
...(kept(captured.id) ? { keptBack: true } : {}),
|
|
398
453
|
accounts: product.accounts,
|
|
399
|
-
// How this test's answers set each cookie: the sign-in is among them, since the capture began before it.
|
|
400
|
-
|
|
454
|
+
// How this test's answers set each cookie: the sign-in is among them, since the capture began before it. The product's
|
|
455
|
+
// answers: what the proxy answered itself under a press set no cookie of the product's.
|
|
456
|
+
cookieFlags: async () => Object.fromEntries((await eachFlow((flow) => flow.status !== undefined && !flow.ended, async (id) => setCookies((await answerOf(id)).headers))).flat().map((cookie) => [cookie.name, cookie.flags ?? {}])),
|
|
401
457
|
// The first request of the capture to carry an account's password is a sign-in; a later one that carries it asks for the password again.
|
|
402
458
|
signsIn: async () => {
|
|
403
459
|
const held = parametersOf(was).find((p) => p.in !== "query" && passwords.includes(p.value))?.value;
|
|
@@ -443,13 +499,40 @@ const FIXTURES = {
|
|
|
443
499
|
throw new Error(`omniqa: ${name} carries no Cookie and no Authorization header: its session rides somewhere a replay cannot swap for ${o.as}'s`);
|
|
444
500
|
if (o.as !== undefined)
|
|
445
501
|
text = await asAccount(o.as, captured, name, text);
|
|
502
|
+
if (o.as !== undefined && kept(captured.id)) {
|
|
503
|
+
// No cookie a request that was kept back was recorded with leaves on it (the gate): one both accounts hold (a
|
|
504
|
+
// banner's, a language's) is left off the other account's request. Where that leaves no session on it at all, the
|
|
505
|
+
// other account's cookies are the recorded ones, and it would be answered as a guest is.
|
|
506
|
+
// ponytail: a product that turns a request down for lacking such a cookie is read as refusing the other account. Tell
|
|
507
|
+
// the gate which cookies are the session's (security.md › Sessions names them) to send the rest along.
|
|
508
|
+
// ponytail: another account is told from the recorded one by its cookies alone. An account of product.yaml that is the
|
|
509
|
+
// recorded one under another name, where every sign-in gets a session of its own, passes for another visitor. Keep
|
|
510
|
+
// which account the test's page signed in as (the logIn fixture knows) to refuse that one by name.
|
|
511
|
+
const theirs = cookiesOf(text).filter((cookie) => !cookiesOf(was).some((recorded) => sameCookie(cookie, recorded)));
|
|
512
|
+
if (theirs.length === 0 && headerValues(text, "authorization").length === 0)
|
|
513
|
+
throw new Error(`omniqa: ${name} cannot be re-sent as ${o.as}: every cookie of ${o.as}'s is one the request was recorded with, and a request that was kept back leaves with none of those`);
|
|
514
|
+
text = withCookies(text, theirs);
|
|
515
|
+
}
|
|
446
516
|
for (const [header, value] of Object.entries(o.headers ?? {}))
|
|
447
517
|
text = withHeader(text, header, value);
|
|
448
518
|
const edited = own || o.as !== undefined || text.headers.length !== was.headers.length;
|
|
449
519
|
const { status, location } = await send(captured, was, edited ? text : undefined, [...(own ? [`${text.method} ${routeOf(URL.parse(text.target, "http://request")?.pathname ?? text.target)}`] : []), ...(o.as === undefined ? [] : [`as ${o.as}`]), ...(dropped.length === 0 ? [] : [`without ${dropped.join(", ")}`])].join(", ") || "as it was");
|
|
450
520
|
// omniqa write runs a check once to learn what the product answers: that run says it, and the test is written with it.
|
|
451
|
-
if (process.env.OMNIQA_SECURITY_ACCEPT !== undefined)
|
|
521
|
+
if (process.env.OMNIQA_SECURITY_ACCEPT !== undefined) {
|
|
452
522
|
appendFileSync(process.env.OMNIQA_SECURITY_ACCEPT, `replay ${status}${location === undefined ? "" : ` ${location}`}\n`);
|
|
523
|
+
// A redirect elsewhere than the login path is a refusal when the login page itself leads there: the writer is told where it leads.
|
|
524
|
+
// Not for the redirect the page's own request was answered with, which is where the product sends whoever it lets in.
|
|
525
|
+
const loginPath = omniqa.product === undefined ? undefined : parseProduct(omniqa.product, process.env).crawl.loginPath;
|
|
526
|
+
const reply = { status, ...(location === undefined ? {} : { location }) };
|
|
527
|
+
if (loginPath !== undefined && redirectsElsewhere(reply, loginPath)) {
|
|
528
|
+
// A request that was kept back has no answer of the product's: the one in the capture is the proxy's own.
|
|
529
|
+
const first = kept(captured.id) ? undefined : await interceptor.answer(captured.id);
|
|
530
|
+
const firstLocation = first?.headers.find(([header]) => header.toLowerCase() === "location")?.[1];
|
|
531
|
+
const answered = first === undefined ? undefined : { status: first.status, ...(firstLocation === undefined ? {} : { location: pointsTo(firstLocation, urlOf(captured, was)) }) };
|
|
532
|
+
if (answered === undefined || !sameAnswer(reply, answered))
|
|
533
|
+
appendFileSync(process.env.OMNIQA_SECURITY_ACCEPT, (await loginPagesFrom(captured, was, loginPath, "replay")).map((page) => `login ${page}\n`).join(""));
|
|
534
|
+
}
|
|
535
|
+
}
|
|
453
536
|
return { status, ...(location === undefined ? {} : { location }) };
|
|
454
537
|
},
|
|
455
538
|
async check(check) {
|
|
@@ -463,7 +546,8 @@ const FIXTURES = {
|
|
|
463
546
|
// Whatever passed the proxy before the page was there is known once Interceptor has answered anything.
|
|
464
547
|
await interceptor.findings();
|
|
465
548
|
// The request for the page's own address; where a script put another address in the browser (a single-page product's router), the newest page the test was served.
|
|
466
|
-
|
|
549
|
+
// What the proxy answered itself under a press is no page the product served.
|
|
550
|
+
const asked = at === null ? [] : interceptor.flows().filter((flow) => !flow.asset && !flow.ended && flow.method === "GET" && flow.host === at.hostname);
|
|
467
551
|
const document = asked.findLast((flow) => flow.path === at?.pathname) ?? asked.findLast((flow) => flow.page);
|
|
468
552
|
if (document === undefined)
|
|
469
553
|
throw new Error("omniqa: open a page first: a check on the site asks from a request the page made");
|
|
@@ -496,8 +580,21 @@ const FIXTURES = {
|
|
|
496
580
|
await page.waitForLoadState("networkidle", { timeout: 5_000 }).catch(() => undefined);
|
|
497
581
|
// A click that left every cookie as it was signed nobody out (a dialog to confirm, a session kept elsewhere): a request
|
|
498
582
|
// replayed after it would be answered as before, and that would read as a session the product does not end.
|
|
499
|
-
|
|
583
|
+
const since = await jar();
|
|
584
|
+
if (since === before)
|
|
500
585
|
throw new Error(`omniqa: the sign-out control on ${where} was used and no cookie changed: nothing shows that a session ended, so what a request is answered after it proves nothing`);
|
|
586
|
+
// What was kept back before it asks with the session that just ended when it is sent as it was: the gate lets it out from
|
|
587
|
+
// here on, where a cookie it was recorded with is gone from the browser or has another value. One whose cookies the browser
|
|
588
|
+
// all still holds had no session of its own ended by this click, and stays where it was.
|
|
589
|
+
// ponytail: which of its cookies holds the session is not known. A click that changed another cookie of the request and
|
|
590
|
+
// ended no session lets a request that was kept back do what it does, as the account itself. Ask that the session's own
|
|
591
|
+
// cookies are gone or changed (security.md › Sessions names them) if a product's sign-out does that.
|
|
592
|
+
const held = cookiePairs([since]);
|
|
593
|
+
for (const id of new Set([...keptBack, ...interceptor.flows().filter((flow) => flow.ended).map((flow) => flow.id)])) {
|
|
594
|
+
const raw = await interceptor.raw(id);
|
|
595
|
+
if (raw !== undefined && cookiesOf(parseRequest(raw)).some((cookie) => !held.some((now) => sameCookie(cookie, now))))
|
|
596
|
+
signedOut.add(id);
|
|
597
|
+
}
|
|
501
598
|
},
|
|
502
599
|
async submit(button) {
|
|
503
600
|
if (omniqa.environment === undefined)
|
|
@@ -507,6 +604,18 @@ const FIXTURES = {
|
|
|
507
604
|
if (why !== undefined)
|
|
508
605
|
throw new Error(`omniqa: the form ${JSON.stringify(button)} on ${routeOf(new URL(page.url()).pathname)} is not sent: ${why}`);
|
|
509
606
|
},
|
|
607
|
+
async keepBack(button) {
|
|
608
|
+
if (omniqa.environment === undefined)
|
|
609
|
+
throw new Error("omniqa: security.keepBack needs .omniqa/product.yaml in the project; run omniqa init");
|
|
610
|
+
const page = await s.get("page");
|
|
611
|
+
// It rejects only where the proxy does not show its rule gone: nothing gets through then, and the test ends there.
|
|
612
|
+
const pressed = await pressKeptBack(page, button, omniqa.environment, interceptor).catch((err) => {
|
|
613
|
+
throw new Error(`omniqa: ${err.message}`, { cause: err });
|
|
614
|
+
});
|
|
615
|
+
if ("not" in pressed)
|
|
616
|
+
throw new Error(`omniqa: no request was kept back from ${JSON.stringify(button)}: ${pressed.not}`);
|
|
617
|
+
keptBack.add(pressed.kept.id);
|
|
618
|
+
},
|
|
510
619
|
async visit(path) {
|
|
511
620
|
const page = await s.get("page");
|
|
512
621
|
await page.goto(path);
|
|
@@ -561,12 +670,14 @@ const FIXTURES = {
|
|
|
561
670
|
device: omniqa.device.device,
|
|
562
671
|
// A browser app shows the environment: it opens on the url (a native app's environment url is its backend, not a screen).
|
|
563
672
|
...(browserOf(app) === undefined ? {} : { url: environment.url }),
|
|
673
|
+
// Either way the url says which hosts are the product's: navigate opens those, and the linked ones its owner switched on.
|
|
674
|
+
hosts: [...hostPatterns(environment.url), ...linkedPatterns(environment.linkedTests ?? [])],
|
|
564
675
|
});
|
|
565
676
|
}
|
|
566
677
|
const capabilities = device?.capabilities();
|
|
567
678
|
const counted = countedModels(models ?? createModels(omniqa.models), info);
|
|
568
679
|
// The page is built here, only for a web project: a device test launches no browser.
|
|
569
|
-
const engine = device ?? createWebEngine(await s.get("page"), { testIdAttribute: omniqa.testIdAttribute, rootDir: info.config.rootDir });
|
|
680
|
+
const engine = device ?? createWebEngine(await s.get("page"), { testIdAttribute: omniqa.testIdAttribute, rootDir: info.config.rootDir, baseURL: environment.url, ...(environment.linkedTests === undefined ? {} : { linkedHosts: environment.linkedTests }) });
|
|
570
681
|
const agent = createAgent({
|
|
571
682
|
engine,
|
|
572
683
|
models: counted,
|
|
@@ -821,8 +932,10 @@ async function attempts(t, title, titlePath, body, repeat) {
|
|
|
821
932
|
}
|
|
822
933
|
if (status === "passed")
|
|
823
934
|
return;
|
|
824
|
-
// The runner cancelled the test (-x): no retry on a dead signal.
|
|
825
|
-
|
|
935
|
+
// The runner cancelled the test (-x): no retry on a dead signal. And a security test is run once, whatever was asked: it
|
|
936
|
+
// is written by code, so its failure is what it found, and a second run sends every probe again (wrong passwords among
|
|
937
|
+
// them) and may end green over a hole that shows now and then.
|
|
938
|
+
if (retry >= (securityFile ? 0 : o.retries) || t.signal.aborted)
|
|
826
939
|
throw error;
|
|
827
940
|
}
|
|
828
941
|
}
|
|
@@ -858,7 +971,7 @@ function register(title, opts, body, node) {
|
|
|
858
971
|
const rel = posix(relative(o.testDir, specFile));
|
|
859
972
|
// Playwright's grep ran over the project, the file, the titles and the tags joined by spaces: --tier's `--grep @production` and the writer's `--grep "<id>: "` rely on it.
|
|
860
973
|
const text = [o.project, rel, ...titlePath, ...tags].join(" ");
|
|
861
|
-
if (o.grep !== undefined && !
|
|
974
|
+
if (o.grep !== undefined && ![o.grep].flat().every((pattern) => grepPattern(pattern).test(text)))
|
|
862
975
|
return;
|
|
863
976
|
if (o.grepInvert !== undefined && grepPattern(o.grepInvert).test(text))
|
|
864
977
|
return;
|
|
@@ -866,7 +979,10 @@ function register(title, opts, body, node) {
|
|
|
866
979
|
console.log(`[${o.project}] › ${rel} › ${titlePath.join(" › ")}`);
|
|
867
980
|
return;
|
|
868
981
|
}
|
|
869
|
-
|
|
982
|
+
// A test planned for the dev tier alone is not run on a production-tier environment, whatever flags started the run:
|
|
983
|
+
// --tier production leaves it out, and --env <a production environment> alone ran it there, the ones that change data too.
|
|
984
|
+
const offTier = o.omniqa.environment?.tier === "production" && tags.includes("@dev") && !tags.includes("@production") ? `planned for the dev tier alone: not run on ${o.omniqa.environment.name}, a production-tier environment` : undefined;
|
|
985
|
+
const skip = uses.skip?.reason ?? node.skip ?? offTier ?? securitySkip(o);
|
|
870
986
|
const only = node.only === undefined ? {} : { only: node.only };
|
|
871
987
|
// No node timeout: the attempts' deadline bounds every phase (test.setTimeout moves it), so a stuck action settles when the context closes.
|
|
872
988
|
for (let i = 0; i < o.repeatEach; i++)
|