@validate.qa/runner 1.0.100 → 1.0.101

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.
@@ -1,293 +1,13 @@
1
1
  import {
2
- require_run_write_guard
3
- } from "./chunk-2XD63NU5.mjs";
2
+ require_run_write_guard_preload
3
+ } from "./chunk-2OKZY3WN.mjs";
4
+ import "./chunk-BBTK6OX6.mjs";
5
+ import "./chunk-SN3PN4G4.mjs";
6
+ import "./chunk-IGXGSDE3.mjs";
4
7
  import {
5
- require_survey_network_guard
6
- } from "./chunk-GIIIVO2W.mjs";
7
- import "./chunk-MBKGTELT.mjs";
8
- import {
9
- __commonJS,
10
- __require,
11
8
  __toESM
12
9
  } from "./chunk-WQXBGQU4.mjs";
13
10
 
14
- // ../runner-core/dist/services/run-write-guard-preload.js
15
- var require_run_write_guard_preload = __commonJS({
16
- "../runner-core/dist/services/run-write-guard-preload.js"(exports) {
17
- "use strict";
18
- Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.VERIFIED_PLAYWRIGHT_CORE = exports.installRunWriteGuard = exports.installNodeFetchGuard = exports.clearRunWriteRelay = exports.addRunWriteBrokerToken = exports.addRunWriteAuthHandler = void 0;
20
- exports.describeBuiltRequest = describeBuiltRequest;
21
- exports.installHttpGuard = installHttpGuard;
22
- exports.installPlaywrightContextGuard = installPlaywrightContextGuard;
23
- exports.startRunWriteGuardPreload = startRunWriteGuardPreload;
24
- var node_module_1 = __require("module");
25
- var node_path_1 = __require("path");
26
- var survey_network_guard_js_1 = require_survey_network_guard();
27
- var run_write_guard_js_1 = require_run_write_guard();
28
- var run_write_guard_js_2 = require_run_write_guard();
29
- Object.defineProperty(exports, "addRunWriteAuthHandler", { enumerable: true, get: function() {
30
- return run_write_guard_js_2.addRunWriteAuthHandler;
31
- } });
32
- Object.defineProperty(exports, "addRunWriteBrokerToken", { enumerable: true, get: function() {
33
- return run_write_guard_js_2.addRunWriteBrokerToken;
34
- } });
35
- Object.defineProperty(exports, "clearRunWriteRelay", { enumerable: true, get: function() {
36
- return run_write_guard_js_2.clearRunWriteRelay;
37
- } });
38
- Object.defineProperty(exports, "installNodeFetchGuard", { enumerable: true, get: function() {
39
- return run_write_guard_js_2.installNodeFetchGuard;
40
- } });
41
- Object.defineProperty(exports, "installRunWriteGuard", { enumerable: true, get: function() {
42
- return run_write_guard_js_2.installRunWriteGuard;
43
- } });
44
- var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
45
- var MAX_DECIDED_BODY_BYTES = 1024 * 1024;
46
- function describeBuiltRequest(req) {
47
- const method = typeof req.method === "string" && req.method ? req.method.toUpperCase() : "GET";
48
- const protocol = req.protocol === "https:" ? "https:" : "http:";
49
- const path = typeof req.path === "string" && req.path.startsWith("/") ? req.path : null;
50
- if (path === null)
51
- throw new Error("unusable request path");
52
- if (typeof req.socketPath === "string" && req.socketPath) {
53
- return { method, url: `${protocol}//unix-socket.invalid${path}` };
54
- }
55
- if (typeof req.host !== "string" || !req.host)
56
- throw new Error("unusable request host");
57
- const host = req.host.includes(":") && !req.host.startsWith("[") ? `[${req.host}]` : req.host;
58
- return { method, url: new URL(`${protocol}//${host}${path}`).href };
59
- }
60
- function headerString(value) {
61
- if (typeof value === "string")
62
- return value;
63
- if (Array.isArray(value))
64
- return value.map(String).join(", ");
65
- if (typeof value === "number")
66
- return String(value);
67
- return null;
68
- }
69
- function installHttpGuard(policy, opts, mod) {
70
- if (policy.mode === "off")
71
- return void 0;
72
- const original = mod.request;
73
- if (typeof original !== "function" || original.__vqaWriteGuarded)
74
- return void 0;
75
- const guard = new run_write_guard_js_1.RunWriteGuard(policy, opts);
76
- const wrapped = function guardedRequest(...args) {
77
- const req = original.apply(this, args);
78
- const fields = req;
79
- const connectedTo = { host: fields.host, socketPath: fields.socketPath, protocol: fields.protocol };
80
- const chunks = [];
81
- let bytes = 0;
82
- let state = "pending";
83
- const held = () => state === "held";
84
- const originalWrite = req.write.bind(req);
85
- const originalEnd = req.end.bind(req);
86
- const originalFlushHeaders = req.flushHeaders.bind(req);
87
- const take = (chunk, encoding) => {
88
- if (chunk === void 0 || chunk === null || typeof chunk === "function")
89
- return;
90
- const buf = Buffer.isBuffer(chunk) ? chunk : chunk instanceof Uint8Array ? Buffer.from(chunk) : Buffer.from(String(chunk), typeof encoding === "string" ? encoding : "utf8");
91
- chunks.push(buf);
92
- bytes += buf.length;
93
- };
94
- const decide = (withBody) => {
95
- const builtLine = typeof fields._header === "string" ? /^([A-Z]+) (\S+) HTTP\//.exec(fields._header) : null;
96
- let described = null;
97
- try {
98
- described = describeBuiltRequest({
99
- ...connectedTo,
100
- method: builtLine ? builtLine[1] : fields.method,
101
- path: builtLine ? builtLine[2] : fields.path
102
- });
103
- } catch {
104
- described = null;
105
- }
106
- const moved = fields.host !== connectedTo.host || fields.socketPath !== connectedTo.socketPath || fields.protocol !== connectedTo.protocol;
107
- let decision;
108
- try {
109
- if (!described || moved || typeof fields._header === "string" && !builtLine)
110
- throw new Error("undescribable request");
111
- const host = new URL(described.url).hostname.toLowerCase();
112
- decision = LOOPBACK_HOSTS.has(host) && !policy.appSites.includes(host) ? { action: "allow", rule: "non-http" } : guard.decide({
113
- method: described.method,
114
- url: described.url,
115
- postData: withBody ? Buffer.concat(chunks).toString("utf8") : null,
116
- contentType: headerString(req.getHeader("content-type")),
117
- amzTarget: headerString(req.getHeader("x-amz-target"))
118
- });
119
- } catch {
120
- decision = {
121
- action: "write",
122
- rule: "decision-error",
123
- record: { method: described?.method ?? "REQUEST", host: "", path: described ? (0, survey_network_guard_js_1.maskedPath)(described.url) : "(undescribable)", keys: [], rule: "decision-error" }
124
- };
125
- }
126
- if (decision.action === "write" && decision.record) {
127
- guard.note(decision.record);
128
- if (guard.holds(decision.rule)) {
129
- state = "held";
130
- chunks.length = 0;
131
- req.destroy(new Error(`blocked by the run write guard: ${decision.record.method} ${decision.record.host}${decision.record.path}`));
132
- return;
133
- }
134
- }
135
- state = "allowed";
136
- for (const buf of chunks.splice(0))
137
- originalWrite(buf);
138
- };
139
- req.write = (chunk, encoding, cb) => {
140
- const done = typeof encoding === "function" ? encoding : cb;
141
- if (state === "allowed")
142
- return originalWrite(chunk, encoding, cb);
143
- if (state === "pending") {
144
- take(chunk, encoding);
145
- if (bytes > MAX_DECIDED_BODY_BYTES)
146
- decide(false);
147
- }
148
- if (held()) {
149
- if (done)
150
- process.nextTick(done, new Error("blocked by the run write guard"));
151
- return false;
152
- }
153
- if (done)
154
- process.nextTick(done);
155
- return true;
156
- };
157
- req.flushHeaders = () => {
158
- if (state === "allowed")
159
- originalFlushHeaders();
160
- };
161
- req.end = (chunk, encoding, cb) => {
162
- if (state === "allowed")
163
- return originalEnd(chunk, encoding, cb);
164
- if (state === "held")
165
- return req;
166
- const done = [chunk, encoding, cb].find((a) => typeof a === "function");
167
- if (typeof chunk !== "function")
168
- take(chunk, typeof encoding === "function" ? void 0 : encoding);
169
- decide(bytes <= MAX_DECIDED_BODY_BYTES);
170
- if (held())
171
- return req;
172
- return originalEnd(done);
173
- };
174
- return req;
175
- };
176
- Object.defineProperty(wrapped, "__vqaWriteGuarded", { value: true });
177
- const wrappedGet = function guardedGet(...args) {
178
- const req = wrapped.apply(this, args);
179
- req.end();
180
- return req;
181
- };
182
- Object.defineProperty(wrappedGet, "__vqaWriteGuarded", { value: true });
183
- const install = (name, value) => {
184
- if (policy.mode === "block") {
185
- Object.defineProperty(mod, name, { value, writable: false, configurable: false, enumerable: true });
186
- } else {
187
- mod[name] = value;
188
- }
189
- };
190
- install("request", wrapped);
191
- if (typeof mod.get === "function")
192
- install("get", wrappedGet);
193
- return guard;
194
- }
195
- exports.VERIFIED_PLAYWRIGHT_CORE = /^1\.64\./;
196
- function installPlaywrightContextGuard(policy, opts, from = __filename) {
197
- if (policy.mode === "off")
198
- return true;
199
- let pw;
200
- let version = "";
201
- try {
202
- const req = (0, node_module_1.createRequire)(from);
203
- let base = from;
204
- try {
205
- base = (0, node_path_1.dirname)(req.resolve("@playwright/test/package.json"));
206
- } catch {
207
- }
208
- try {
209
- base = (0, node_path_1.dirname)((0, node_module_1.createRequire)(`${base}/`).resolve("playwright/package.json"));
210
- } catch {
211
- }
212
- const fromPlaywright = (0, node_module_1.createRequire)(`${base}/`);
213
- version = String(fromPlaywright("playwright-core/package.json").version ?? "");
214
- pw = fromPlaywright("playwright-core");
215
- } catch {
216
- return false;
217
- }
218
- if (!exports.VERIFIED_PLAYWRIGHT_CORE.test(version)) {
219
- if (policy.mode === "block")
220
- return false;
221
- opts.onLog?.(`[run-write-guard] observe: playwright-core ${version || "(unknown)"} is not a version the context hook was verified on`);
222
- }
223
- const add = pw?._instrumentation?.addListener;
224
- if (typeof add !== "function")
225
- return false;
226
- add.call(pw._instrumentation, {
227
- // Block mode: the context's service workers are off (design §4), whatever the test asked for.
228
- // Playwright passes the options object it builds the context from (browser.newContext,
229
- // launchPersistentContext); a context whose options cannot be set is still routed below.
230
- runBeforeCreateBrowserContext: async (options) => {
231
- if (options && typeof options === "object")
232
- Object.assign(options, (0, run_write_guard_js_1.runWriteContextOptions)(policy));
233
- },
234
- runAfterCreateBrowserContext: async (context) => {
235
- await (0, run_write_guard_js_1.installRunWriteGuard)(context, policy, opts);
236
- }
237
- });
238
- return true;
239
- }
240
- function startRunWriteGuardPreload(env = process.env) {
241
- const raw = env[run_write_guard_js_1.RUN_WRITE_POLICY_ENV];
242
- if (!raw)
243
- return [];
244
- let policy = null;
245
- try {
246
- policy = (0, run_write_guard_js_1.parseRunWritePolicy)(JSON.parse(raw));
247
- } catch {
248
- policy = null;
249
- }
250
- if (!policy) {
251
- console.log(`${run_write_guard_js_1.RUN_WRITE_UNAVAILABLE_LINE}the run write policy could not be read`);
252
- return ["policy"];
253
- }
254
- if (policy.mode === "off")
255
- return [];
256
- const names = (env[run_write_guard_js_1.RUN_WRITE_SIGNIN_VARS_ENV] ?? "").split(",").map((n) => n.trim()).filter((n) => /^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(n)).slice(0, 16);
257
- const signInSecrets = names.map((n) => env[n]).filter((v) => typeof v === "string");
258
- const opts = { onLog: (line) => console.log(line), signInSecrets };
259
- const missing = [];
260
- try {
261
- (0, run_write_guard_js_1.installNodeFetchGuard)(policy, opts);
262
- } catch {
263
- missing.push("fetch");
264
- }
265
- const nodeRequire = (0, node_module_1.createRequire)(__filename);
266
- try {
267
- installHttpGuard(policy, opts, nodeRequire("node:http"));
268
- } catch {
269
- missing.push("http");
270
- }
271
- try {
272
- installHttpGuard(policy, opts, nodeRequire("node:https"));
273
- } catch {
274
- missing.push("https");
275
- }
276
- try {
277
- (0, node_module_1.syncBuiltinESMExports)();
278
- } catch {
279
- }
280
- if (!installPlaywrightContextGuard(policy, opts))
281
- missing.push("browser contexts");
282
- for (const piece of missing)
283
- console.log(`${run_write_guard_js_1.RUN_WRITE_UNAVAILABLE_LINE}the preload could not guard ${piece}`);
284
- return missing;
285
- }
286
- if (process.env[run_write_guard_js_1.RUN_WRITE_POLICY_ENV])
287
- startRunWriteGuardPreload();
288
- }
289
- });
290
-
291
11
  // src/run-write-guard-preload.ts
292
12
  var import_run_write_guard_preload = __toESM(require_run_write_guard_preload());
293
13
  var export_addRunWriteAuthHandler = import_run_write_guard_preload.addRunWriteAuthHandler;