@testsprite/testsprite-cli 0.6.0 → 0.7.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/README.md +38 -30
- package/dist/commands/agent.js +44 -42
- package/dist/commands/doctor.d.ts +1 -1
- package/dist/commands/doctor.js +4 -7
- package/dist/commands/project.js +3 -2
- package/dist/commands/schedule.d.ts +120 -0
- package/dist/commands/schedule.js +487 -0
- package/dist/commands/test.d.ts +15 -1
- package/dist/commands/test.js +460 -256
- package/dist/commands/testlist.d.ts +88 -0
- package/dist/commands/testlist.js +747 -0
- package/dist/index.js +6 -2
- package/dist/lib/agent-targets.d.ts +13 -4
- package/dist/lib/agent-targets.js +11 -2
- package/dist/lib/conflict-reason.d.ts +30 -0
- package/dist/lib/conflict-reason.js +45 -0
- package/dist/lib/credentials.js +42 -1
- package/dist/lib/cron.d.ts +40 -0
- package/dist/lib/cron.js +190 -0
- package/dist/lib/dry-run/samples.js +177 -55
- package/dist/lib/errors.d.ts +9 -0
- package/dist/lib/errors.js +11 -0
- package/dist/lib/gh-output.d.ts +26 -1
- package/dist/lib/gh-output.js +47 -20
- package/dist/lib/http.d.ts +25 -0
- package/dist/lib/http.js +128 -2
- package/dist/lib/junit-report.d.ts +20 -2
- package/dist/lib/junit-report.js +38 -5
- package/dist/lib/proxy.d.ts +16 -0
- package/dist/lib/proxy.js +19 -1
- package/dist/lib/response-schemas.d.ts +7 -0
- package/dist/lib/response-schemas.js +23 -1
- package/dist/lib/runs.types.d.ts +8 -3
- package/dist/lib/secret-file.d.ts +15 -0
- package/dist/lib/secret-file.js +82 -0
- package/dist/lib/target-url-preflight.d.ts +91 -0
- package/dist/lib/target-url-preflight.js +259 -0
- package/dist/lib/target-url.d.ts +22 -5
- package/dist/lib/target-url.js +60 -28
- package/dist/lib/testlist.types.d.ts +77 -0
- package/dist/lib/testlist.types.js +9 -0
- package/dist/lib/v3-advisory.d.ts +35 -22
- package/dist/lib/v3-advisory.js +44 -24
- package/dist/lib/wait-exit.d.ts +29 -0
- package/dist/lib/wait-exit.js +103 -0
- package/dist/version-guard.d.ts +10 -7
- package/dist/version-guard.js +37 -9
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-charge reachability preflight for a caller-supplied `--target-url`.
|
|
3
|
+
*
|
|
4
|
+
* A blocked-run analysis measured 1,003 blocked-with-URL CLI runs: 26%
|
|
5
|
+
* pointed at a third-party tunnel host (`*.trycloudflare.com`, `*.loca.lt`,
|
|
6
|
+
* ngrok), 55.5% of those were blocked, and every one of them was charged
|
|
7
|
+
* anyway — the run row and its credit spend happen before the Lambda ever
|
|
8
|
+
* discovers the target is dead. This probe runs BEFORE the trigger POST so
|
|
9
|
+
* an obviously-doomed run never gets a run row or a charge.
|
|
10
|
+
*
|
|
11
|
+
* **Honest limitation** (this must also be stated in `--help` and the PR
|
|
12
|
+
* body): the probe below runs from wherever this CLI process runs — the
|
|
13
|
+
* caller's laptop, a CI runner — while the actual test executes from a
|
|
14
|
+
* Lambda inside AWS. Reachability from one is not proof of reachability
|
|
15
|
+
* from the other. That asymmetry is why the refusal set is deliberately
|
|
16
|
+
* narrow (only the failure classes that analysis actually measured — a
|
|
17
|
+
* broader rule would not have prevented a single one of those 1,003 runs), why
|
|
18
|
+
* every ambiguous signal downgrades to a warning instead of a hard block,
|
|
19
|
+
* and why `--skip-preflight` exists as a full opt-out (zero network calls).
|
|
20
|
+
*
|
|
21
|
+
* Two injectable seams, mirroring the MCP plugin's `checkPortListening`
|
|
22
|
+
* shape (a cheap first check, then an HTTP-level fallback for the signal
|
|
23
|
+
* the first check can't see) rather than inventing a new one:
|
|
24
|
+
* - `dnsLookup` — a raw DNS resolution. Deliberately separate from the
|
|
25
|
+
* HTTP probe below: `proxy.ts` installs a proxy dispatcher that only
|
|
26
|
+
* `fetch()` honours, never a raw socket/DNS call, so behind a
|
|
27
|
+
* configured HTTP(S) proxy this step can fail locally (the real
|
|
28
|
+
* resolution happens at the proxy) even though the target is reachable
|
|
29
|
+
* — hence the proxy carve-out downgrades a negative *failure* result
|
|
30
|
+
* here. A resolved address landing in the private/loopback/link-local/
|
|
31
|
+
* metadata range is a different kind of signal (DNS rebinding, not
|
|
32
|
+
* ambiguity about where resolution happens) and always refuses — see
|
|
33
|
+
* the resolved-address check below.
|
|
34
|
+
* - `fetchImpl` — the actual HTTP probe (proxy-aware once a proxy
|
|
35
|
+
* dispatcher is installed), used for the 502/503/504 gateway-error
|
|
36
|
+
* signal a DNS/TCP-level check cannot see at all. Runs with
|
|
37
|
+
* `redirect: 'manual'`: a 3xx is treated as a live/reachable signal
|
|
38
|
+
* (a real app 302ing to a login page is healthy) but is never
|
|
39
|
+
* followed — the redirect target is unvalidated by everything above
|
|
40
|
+
* (`assertNotLocal` only ever inspected the literal `--target-url`
|
|
41
|
+
* string; the resolved-address check only covers *this* URL's host),
|
|
42
|
+
* so following it would hand an attacker-controlled Location header a
|
|
43
|
+
* live SSRF primitive running on the caller's machine or CI runner.
|
|
44
|
+
*/
|
|
45
|
+
import * as dns from 'node:dns';
|
|
46
|
+
import { isIP } from 'node:net';
|
|
47
|
+
import { ApiError } from './errors.js';
|
|
48
|
+
import { isProxyAgentActive } from './proxy.js';
|
|
49
|
+
import { disallowedIpReason } from './target-url.js';
|
|
50
|
+
/** ~8s, matching the MCP plugin's `checkPortListening` TCP-probe budget. */
|
|
51
|
+
const PREFLIGHT_TIMEOUT_MS = 8_000;
|
|
52
|
+
const GATEWAY_ERROR_STATUSES = new Set([502, 503, 504]);
|
|
53
|
+
/** Pulls the string addresses out of a `dns.lookup` result, whether it's a
|
|
54
|
+
* single `{ address, family }` object (the no-options default) or an array
|
|
55
|
+
* of them (the `{ all: true }` shape the real default below requests, so a
|
|
56
|
+
* dual-stack host's A *and* AAAA records are both checked). */
|
|
57
|
+
function resolvedAddresses(lookupResult) {
|
|
58
|
+
const records = Array.isArray(lookupResult) ? lookupResult : [lookupResult];
|
|
59
|
+
return records
|
|
60
|
+
.map(r => r?.address)
|
|
61
|
+
.filter((a) => typeof a === 'string');
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* True when `err` (or a `cause` nested inside it — including an
|
|
65
|
+
* `AggregateError`'s `.errors[]`, the shape undici throws for a dual-stack
|
|
66
|
+
* host where one address family connects and the other refuses) carries
|
|
67
|
+
* one of `codes` as its `code`.
|
|
68
|
+
*/
|
|
69
|
+
function errorHasCode(err, codes) {
|
|
70
|
+
const top = err?.code;
|
|
71
|
+
if (typeof top === 'string' && codes.includes(top))
|
|
72
|
+
return true;
|
|
73
|
+
const cause = err?.cause;
|
|
74
|
+
const causeCode = cause?.code;
|
|
75
|
+
if (typeof causeCode === 'string' && codes.includes(causeCode))
|
|
76
|
+
return true;
|
|
77
|
+
const aggErrors = cause?.errors;
|
|
78
|
+
if (Array.isArray(aggErrors)) {
|
|
79
|
+
return aggErrors.some(e => {
|
|
80
|
+
const code = e?.code;
|
|
81
|
+
return typeof code === 'string' && codes.includes(code);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
function isTimeoutError(err) {
|
|
87
|
+
const name = err?.name;
|
|
88
|
+
return name === 'AbortError' || name === 'TimeoutError';
|
|
89
|
+
}
|
|
90
|
+
/** Strips the `[...]` bracket notation the WHATWG `URL.hostname` getter uses for IPv6 literals. */
|
|
91
|
+
function bareHost(hostname) {
|
|
92
|
+
return hostname.startsWith('[') && hostname.endsWith(']') ? hostname.slice(1, -1) : hostname;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Probe `rawUrl` for the narrow refusal set described in the module
|
|
96
|
+
* docstring. Pure decision function — never throws for a network failure
|
|
97
|
+
* (every reachable failure classifies to `warn` or `refuse`); a malformed
|
|
98
|
+
* URL degrades to `warn` rather than crashing (callers validate the URL
|
|
99
|
+
* shape via `assertNotLocal` before this runs).
|
|
100
|
+
*/
|
|
101
|
+
export async function probeTargetUrl(rawUrl, deps = {}) {
|
|
102
|
+
const proxied = deps.proxyActive ?? isProxyAgentActive();
|
|
103
|
+
let parsed;
|
|
104
|
+
try {
|
|
105
|
+
parsed = new URL(rawUrl);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return { verdict: 'warn', reason: 'could not parse --target-url for the reachability probe' };
|
|
109
|
+
}
|
|
110
|
+
const host = bareHost(parsed.hostname);
|
|
111
|
+
// Step 1 — DNS. Skipped for a literal IP host (nothing to resolve, and
|
|
112
|
+
// dns.lookup on a literal is a needless round trip through the resolver).
|
|
113
|
+
if (isIP(host) === 0) {
|
|
114
|
+
const dnsLookup = deps.dnsLookup ?? ((hostname) => dns.promises.lookup(hostname, { all: true }));
|
|
115
|
+
let lookupResult;
|
|
116
|
+
try {
|
|
117
|
+
lookupResult = await dnsLookup(host);
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
const code = err?.code;
|
|
121
|
+
if (code === 'ENOTFOUND' || code === 'EAI_NONAME') {
|
|
122
|
+
if (proxied) {
|
|
123
|
+
return {
|
|
124
|
+
verdict: 'warn',
|
|
125
|
+
reason: `DNS lookup for "${host}" failed locally (${code}) — not conclusive behind a configured proxy`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
verdict: 'refuse',
|
|
130
|
+
reason: `--target-url host "${host}" does not resolve (${code})`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// Anything else (e.g. EAI_AGAIN — a transient resolver hiccup) is
|
|
134
|
+
// ambiguous, not a confirmed dead target — warn, never refuse.
|
|
135
|
+
return {
|
|
136
|
+
verdict: 'warn',
|
|
137
|
+
reason: `DNS lookup for "${host}" failed (${typeof code === 'string' ? code : 'unknown error'})`,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
// DNS rebinding: a public-looking hostname (e.g. an attacker-controlled
|
|
141
|
+
// domain, or a tunnel host with attacker-influenced DNS) whose A/AAAA
|
|
142
|
+
// record actually points at a private, loopback, link-local, or
|
|
143
|
+
// metadata-service address. `assertNotLocal` never catches this — it
|
|
144
|
+
// only ever inspected the literal `--target-url` *string*, and this
|
|
145
|
+
// hostname passed that check honestly (it doesn't LOOK private). Unlike
|
|
146
|
+
// the DNS-failure branch above, there is no proxy carve-out: resolving
|
|
147
|
+
// locally to a private address is a security signal, not an ambiguous
|
|
148
|
+
// "can't tell from here" result, and a false positive has a documented
|
|
149
|
+
// escape hatch (`--skip-preflight`) rather than a broken workflow.
|
|
150
|
+
for (const address of resolvedAddresses(lookupResult)) {
|
|
151
|
+
const blockedReason = disallowedIpReason(address);
|
|
152
|
+
if (blockedReason !== undefined) {
|
|
153
|
+
return {
|
|
154
|
+
verdict: 'refuse',
|
|
155
|
+
reason: `--target-url host "${host}" resolves to ${address} (${blockedReason})`,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// Step 2 — HTTP probe. Runs through the global `fetch`, which picks up
|
|
161
|
+
// the proxy dispatcher `proxy.ts` installs at startup when one is
|
|
162
|
+
// configured — so this step (unlike the DNS step above) is proxy-aware
|
|
163
|
+
// by construction, not just proxy-tolerant.
|
|
164
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
165
|
+
try {
|
|
166
|
+
const resp = await fetchImpl(rawUrl, {
|
|
167
|
+
method: 'GET',
|
|
168
|
+
// Never follow — see the module docstring. A 3xx is reachability
|
|
169
|
+
// proof on its own (handled immediately below); the redirect target
|
|
170
|
+
// is unvalidated and must not be dereferenced.
|
|
171
|
+
redirect: 'manual',
|
|
172
|
+
signal: AbortSignal.timeout(PREFLIGHT_TIMEOUT_MS),
|
|
173
|
+
});
|
|
174
|
+
// Never read the body — only the status matters here. Cancel it so the
|
|
175
|
+
// connection is released promptly instead of buffering a full page.
|
|
176
|
+
void resp.body?.cancel().catch(() => undefined);
|
|
177
|
+
if (resp.status >= 300 && resp.status < 400) {
|
|
178
|
+
// A redirect is a live-server signal (e.g. a real app 302ing an
|
|
179
|
+
// unauthenticated GET to a login page) — reachable, not refused. The
|
|
180
|
+
// Location header is deliberately never inspected or dereferenced.
|
|
181
|
+
return { verdict: 'ok' };
|
|
182
|
+
}
|
|
183
|
+
if (GATEWAY_ERROR_STATUSES.has(resp.status)) {
|
|
184
|
+
if (proxied) {
|
|
185
|
+
return {
|
|
186
|
+
verdict: 'warn',
|
|
187
|
+
reason: `--target-url responded HTTP ${resp.status} — not conclusive behind a configured proxy`,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
verdict: 'refuse',
|
|
192
|
+
reason: `--target-url responded HTTP ${resp.status} (gateway error — the target is unreachable)`,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
if (resp.status >= 400) {
|
|
196
|
+
return { verdict: 'warn', reason: `--target-url responded HTTP ${resp.status}` };
|
|
197
|
+
}
|
|
198
|
+
return { verdict: 'ok' };
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
if (errorHasCode(err, ['ECONNREFUSED'])) {
|
|
202
|
+
if (proxied) {
|
|
203
|
+
return {
|
|
204
|
+
verdict: 'warn',
|
|
205
|
+
reason: 'connection to --target-url was refused — not conclusive behind a configured proxy',
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return { verdict: 'refuse', reason: 'connection to --target-url was refused (ECONNREFUSED)' };
|
|
209
|
+
}
|
|
210
|
+
if (isTimeoutError(err)) {
|
|
211
|
+
return {
|
|
212
|
+
verdict: 'warn',
|
|
213
|
+
reason: `--target-url did not respond within ${PREFLIGHT_TIMEOUT_MS / 1000}s`,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
// TLS errors and anything else unclassified: warn only — the refusal
|
|
217
|
+
// set stays narrow to exactly what that analysis measured.
|
|
218
|
+
return {
|
|
219
|
+
verdict: 'warn',
|
|
220
|
+
reason: `could not reach --target-url (${err instanceof Error ? err.message : String(err)})`,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/** Shared wording so `--help` and every refuse/warn message agree on the escape hatch. */
|
|
225
|
+
const SKIP_HINT = 'Skip this check entirely with --skip-preflight.';
|
|
226
|
+
/**
|
|
227
|
+
* Run the preflight and either throw (refuse), print an `[advisory]` line
|
|
228
|
+
* (warn), or no-op (ok / skipped). This is the call-site integration point
|
|
229
|
+
* — wired at all four `--target-url` trigger paths, after `assertNotLocal`
|
|
230
|
+
* and before the trigger POST.
|
|
231
|
+
*
|
|
232
|
+
* `skipPreflight: true` makes this a pure no-op with ZERO network calls —
|
|
233
|
+
* neither `dnsLookup` nor `fetchImpl` is invoked.
|
|
234
|
+
*/
|
|
235
|
+
export async function assertTargetUrlReachable(targetUrl, opts, deps, stderrFn) {
|
|
236
|
+
if (opts.skipPreflight === true)
|
|
237
|
+
return;
|
|
238
|
+
const outcome = await probeTargetUrl(targetUrl, deps);
|
|
239
|
+
if (outcome.verdict === 'refuse') {
|
|
240
|
+
throw ApiError.fromEnvelope({
|
|
241
|
+
error: {
|
|
242
|
+
code: 'VALIDATION_ERROR',
|
|
243
|
+
message: `--target-url is not reachable: ${outcome.reason}.`,
|
|
244
|
+
nextAction: 'This CLI probes reachability from where the CLI runs, not from the Lambda that ' +
|
|
245
|
+
'executes the test — a false positive is possible (e.g. an IP allowlist that permits ' +
|
|
246
|
+
`the Lambda but not this machine). If you're confident the target is reachable from the ` +
|
|
247
|
+
`test runner, retry with --skip-preflight. ${SKIP_HINT}`,
|
|
248
|
+
requestId: 'local',
|
|
249
|
+
details: { field: 'targetUrl', reason: 'target-unreachable', probeReason: outcome.reason },
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
if (outcome.verdict === 'warn') {
|
|
254
|
+
stderrFn(`[advisory] --target-url may not be reachable (${outcome.reason}); proceeding anyway ` +
|
|
255
|
+
`(the CLI probes from where it runs, not from the Lambda that executes the test, so this ` +
|
|
256
|
+
`is not conclusive). ${SKIP_HINT}`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=target-url-preflight.js.map
|
package/dist/lib/target-url.d.ts
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
* CLI-side pre-flight guard for `--target-url`.
|
|
3
3
|
*
|
|
4
4
|
* Defense-in-depth: the backend is the trust boundary and performs DNS
|
|
5
|
-
* resolution.
|
|
6
|
-
* fast, friendly error before sending the request
|
|
7
|
-
* DNS rebinding (a public hostname that resolves to a private
|
|
8
|
-
*
|
|
5
|
+
* resolution. `assertNotLocal` below does **string/literal-only** checks
|
|
6
|
+
* to give a fast, friendly error before sending the request — it cannot by
|
|
7
|
+
* itself detect DNS rebinding (a public hostname that resolves to a private
|
|
8
|
+
* IP). That gap is closed one layer up: `target-url-preflight.ts` reuses
|
|
9
|
+
* `disallowedIpReason` (exported below) against the actually-*resolved*
|
|
10
|
+
* address before probing, so the same range list guards both the literal
|
|
11
|
+
* string and the DNS answer — not two drifting copies of it.
|
|
9
12
|
*
|
|
10
13
|
* CLI-side target-url guard (exit 5 on any rejection):
|
|
11
14
|
* - Reject non-http(s) schemes
|
|
@@ -13,7 +16,6 @@
|
|
|
13
16
|
* - Reject `169.254.0.0/16` link-local and the `169.254.169.254` metadata address
|
|
14
17
|
* - Reject RFC1918 literal IPv4 (10.x, 172.16-31.x, 192.168.x)
|
|
15
18
|
* - Reject IPv4-mapped IPv6 (`::ffff:…`), IPv6 link-local (`fe80::/10`), unique-local (`fc00::/7`)
|
|
16
|
-
* - Hostnames that resolve to private IPs are the backend's concern.
|
|
17
19
|
*/
|
|
18
20
|
/**
|
|
19
21
|
* Throws a local `VALIDATION_ERROR` (exit 5) when `rawUrl` is a
|
|
@@ -23,3 +25,18 @@
|
|
|
23
25
|
* Silently returns on allowed URLs.
|
|
24
26
|
*/
|
|
25
27
|
export declare function assertNotLocal(rawUrl: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Classify a bare IP-address literal — IPv4 dotted form, or IPv6 optionally
|
|
30
|
+
* wrapped in the `[...]` bracket notation `URL.hostname` uses — against the
|
|
31
|
+
* private/loopback/link-local/metadata blocklist. Returns the disallowed
|
|
32
|
+
* reason string, or `undefined` when the address is allowed.
|
|
33
|
+
*
|
|
34
|
+
* This is the single source of truth for the range list: `assertNotLocal`
|
|
35
|
+
* calls it for the literal `--target-url` string above, and the reachability
|
|
36
|
+
* preflight (`target-url-preflight.ts`) calls it again for a DNS-*resolved*
|
|
37
|
+
* address — a public-looking hostname whose A/AAAA record actually points
|
|
38
|
+
* at a private or metadata IP (DNS rebinding) is a distinct bypass from a
|
|
39
|
+
* literal private IP typed on the command line, and both need the same
|
|
40
|
+
* range list, not two drifting copies of it.
|
|
41
|
+
*/
|
|
42
|
+
export declare function disallowedIpReason(host: string): string | undefined;
|
package/dist/lib/target-url.js
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
* CLI-side pre-flight guard for `--target-url`.
|
|
3
3
|
*
|
|
4
4
|
* Defense-in-depth: the backend is the trust boundary and performs DNS
|
|
5
|
-
* resolution.
|
|
6
|
-
* fast, friendly error before sending the request
|
|
7
|
-
* DNS rebinding (a public hostname that resolves to a private
|
|
8
|
-
*
|
|
5
|
+
* resolution. `assertNotLocal` below does **string/literal-only** checks
|
|
6
|
+
* to give a fast, friendly error before sending the request — it cannot by
|
|
7
|
+
* itself detect DNS rebinding (a public hostname that resolves to a private
|
|
8
|
+
* IP). That gap is closed one layer up: `target-url-preflight.ts` reuses
|
|
9
|
+
* `disallowedIpReason` (exported below) against the actually-*resolved*
|
|
10
|
+
* address before probing, so the same range list guards both the literal
|
|
11
|
+
* string and the DNS answer — not two drifting copies of it.
|
|
9
12
|
*
|
|
10
13
|
* CLI-side target-url guard (exit 5 on any rejection):
|
|
11
14
|
* - Reject non-http(s) schemes
|
|
@@ -13,7 +16,6 @@
|
|
|
13
16
|
* - Reject `169.254.0.0/16` link-local and the `169.254.169.254` metadata address
|
|
14
17
|
* - Reject RFC1918 literal IPv4 (10.x, 172.16-31.x, 192.168.x)
|
|
15
18
|
* - Reject IPv4-mapped IPv6 (`::ffff:…`), IPv6 link-local (`fe80::/10`), unique-local (`fc00::/7`)
|
|
16
|
-
* - Hostnames that resolve to private IPs are the backend's concern.
|
|
17
19
|
*/
|
|
18
20
|
import { ApiError } from './errors.js';
|
|
19
21
|
const LOCAL_DEV_HINT = 'Local-dev tests are out of scope for the CLI; use testsprite-mcp-plugin for the local tunnel.';
|
|
@@ -44,35 +46,62 @@ export function assertNotLocal(rawUrl) {
|
|
|
44
46
|
// IP literals are already dot-normalized by the WHATWG URL parser, so this
|
|
45
47
|
// only affects named hosts.
|
|
46
48
|
const host = parsed.hostname.toLowerCase().replace(/\.$/, '');
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
+
// 'localhost' is a name, not an IP literal, so it sits outside
|
|
50
|
+
// `disallowedIpReason` below (which classifies IPv4/IPv6 address forms).
|
|
51
|
+
if (host === 'localhost') {
|
|
49
52
|
throw localTargetError('target-url', 'localhost targets are not allowed', LOCAL_DEV_HINT);
|
|
50
53
|
}
|
|
54
|
+
const reason = disallowedIpReason(host);
|
|
55
|
+
if (reason !== undefined) {
|
|
56
|
+
throw localTargetError('target-url', reason, LOCAL_DEV_HINT);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Classify a bare IP-address literal — IPv4 dotted form, or IPv6 optionally
|
|
61
|
+
* wrapped in the `[...]` bracket notation `URL.hostname` uses — against the
|
|
62
|
+
* private/loopback/link-local/metadata blocklist. Returns the disallowed
|
|
63
|
+
* reason string, or `undefined` when the address is allowed.
|
|
64
|
+
*
|
|
65
|
+
* This is the single source of truth for the range list: `assertNotLocal`
|
|
66
|
+
* calls it for the literal `--target-url` string above, and the reachability
|
|
67
|
+
* preflight (`target-url-preflight.ts`) calls it again for a DNS-*resolved*
|
|
68
|
+
* address — a public-looking hostname whose A/AAAA record actually points
|
|
69
|
+
* at a private or metadata IP (DNS rebinding) is a distinct bypass from a
|
|
70
|
+
* literal private IP typed on the command line, and both need the same
|
|
71
|
+
* range list, not two drifting copies of it.
|
|
72
|
+
*/
|
|
73
|
+
export function disallowedIpReason(host) {
|
|
51
74
|
// IPv6 literals. Node's URL parser wraps IPv6 hosts in brackets and
|
|
52
75
|
// normalizes IPv4-mapped forms to hex (`http://[::ffff:127.0.0.1]` →
|
|
53
76
|
// hostname `[::ffff:7f00:1]`). A dotted-form string check alone would miss
|
|
54
77
|
// the normalized variant, so we strip the brackets and classify the
|
|
55
|
-
// address family explicitly.
|
|
56
|
-
|
|
57
|
-
|
|
78
|
+
// address family explicitly. A DNS-resolved IPv6 address arrives
|
|
79
|
+
// unbracketed already; stripping is a no-op for that shape.
|
|
80
|
+
const bare = host.startsWith('[') && host.endsWith(']') ? host.slice(1, -1) : host;
|
|
81
|
+
if (bare.includes(':')) {
|
|
82
|
+
return disallowedIpv6Reason(bare);
|
|
83
|
+
}
|
|
84
|
+
// Unspecified.
|
|
85
|
+
if (bare === '0.0.0.0') {
|
|
86
|
+
return 'localhost targets are not allowed';
|
|
58
87
|
}
|
|
59
88
|
// 127.0.0.0/8 loopback range.
|
|
60
|
-
if (/^127\.\d+\.\d+\.\d+$/.test(
|
|
61
|
-
|
|
89
|
+
if (/^127\.\d+\.\d+\.\d+$/.test(bare)) {
|
|
90
|
+
return 'loopback addresses are not allowed';
|
|
62
91
|
}
|
|
63
|
-
// AWS instance-metadata service
|
|
64
|
-
if (
|
|
65
|
-
|
|
92
|
+
// AWS instance-metadata service.
|
|
93
|
+
if (bare === '169.254.169.254') {
|
|
94
|
+
return '169.254.169.254 (AWS metadata service) is not allowed';
|
|
66
95
|
}
|
|
67
96
|
// 169.254.x.x link-local (IPv4).
|
|
68
|
-
if (/^169\.254\.\d+\.\d+$/.test(
|
|
69
|
-
|
|
97
|
+
if (/^169\.254\.\d+\.\d+$/.test(bare)) {
|
|
98
|
+
return 'link-local addresses are not allowed';
|
|
70
99
|
}
|
|
71
|
-
// RFC1918 literal IP addresses
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
throw localTargetError('target-url', 'private/RFC1918 addresses are not allowed', LOCAL_DEV_HINT);
|
|
100
|
+
// RFC1918 literal IP addresses.
|
|
101
|
+
if (isRfc1918Literal(bare)) {
|
|
102
|
+
return 'private/RFC1918 addresses are not allowed';
|
|
75
103
|
}
|
|
104
|
+
return undefined;
|
|
76
105
|
}
|
|
77
106
|
function isRfc1918Literal(host) {
|
|
78
107
|
// 10.0.0.0/8
|
|
@@ -91,32 +120,35 @@ function isRfc1918Literal(host) {
|
|
|
91
120
|
return false;
|
|
92
121
|
}
|
|
93
122
|
/**
|
|
94
|
-
*
|
|
123
|
+
* Classify disallowed IPv6 literals: loopback (`::1`), unspecified (`::`),
|
|
95
124
|
* IPv4-mapped (`::ffff:…`), link-local (`fe80::/10`), and unique-local
|
|
96
|
-
* (`fc00::/7`). `inner` is the bracket-stripped
|
|
125
|
+
* (`fc00::/7`). `inner` is the bracket-stripped host; callers are
|
|
126
|
+
* responsible for lowercasing (the URL parser already lowercases hostnames,
|
|
127
|
+
* a DNS-resolved address is emitted lowercase by Node).
|
|
97
128
|
*
|
|
98
129
|
* The IPv4-mapped class is rejected wholesale rather than decoding the
|
|
99
130
|
* embedded v4 address: no legitimate target is expressed as a mapped
|
|
100
131
|
* literal, and the hex-normalized form (`::ffff:7f00:1`) is error-prone to
|
|
101
132
|
* decode. This closes the `http://[::ffff:127.0.0.1]` SSRF-guard bypass.
|
|
102
133
|
*/
|
|
103
|
-
function
|
|
134
|
+
function disallowedIpv6Reason(inner) {
|
|
104
135
|
// Loopback (::1) and unspecified (::).
|
|
105
136
|
if (inner === '::1' || inner === '::') {
|
|
106
|
-
|
|
137
|
+
return 'localhost targets are not allowed';
|
|
107
138
|
}
|
|
108
139
|
// IPv4-mapped IPv6 (`::ffff:a.b.c.d`, normalized to `::ffff:hhhh:hhhh`).
|
|
109
140
|
if (inner.startsWith('::ffff:')) {
|
|
110
|
-
|
|
141
|
+
return 'IPv4-mapped IPv6 addresses are not allowed; use the IPv4 form or a hostname';
|
|
111
142
|
}
|
|
112
143
|
// Link-local fe80::/10 (first hextet fe80–febf).
|
|
113
144
|
if (/^fe[89ab][0-9a-f]:/.test(inner)) {
|
|
114
|
-
|
|
145
|
+
return 'link-local addresses are not allowed';
|
|
115
146
|
}
|
|
116
147
|
// Unique-local fc00::/7 (first hextet fc00–fdff).
|
|
117
148
|
if (/^f[cd][0-9a-f]{2}:/.test(inner)) {
|
|
118
|
-
|
|
149
|
+
return 'unique-local (private) addresses are not allowed';
|
|
119
150
|
}
|
|
151
|
+
return undefined;
|
|
120
152
|
}
|
|
121
153
|
function localTargetError(field, reason, hint) {
|
|
122
154
|
return ApiError.fromEnvelope({
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire shapes for the `/api/cli/v1/testlist/*` surface (CRUD).
|
|
3
|
+
*
|
|
4
|
+
* `testId` on a case IS the test's logical id (`test_case.key`) — the same id
|
|
5
|
+
* `test list` / `test get` return and `test run` accepts, so a case can be added
|
|
6
|
+
* to a list with no translation.
|
|
7
|
+
*/
|
|
8
|
+
import type { RunConflict } from './conflict-reason.js';
|
|
9
|
+
export interface CliProjectEnvironment {
|
|
10
|
+
projectId: string;
|
|
11
|
+
environmentName: string;
|
|
12
|
+
}
|
|
13
|
+
/** A test-list row (no cases) — `testlist list`. */
|
|
14
|
+
export interface CliTestList {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
orgId: string;
|
|
18
|
+
caseCount: number;
|
|
19
|
+
projectEnvironments: CliProjectEnvironment[];
|
|
20
|
+
lastExecutionId: string | null;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
updatedAt: string;
|
|
23
|
+
}
|
|
24
|
+
/** One case inside a list — `testlist get`. */
|
|
25
|
+
export interface CliTestListCase {
|
|
26
|
+
/** The test's logical id (== `test_case.key`). */
|
|
27
|
+
testId: string;
|
|
28
|
+
type: 'frontend' | 'backend';
|
|
29
|
+
projectId: string;
|
|
30
|
+
projectName: string;
|
|
31
|
+
title: string | null;
|
|
32
|
+
category: string | null;
|
|
33
|
+
priority: string | null;
|
|
34
|
+
modified: string | null;
|
|
35
|
+
status: string | null;
|
|
36
|
+
}
|
|
37
|
+
/** Full detail incl. cases + stats — `testlist get` / after a mutation. */
|
|
38
|
+
export interface CliTestListDetail extends CliTestList {
|
|
39
|
+
cases: CliTestListCase[];
|
|
40
|
+
stats: {
|
|
41
|
+
total: number;
|
|
42
|
+
passed: number;
|
|
43
|
+
failed: number;
|
|
44
|
+
blocked: number;
|
|
45
|
+
running: number;
|
|
46
|
+
};
|
|
47
|
+
lastExecutionCreated: string | null;
|
|
48
|
+
}
|
|
49
|
+
export interface CliTestListListResponse {
|
|
50
|
+
items: CliTestList[];
|
|
51
|
+
}
|
|
52
|
+
export interface CliDeleteTestListResponse {
|
|
53
|
+
listId: string;
|
|
54
|
+
}
|
|
55
|
+
/** One dispatched run from `testlist run` — `runId` polls via `GET /runs/{runId}`. */
|
|
56
|
+
export interface CliTestListRunAccepted {
|
|
57
|
+
testId: string;
|
|
58
|
+
runId: string;
|
|
59
|
+
enqueuedAt: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* `testlist run` result. Mirrors the batch-run-fresh envelope so `--wait` reuses
|
|
63
|
+
* the same poll/summary tail. `conflicts[]` carry the in-flight `currentRunId`
|
|
64
|
+
* (poll it instead of retrying). `deferred[]` carries the cases the per-key
|
|
65
|
+
* run-rate budget could not admit this call (retry after ~60s). `notFound[]` is
|
|
66
|
+
* present on a PARTIAL `--case` miss — ids not in this list, skipped (a FULL miss
|
|
67
|
+
* is a 404). `reason` is set only when nothing dispatched (empty list).
|
|
68
|
+
*/
|
|
69
|
+
export interface CliTestListRunResponse {
|
|
70
|
+
accepted: CliTestListRunAccepted[];
|
|
71
|
+
conflicts: RunConflict[];
|
|
72
|
+
deferred: Array<{
|
|
73
|
+
testId: string;
|
|
74
|
+
}>;
|
|
75
|
+
notFound?: string[];
|
|
76
|
+
reason?: 'no_matching_cases' | 'empty_list';
|
|
77
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire shapes for the `/api/cli/v1/testlist/*` surface (CRUD).
|
|
3
|
+
*
|
|
4
|
+
* `testId` on a case IS the test's logical id (`test_case.key`) — the same id
|
|
5
|
+
* `test list` / `test get` return and `test run` accepts, so a case can be added
|
|
6
|
+
* to a list with no translation.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=testlist.types.js.map
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared V3-routing text surfaces
|
|
2
|
+
* Shared V3-routing text surfaces.
|
|
3
3
|
*
|
|
4
|
-
* `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* `V3_ROUTING_ADVISORY`/`emitV3RoutingAdvisory` back `auth status` and
|
|
5
|
+
* `doctor`: `v3Enabled` on the `/me` response is the authoritative routing
|
|
6
|
+
* bit, and when it is on, some commands behave differently while the V3
|
|
7
|
+
* gaps stay open — the advisory names them. Copy lives here so both
|
|
8
|
+
* commands stay in sync.
|
|
9
|
+
*
|
|
10
|
+
* `targetUrlAdvisoryText`/`emitTargetUrlMismatchAdvisory` back the
|
|
11
|
+
* `--target-url` point-of-use advisory in `commands/test.ts` — a different,
|
|
12
|
+
* response-driven mechanism (see its own docblock below) that does not
|
|
13
|
+
* depend on `v3Enabled` at all.
|
|
7
14
|
*/
|
|
8
15
|
/** One-word routing label for the text card. */
|
|
9
16
|
export declare function routingLabel(v3Enabled: boolean): 'v3' | 'v2';
|
|
@@ -21,22 +28,28 @@ export declare const V3_ROUTING_ADVISORY: string[];
|
|
|
21
28
|
/** Write the advisory to a stderr sink, one line per call. */
|
|
22
29
|
export declare function emitV3RoutingAdvisory(stderr: (line: string) => void): void;
|
|
23
30
|
/**
|
|
24
|
-
* Point-of-use advisory for `test run --target-url
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* (
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* `
|
|
35
|
-
*
|
|
36
|
-
* (no "on
|
|
37
|
-
*
|
|
38
|
-
*
|
|
31
|
+
* Point-of-use advisory for `test run --target-url`, redesigned to be
|
|
32
|
+
* response-driven rather than assumption-driven. The original
|
|
33
|
+
* version probed `GET /me` for `v3Enabled` and warned on that ASSUMPTION —
|
|
34
|
+
* but the backend is the ground truth here, not a proxy for it. V3
|
|
35
|
+
* deliberately returns `targetUrl: ''` rather than echoing an override it
|
|
36
|
+
* did not apply ("so the response doesn't claim a target we didn't use"),
|
|
37
|
+
* while V2 echoes the real applied value. So the advisory now fires purely
|
|
38
|
+
* from comparing what the caller asked for against what the trigger
|
|
39
|
+
* response reports — it self-corrects the day the backend applies the
|
|
40
|
+
* override, needs no `v3Enabled` lookup (and so no extra `/me` round trip,
|
|
41
|
+
* no `X-CLI-Command` tagging machinery), and is exact rather than inferred.
|
|
42
|
+
*
|
|
43
|
+
* Deliberately type-agnostic in its wording (no "on the V3 path" claim):
|
|
44
|
+
* a mismatch is reported purely from the observed response, regardless of
|
|
45
|
+
* why the backend didn't apply the override.
|
|
46
|
+
*/
|
|
47
|
+
export declare function targetUrlAdvisoryText(requested: string, applied: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Compare the requested `--target-url` against what the trigger response
|
|
50
|
+
* reports and write the advisory when they differ. No-op when they match
|
|
51
|
+
* (the override was applied, or the caller didn't supply one — callers are
|
|
52
|
+
* expected to gate the `requested` argument on `opts.targetUrl !== undefined`
|
|
53
|
+
* themselves so this stays a pure comparison).
|
|
39
54
|
*/
|
|
40
|
-
export declare
|
|
41
|
-
/** Write the target-url advisory to a stderr sink. */
|
|
42
|
-
export declare function emitTargetUrlV3Advisory(stderr: (line: string) => void): void;
|
|
55
|
+
export declare function emitTargetUrlMismatchAdvisory(stderr: (line: string) => void, requested: string, applied: string): void;
|