@halonicjs/testing 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +4 -0
- package/README.md +1 -1
- package/dist/adapters/http-kit/src/address-checking.d.ts +19 -0
- package/dist/adapters/http-kit/src/address-checking.js +1 -0
- package/dist/adapters/http-kit/src/index.d.ts +1 -0
- package/dist/adapters/integration-kit/src/auth-placement.d.ts +40 -0
- package/dist/adapters/integration-kit/src/auth-placement.js +102 -0
- package/dist/adapters/integration-kit/src/current-secret-forms.d.ts +28 -0
- package/dist/adapters/integration-kit/src/current-secret-forms.js +60 -0
- package/dist/adapters/integration-kit/src/declaration.d.ts +2 -1
- package/dist/adapters/integration-kit/src/declaration.js +4 -3
- package/dist/adapters/integration-kit/src/host.d.ts +7 -1
- package/dist/adapters/integration-kit/src/host.js +1 -0
- package/dist/adapters/integration-kit/src/index.d.ts +3 -1
- package/dist/adapters/integration-kit/src/index.js +1 -0
- package/dist/adapters/integration-kit/src/leak-attempt.d.ts +4 -2
- package/dist/adapters/integration-kit/src/leak-attempt.js +5 -2
- package/dist/adapters/integration-kit/src/limited-http.d.ts +7 -1
- package/dist/adapters/integration-kit/src/limited-http.js +53 -10
- package/dist/adapters/integration-kit/src/loader.d.ts +29 -2
- package/dist/adapters/integration-kit/src/loader.js +44 -12
- package/dist/adapters/integration-kit/src/own-request.d.ts +2 -2
- package/dist/adapters/integration-kit/src/own-request.js +1 -1
- package/dist/adapters/integration-kit/src/plugin-load.d.ts +3 -3
- package/dist/adapters/integration-kit/src/plugin-load.js +5 -5
- package/dist/adapters/integration-kit/src/policy.d.ts +28 -0
- package/dist/adapters/integration-kit/src/response-body.d.ts +6 -2
- package/dist/adapters/integration-kit/src/secret-filter.d.ts +3 -3
- package/dist/adapters/integration-kit/src/secret-filter.js +19 -4
- package/dist/adapters/integration-kit/src/secret-in-request.d.ts +3 -0
- package/dist/adapters/integration-kit/src/secret-in-request.js +8 -2
- package/dist/adapters/integration-kit/src/secret-placement.d.ts +35 -25
- package/dist/adapters/integration-kit/src/secret-placement.js +65 -95
- package/dist/adapters/integration-kit/src/sign-in-placement.d.ts +29 -0
- package/dist/adapters/integration-kit/src/sign-in-placement.js +92 -0
- package/dist/core/events/src/blocked-sites.d.ts +57 -0
- package/dist/core/events/src/blocked-sites.js +89 -0
- package/dist/core/events/src/index.d.ts +5 -1
- package/dist/core/events/src/index.js +3 -0
- package/dist/core/events/src/run-basics.d.ts +30 -7
- package/dist/core/events/src/run-event.d.ts +49 -5
- package/dist/core/events/src/run-reads.d.ts +25 -0
- package/dist/core/events/src/run-reads.js +44 -0
- package/dist/core/events/src/run-sends.d.ts +47 -0
- package/dist/core/events/src/run-sends.js +68 -0
- package/dist/core/events/src/summarize.js +5 -1
- package/dist/core/events/src/timeline-entry.js +1 -0
- package/dist/core/format/src/index.d.ts +7 -5
- package/dist/core/format/src/index.js +5 -3
- package/dist/core/format/src/integration/index.d.ts +3 -2
- package/dist/core/format/src/integration/index.js +2 -1
- package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +15 -5
- package/dist/core/format/src/kinds/agent/sandbox-fields.js +29 -10
- package/dist/core/format/src/kinds/agent/schema.js +2 -2
- package/dist/core/format/src/kinds/connector/is-local.js +1 -1
- package/dist/core/format/src/kinds/connector/kind.js +99 -0
- package/dist/core/format/src/kinds/connector/schema.d.ts +24 -0
- package/dist/core/format/src/kinds/connector/schema.js +53 -2
- package/dist/core/format/src/kinds/deployments/kind.js +25 -1
- package/dist/core/format/src/kinds/deployments/schema.d.ts +40 -0
- package/dist/core/format/src/kinds/deployments/schema.js +52 -0
- package/dist/core/format/src/kinds/integration/approved-sign-ins.d.ts +62 -0
- package/dist/core/format/src/kinds/integration/approved-sign-ins.js +125 -0
- package/dist/core/format/src/kinds/integration/host-key.d.ts +7 -0
- package/dist/core/format/src/kinds/integration/host-key.js +8 -0
- package/dist/core/format/src/kinds/integration/kind.d.ts +4 -2
- package/dist/core/format/src/kinds/integration/kind.js +49 -12
- package/dist/core/format/src/kinds/integration/policy.d.ts +47 -2
- package/dist/core/format/src/kinds/integration/policy.js +61 -2
- package/dist/core/format/src/kinds/integration/schema.d.ts +180 -3
- package/dist/core/format/src/kinds/integration/schema.js +132 -6
- package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +13 -0
- package/dist/core/format/src/kinds/integration/sign-in-checks.js +120 -0
- package/dist/core/format/src/kinds/integration/sign-in-urls.d.ts +19 -0
- package/dist/core/format/src/kinds/integration/sign-in-urls.js +47 -0
- package/dist/core/format/src/kinds/plugin/checks.js +7 -1
- package/dist/core/format/src/kinds/plugin/schema.d.ts +130 -0
- package/dist/core/format/src/kinds/plugin/schema.js +2 -2
- package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +1 -1
- package/dist/core/format/src/kinds/plugin/ui-checks.js +1 -10
- package/dist/core/format/src/kinds/routine/kind.js +38 -1
- package/dist/core/format/src/kinds/routine/schema.d.ts +10 -0
- package/dist/core/format/src/kinds/routine/schema.js +23 -1
- package/dist/core/format/src/kinds/routine/webhook-headers.d.ts +9 -0
- package/dist/core/format/src/kinds/routine/webhook-headers.js +26 -0
- package/dist/core/format/src/kinds/workflow/schema.js +1 -1
- package/dist/core/format/src/kinds/workspace/kind.js +1 -1
- package/dist/core/format/src/kinds/workspace/schema.d.ts +2 -2
- package/dist/core/format/src/kinds/workspace/schema.js +1 -1
- package/dist/core/format/src/shared/fields.d.ts +3 -6
- package/dist/core/format/src/shared/fields.js +33 -13
- package/dist/core/ports/src/agent-runs-not-available.d.ts +21 -0
- package/dist/core/ports/src/agent-runs-not-available.js +25 -0
- package/dist/core/ports/src/blob-store.d.ts +12 -0
- package/dist/core/ports/src/blob-store.js +22 -0
- package/dist/core/ports/src/connector-client.d.ts +48 -4
- package/dist/core/ports/src/connector-client.js +17 -0
- package/dist/core/ports/src/definition-store.d.ts +23 -2
- package/dist/core/ports/src/harness-bridge-server.d.ts +12 -3
- package/dist/core/ports/src/harness-sign-in-command.d.ts +27 -0
- package/dist/core/ports/src/harness-sign-in-command.js +31 -0
- package/dist/core/ports/src/harness.d.ts +46 -13
- package/dist/core/ports/src/harness.js +1 -1
- package/dist/core/ports/src/host-settings-store.d.ts +116 -0
- package/dist/core/ports/src/host-settings-store.js +106 -0
- package/dist/core/ports/src/index.d.ts +18 -10
- package/dist/core/ports/src/index.js +15 -7
- package/dist/core/ports/src/instruction-trust-store.d.ts +81 -0
- package/dist/core/ports/src/instruction-trust-store.js +43 -0
- package/dist/core/ports/src/integration.d.ts +71 -7
- package/dist/core/ports/src/integration.js +22 -4
- package/dist/core/ports/src/llm-provider.d.ts +3 -1
- package/dist/core/ports/src/llm-provider.js +3 -0
- package/dist/core/ports/src/password-hasher.d.ts +36 -20
- package/dist/core/ports/src/port-versions.d.ts +7 -4
- package/dist/core/ports/src/port-versions.js +6 -0
- package/dist/core/ports/src/program-probe.d.ts +25 -2
- package/dist/core/ports/src/program-probe.js +1 -1
- package/dist/core/ports/src/provider-default-base-url.d.ts +10 -0
- package/dist/core/ports/src/provider-default-base-url.js +18 -0
- package/dist/core/ports/src/record-store.d.ts +17 -0
- package/dist/core/ports/src/record-store.js +70 -0
- package/dist/core/ports/src/run-executor.d.ts +5 -4
- package/dist/core/ports/src/run-target-not-found.d.ts +34 -0
- package/dist/core/ports/src/run-target-not-found.js +41 -0
- package/dist/core/ports/src/sandbox-setting-store.d.ts +68 -0
- package/dist/core/ports/src/sandbox-setting-store.js +33 -0
- package/dist/core/ports/src/sandbox.d.ts +130 -13
- package/dist/core/ports/src/sandbox.js +38 -2
- package/dist/core/ports/src/secrets.d.ts +73 -0
- package/dist/core/ports/src/secrets.js +56 -0
- package/dist/core/ports/src/tool-approval-store.d.ts +50 -8
- package/dist/core/ports/src/tool-approval-store.js +59 -0
- package/dist/core/ports/src/vcs-status.d.ts +8 -0
- package/dist/core/ports/src/vcs-status.js +90 -0
- package/dist/core/std/src/amount.d.ts +13 -0
- package/dist/core/std/src/amount.js +22 -0
- package/dist/core/std/src/hidden-characters.d.ts +19 -0
- package/dist/core/std/src/hidden-characters.js +54 -0
- package/dist/core/std/src/index.d.ts +5 -0
- package/dist/core/std/src/index.js +5 -0
- package/dist/core/std/src/public-suffixes.generated.d.ts +9 -0
- package/dist/core/std/src/public-suffixes.generated.js +10429 -0
- package/dist/core/std/src/registrable-domain.d.ts +10 -0
- package/dist/core/std/src/registrable-domain.js +62 -0
- package/dist/core/std/src/secret-variable-name.d.ts +12 -0
- package/dist/core/std/src/secret-variable-name.js +34 -0
- package/dist/core/std/src/site-name.d.ts +35 -0
- package/dist/core/std/src/site-name.js +111 -0
- package/dist/core/std/src/url-host.d.ts +35 -0
- package/dist/core/std/src/url-host.js +170 -0
- package/dist/testing/integration/src/load.js +3 -1
- package/package.json +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The registrable domain of `host`: its public suffix and one label before
|
|
3
|
+
* it. A host that is a public suffix itself, or has a single label, is its
|
|
4
|
+
* own domain. A suffix the list doesn't know is the last label, as the list
|
|
5
|
+
* says. Labels are compared as they are, so pass a lowercase ASCII host.
|
|
6
|
+
*
|
|
7
|
+
* @param host - a lowercase host name in ASCII form, without a trailing dot
|
|
8
|
+
* @returns the registrable domain, at the end of `host`
|
|
9
|
+
*/
|
|
10
|
+
export declare function registrableDomain(host: string): string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Finds a host's registrable domain with our pinned copy of the public suffix
|
|
2
|
+
// list (P7 on HAL-1782): the part a person or company registered, such as
|
|
3
|
+
// `example.co.uk` in `api.example.co.uk`. The list's own algorithm is at
|
|
4
|
+
// https://github.com/publicsuffix/list/wiki/Format.
|
|
5
|
+
import { publicSuffixRules } from "./public-suffixes.generated.js";
|
|
6
|
+
// Split on first use, not when the package loads: most programs that use std
|
|
7
|
+
// never show a site. The rules never change while a program runs.
|
|
8
|
+
let rules;
|
|
9
|
+
/**
|
|
10
|
+
* The registrable domain of `host`: its public suffix and one label before
|
|
11
|
+
* it. A host that is a public suffix itself, or has a single label, is its
|
|
12
|
+
* own domain. A suffix the list doesn't know is the last label, as the list
|
|
13
|
+
* says. Labels are compared as they are, so pass a lowercase ASCII host.
|
|
14
|
+
*
|
|
15
|
+
* @param host - a lowercase host name in ASCII form, without a trailing dot
|
|
16
|
+
* @returns the registrable domain, at the end of `host`
|
|
17
|
+
*/
|
|
18
|
+
export function registrableDomain(host) {
|
|
19
|
+
const labels = host.split(".");
|
|
20
|
+
const suffixLength = publicSuffixLength(labels);
|
|
21
|
+
if (labels.length <= suffixLength)
|
|
22
|
+
return host;
|
|
23
|
+
return labels.slice(-(suffixLength + 1)).join(".");
|
|
24
|
+
}
|
|
25
|
+
/** How many labels at the end of `labels` are the public suffix. */
|
|
26
|
+
function publicSuffixLength(labels) {
|
|
27
|
+
const { exact, wildcard, exception } = suffixRules();
|
|
28
|
+
// From the longest candidate to the shortest, so the first rule that
|
|
29
|
+
// matches is the longest. An exception rule wins over the wildcard it
|
|
30
|
+
// undoes: its suffix is the candidate without its first label.
|
|
31
|
+
for (let start = 0; start < labels.length; start += 1) {
|
|
32
|
+
const candidate = labels.slice(start).join(".");
|
|
33
|
+
if (exception.has(candidate))
|
|
34
|
+
return labels.length - start - 1;
|
|
35
|
+
if (exact.has(candidate))
|
|
36
|
+
return labels.length - start;
|
|
37
|
+
const parent = labels.slice(start + 1).join(".");
|
|
38
|
+
if (start + 1 < labels.length && wildcard.has(parent))
|
|
39
|
+
return labels.length - start;
|
|
40
|
+
}
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
function suffixRules() {
|
|
44
|
+
rules ??= splitRules(publicSuffixRules);
|
|
45
|
+
return rules;
|
|
46
|
+
}
|
|
47
|
+
function splitRules(text) {
|
|
48
|
+
const exact = new Set();
|
|
49
|
+
const wildcard = new Set();
|
|
50
|
+
const exception = new Set();
|
|
51
|
+
for (const rule of text.split("\n")) {
|
|
52
|
+
if (rule === "")
|
|
53
|
+
continue;
|
|
54
|
+
if (rule.startsWith("!"))
|
|
55
|
+
exception.add(rule.slice(1));
|
|
56
|
+
else if (rule.startsWith("*."))
|
|
57
|
+
wildcard.add(rule.slice(2));
|
|
58
|
+
else
|
|
59
|
+
exact.add(rule);
|
|
60
|
+
}
|
|
61
|
+
return { exact, wildcard, exception };
|
|
62
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether an environment variable's name says its value is a secret: one
|
|
3
|
+
* of its words, in any letter case, is a word such as `TOKEN`, `KEY` or
|
|
4
|
+
* `PASSWORD`. Words are split at each character that is not a letter or
|
|
5
|
+
* digit and before a capital letter that follows a small letter or digit.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* isSecretVariableName("ANTHROPIC_API_KEY"); // true
|
|
9
|
+
* isSecretVariableName("authToken"); // true
|
|
10
|
+
* isSecretVariableName("KEYMAP"); // false
|
|
11
|
+
*/
|
|
12
|
+
export declare function isSecretVariableName(name: string): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Words in a variable's name that say its value is a secret, such as
|
|
3
|
+
* `API_KEY`, `NODE_AUTH_TOKEN` or `npm_config__authToken`. Only whole words
|
|
4
|
+
* count, so `KEYMAP` or `AUTHOR` don't.
|
|
5
|
+
*/
|
|
6
|
+
const secretWords = new Set([
|
|
7
|
+
"APIKEY",
|
|
8
|
+
"AUTH",
|
|
9
|
+
"COOKIE",
|
|
10
|
+
"CREDENTIAL",
|
|
11
|
+
"CREDENTIALS",
|
|
12
|
+
"KEY",
|
|
13
|
+
"PASSPHRASE",
|
|
14
|
+
"PASSWD",
|
|
15
|
+
"PASSWORD",
|
|
16
|
+
"PRIVATE",
|
|
17
|
+
"SECRET",
|
|
18
|
+
"TOKEN",
|
|
19
|
+
]);
|
|
20
|
+
/**
|
|
21
|
+
* Whether an environment variable's name says its value is a secret: one
|
|
22
|
+
* of its words, in any letter case, is a word such as `TOKEN`, `KEY` or
|
|
23
|
+
* `PASSWORD`. Words are split at each character that is not a letter or
|
|
24
|
+
* digit and before a capital letter that follows a small letter or digit.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* isSecretVariableName("ANTHROPIC_API_KEY"); // true
|
|
28
|
+
* isSecretVariableName("authToken"); // true
|
|
29
|
+
* isSecretVariableName("KEYMAP"); // false
|
|
30
|
+
*/
|
|
31
|
+
export function isSecretVariableName(name) {
|
|
32
|
+
const words = name.split(/[^A-Za-z0-9]+|(?<=[a-z0-9])(?=[A-Z])/);
|
|
33
|
+
return words.some((word) => secretWords.has(word.toUpperCase()));
|
|
34
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** A site's name, split so a screen can show the registrable domain apart. */
|
|
2
|
+
export interface SiteName {
|
|
3
|
+
/** The labels before the domain, with their last dot, such as `registry.`; empty when there are none. */
|
|
4
|
+
readonly prefix: string;
|
|
5
|
+
/** The registrable domain, such as `npmjs.org`, or the whole address of an IP host. */
|
|
6
|
+
readonly domain: string;
|
|
7
|
+
/** Whether the name was shortened to fit {@link siteNameMaxLength}; the text then holds `…`. */
|
|
8
|
+
readonly cut: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** The most characters `prefix` and `domain` hold together, `…` and escapes included. */
|
|
11
|
+
export declare const siteNameMaxLength = 64;
|
|
12
|
+
/**
|
|
13
|
+
* Writes a host name the way a screen shows a site (requirement
|
|
14
|
+
* `std.site-name`). It is lowercased and loses a trailing dot. Any character
|
|
15
|
+
* other than `a`–`z`, `0`–`9`, `.`, `-`, `:`, `[` and `]` is written as
|
|
16
|
+
* `\u{…}`, so a Cyrillic letter, a full-width dot or a bidi mark can't look
|
|
17
|
+
* like the real thing. Punycode (`xn--`) labels stay as they are, never
|
|
18
|
+
* decoded. `domain` is the registrable domain from our pinned copy of the
|
|
19
|
+
* public suffix list, private section included, looked up on the host's
|
|
20
|
+
* ASCII form so a suffix written in Unicode (`公司.cn`) is found; an IP
|
|
21
|
+
* address is all domain.
|
|
22
|
+
*
|
|
23
|
+
* A name longer than {@link siteNameMaxLength} keeps its domain whole and
|
|
24
|
+
* loses the middle of its prefix, or all of it when the domain alone fills
|
|
25
|
+
* the cap. A domain too long by itself loses its start.
|
|
26
|
+
* Either way `cut` is set and the text holds `…`.
|
|
27
|
+
*
|
|
28
|
+
* @param host - the host as the sandbox reported it, without a port
|
|
29
|
+
* @returns the plain-text parts to show; never a link
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* siteName("registry.npmjs.org.evil.example");
|
|
33
|
+
* // => { prefix: "registry.npmjs.org.", domain: "evil.example", cut: false }
|
|
34
|
+
*/
|
|
35
|
+
export declare function siteName(host: string): SiteName;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// A site's name as a screen shows it: plain text, capped in length, with the
|
|
2
|
+
// registrable domain apart so it can stand out. Julian's conditions for
|
|
3
|
+
// showing blocked and allowed sites (HAL-1673): a look-alike name must never
|
|
4
|
+
// pass for the real one, and a long name must never push the real domain out
|
|
5
|
+
// of sight.
|
|
6
|
+
import { asciiHost } from "./ascii-host.js";
|
|
7
|
+
import { registrableDomain } from "./registrable-domain.js";
|
|
8
|
+
/** The most characters `prefix` and `domain` hold together, `…` and escapes included. */
|
|
9
|
+
export const siteNameMaxLength = 64;
|
|
10
|
+
const ellipsis = "…";
|
|
11
|
+
/** The characters shown as they are; any other is escaped. */
|
|
12
|
+
const plainCharacter = /^[a-z0-9.\-:[\]]$/;
|
|
13
|
+
const ipv4 = /^\d{1,3}(?:\.\d{1,3}){3}$/;
|
|
14
|
+
/**
|
|
15
|
+
* Writes a host name the way a screen shows a site (requirement
|
|
16
|
+
* `std.site-name`). It is lowercased and loses a trailing dot. Any character
|
|
17
|
+
* other than `a`–`z`, `0`–`9`, `.`, `-`, `:`, `[` and `]` is written as
|
|
18
|
+
* `\u{…}`, so a Cyrillic letter, a full-width dot or a bidi mark can't look
|
|
19
|
+
* like the real thing. Punycode (`xn--`) labels stay as they are, never
|
|
20
|
+
* decoded. `domain` is the registrable domain from our pinned copy of the
|
|
21
|
+
* public suffix list, private section included, looked up on the host's
|
|
22
|
+
* ASCII form so a suffix written in Unicode (`公司.cn`) is found; an IP
|
|
23
|
+
* address is all domain.
|
|
24
|
+
*
|
|
25
|
+
* A name longer than {@link siteNameMaxLength} keeps its domain whole and
|
|
26
|
+
* loses the middle of its prefix, or all of it when the domain alone fills
|
|
27
|
+
* the cap. A domain too long by itself loses its start.
|
|
28
|
+
* Either way `cut` is set and the text holds `…`.
|
|
29
|
+
*
|
|
30
|
+
* @param host - the host as the sandbox reported it, without a port
|
|
31
|
+
* @returns the plain-text parts to show; never a link
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* siteName("registry.npmjs.org.evil.example");
|
|
35
|
+
* // => { prefix: "registry.npmjs.org.", domain: "evil.example", cut: false }
|
|
36
|
+
*/
|
|
37
|
+
export function siteName(host) {
|
|
38
|
+
const plainHost = host.endsWith(".") ? host.slice(0, -1) : host;
|
|
39
|
+
const tokens = shownCharacters(plainHost);
|
|
40
|
+
const text = tokens.join("");
|
|
41
|
+
const domainStart = isIpAddress(text) ? 0 : domainStartOf(tokens, plainHost);
|
|
42
|
+
const prefixTokens = tokens.slice(0, domainStart);
|
|
43
|
+
const domainTokens = tokens.slice(domainStart);
|
|
44
|
+
const domain = domainTokens.join("");
|
|
45
|
+
if (text.length <= siteNameMaxLength) {
|
|
46
|
+
return { prefix: prefixTokens.join(""), domain, cut: false };
|
|
47
|
+
}
|
|
48
|
+
if (domain.length === siteNameMaxLength)
|
|
49
|
+
return { prefix: "", domain, cut: true };
|
|
50
|
+
if (domain.length < siteNameMaxLength) {
|
|
51
|
+
return {
|
|
52
|
+
prefix: middleCut(prefixTokens, siteNameMaxLength - domain.length),
|
|
53
|
+
domain,
|
|
54
|
+
cut: true,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const kept = lastTokens(domainTokens, siteNameMaxLength - ellipsis.length);
|
|
58
|
+
return { prefix: "", domain: ellipsis + kept.join(""), cut: true };
|
|
59
|
+
}
|
|
60
|
+
/** The host's characters as shown: ASCII letters lowercased, others plain or escaped. */
|
|
61
|
+
function shownCharacters(host) {
|
|
62
|
+
return Array.from(host, (character) => {
|
|
63
|
+
const lower = /^[A-Z]$/.test(character) ? character.toLowerCase() : character;
|
|
64
|
+
if (plainCharacter.test(lower))
|
|
65
|
+
return lower;
|
|
66
|
+
const codePoint = lower.codePointAt(0) ?? 0;
|
|
67
|
+
return `\\u{${codePoint.toString(16)}}`;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function isIpAddress(text) {
|
|
71
|
+
return ipv4.test(text) || text.includes(":");
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Where the registrable domain starts in the shown tokens. The list is read
|
|
75
|
+
* on the ASCII form, which has the same labels: only a plain `.` separates
|
|
76
|
+
* them in both, and an escaped character is never one.
|
|
77
|
+
*/
|
|
78
|
+
function domainStartOf(tokens, host) {
|
|
79
|
+
const domainLabels = registrableDomain(asciiHost(host)).split(".").length;
|
|
80
|
+
let dots = 0;
|
|
81
|
+
for (let index = tokens.length - 1; index >= 0; index -= 1) {
|
|
82
|
+
if (tokens[index] !== ".")
|
|
83
|
+
continue;
|
|
84
|
+
dots += 1;
|
|
85
|
+
if (dots === domainLabels)
|
|
86
|
+
return index + 1;
|
|
87
|
+
}
|
|
88
|
+
return 0;
|
|
89
|
+
}
|
|
90
|
+
/** `tokens` in at most `budget` characters, with `…` in place of the middle. Never splits an escape. */
|
|
91
|
+
function middleCut(tokens, budget) {
|
|
92
|
+
const room = budget - ellipsis.length;
|
|
93
|
+
// The end gets the odd character, so a prefix keeps its last dot.
|
|
94
|
+
const tail = lastTokens(tokens, Math.ceil(room / 2));
|
|
95
|
+
const head = firstTokens(tokens, room - Math.ceil(room / 2));
|
|
96
|
+
return head.join("") + ellipsis + tail.join("");
|
|
97
|
+
}
|
|
98
|
+
function firstTokens(tokens, budget) {
|
|
99
|
+
const kept = [];
|
|
100
|
+
let characters = 0;
|
|
101
|
+
for (const token of tokens) {
|
|
102
|
+
if (characters + token.length > budget)
|
|
103
|
+
break;
|
|
104
|
+
kept.push(token);
|
|
105
|
+
characters += token.length;
|
|
106
|
+
}
|
|
107
|
+
return kept;
|
|
108
|
+
}
|
|
109
|
+
function lastTokens(tokens, budget) {
|
|
110
|
+
return firstTokens([...tokens].reverse(), budget).reverse();
|
|
111
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** The host of a URL, as a name or an address. */
|
|
2
|
+
export type UrlHost = {
|
|
3
|
+
readonly kind: "domain";
|
|
4
|
+
readonly name: string;
|
|
5
|
+
}
|
|
6
|
+
/** Four numbers from 0 to 255. */
|
|
7
|
+
| {
|
|
8
|
+
readonly kind: "ipv4";
|
|
9
|
+
readonly octets: readonly number[];
|
|
10
|
+
}
|
|
11
|
+
/** Eight numbers from 0 to 65535, the groups of the address in order. */
|
|
12
|
+
| {
|
|
13
|
+
readonly kind: "ipv6";
|
|
14
|
+
readonly groups: readonly number[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Reads the host of an `http` or `https` URL the way a browser would, for
|
|
18
|
+
* the cases that decide where a request goes: user info before an `@`, a
|
|
19
|
+
* port, a trailing dot, an IPv4 address written as `127.1`, `2130706433` or
|
|
20
|
+
* `0x7f.0.0.1`, and an IPv6 address in brackets. The core has no `URL`
|
|
21
|
+
* class, so it is read by hand.
|
|
22
|
+
*
|
|
23
|
+
* It does not give the full IDNA mapping, so a host with any non-ASCII
|
|
24
|
+
* character, a percent-encoded host, other schemes and anything it doesn't
|
|
25
|
+
* fully understand give `undefined`.
|
|
26
|
+
* Callers that need a safe answer treat that as "unknown".
|
|
27
|
+
*
|
|
28
|
+
* @param url - the URL as written
|
|
29
|
+
* @returns the host, or `undefined` when it is not an `http(s)` URL with a host this reader understands
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* urlHost("http://127.1:8080"); // { kind: "ipv4", octets: [127, 0, 0, 1] }
|
|
33
|
+
* urlHost("http://localhost@evil.example"); // { kind: "domain", name: "evil.example" }
|
|
34
|
+
*/
|
|
35
|
+
export declare function urlHost(url: string): UrlHost | undefined;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { asciiHost } from "./ascii-host.js";
|
|
2
|
+
const urlShape = /^(https?):\/\/([^/?#\\]*)/i;
|
|
3
|
+
const maxPort = 65535;
|
|
4
|
+
const forbiddenInDomain = /[\s#%/:<>?@[\\\]^|]/;
|
|
5
|
+
/**
|
|
6
|
+
* Reads the host of an `http` or `https` URL the way a browser would, for
|
|
7
|
+
* the cases that decide where a request goes: user info before an `@`, a
|
|
8
|
+
* port, a trailing dot, an IPv4 address written as `127.1`, `2130706433` or
|
|
9
|
+
* `0x7f.0.0.1`, and an IPv6 address in brackets. The core has no `URL`
|
|
10
|
+
* class, so it is read by hand.
|
|
11
|
+
*
|
|
12
|
+
* It does not give the full IDNA mapping, so a host with any non-ASCII
|
|
13
|
+
* character, a percent-encoded host, other schemes and anything it doesn't
|
|
14
|
+
* fully understand give `undefined`.
|
|
15
|
+
* Callers that need a safe answer treat that as "unknown".
|
|
16
|
+
*
|
|
17
|
+
* @param url - the URL as written
|
|
18
|
+
* @returns the host, or `undefined` when it is not an `http(s)` URL with a host this reader understands
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* urlHost("http://127.1:8080"); // { kind: "ipv4", octets: [127, 0, 0, 1] }
|
|
22
|
+
* urlHost("http://localhost@evil.example"); // { kind: "domain", name: "evil.example" }
|
|
23
|
+
*/
|
|
24
|
+
export function urlHost(url) {
|
|
25
|
+
const match = urlShape.exec(trimEdges(url));
|
|
26
|
+
if (match === null) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const authority = (match[2] ?? "").slice((match[2] ?? "").lastIndexOf("@") + 1);
|
|
30
|
+
if (authority.startsWith("[")) {
|
|
31
|
+
return ipv6Host(authority);
|
|
32
|
+
}
|
|
33
|
+
const colon = authority.indexOf(":");
|
|
34
|
+
const text = colon === -1 ? authority : authority.slice(0, colon);
|
|
35
|
+
if (colon !== -1 && !isPort(authority.slice(colon + 1))) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
return nameOrIpv4(text);
|
|
39
|
+
}
|
|
40
|
+
/** A port is digits only, or empty, and fits in 16 bits. */
|
|
41
|
+
function isPort(text) {
|
|
42
|
+
return /^\d*$/.test(text) && (text === "" || Number(text) <= maxPort);
|
|
43
|
+
}
|
|
44
|
+
function ipv6Host(authority) {
|
|
45
|
+
const end = authority.indexOf("]");
|
|
46
|
+
const after = authority.slice(end + 1);
|
|
47
|
+
if (end === -1 || !(after === "" || (after.startsWith(":") && isPort(after.slice(1))))) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const groups = parseIpv6(authority.slice(1, end));
|
|
51
|
+
return groups === undefined ? undefined : { kind: "ipv6", groups };
|
|
52
|
+
}
|
|
53
|
+
function nameOrIpv4(text) {
|
|
54
|
+
// Non-ASCII hosts would need the full IDNA mapping, so a wrong guess is worse than none.
|
|
55
|
+
if (text === "" ||
|
|
56
|
+
hasNonAscii(text) ||
|
|
57
|
+
forbiddenInDomain.test(text) ||
|
|
58
|
+
hasControlCharacter(text)) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const name = asciiHost(text.endsWith(".") ? text.slice(0, -1) : text);
|
|
62
|
+
const labels = name.split(".");
|
|
63
|
+
if (labels.some((label) => label === "")) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
if (!endsInNumber(labels)) {
|
|
67
|
+
return { kind: "domain", name };
|
|
68
|
+
}
|
|
69
|
+
const octets = parseIpv4(labels);
|
|
70
|
+
return octets === undefined ? undefined : { kind: "ipv4", octets };
|
|
71
|
+
}
|
|
72
|
+
/** A host whose last label is a number is an IPv4 address or nothing (WHATWG "ends in a number"). */
|
|
73
|
+
function endsInNumber(labels) {
|
|
74
|
+
const last = labels[labels.length - 1] ?? "";
|
|
75
|
+
return /^(\d+|0x[0-9a-f]*)$/.test(last);
|
|
76
|
+
}
|
|
77
|
+
function parseIpv4(labels) {
|
|
78
|
+
if (labels.length > 4) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
const numbers = labels.map(ipv4Number);
|
|
82
|
+
if (numbers.some((number) => number === undefined)) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
const values = numbers;
|
|
86
|
+
const last = values[values.length - 1];
|
|
87
|
+
const head = values.slice(0, -1);
|
|
88
|
+
if (head.some((value) => value > 255) || last >= 256 ** (5 - values.length)) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
let address = last;
|
|
92
|
+
head.forEach((value, index) => {
|
|
93
|
+
address += value * 256 ** (3 - index);
|
|
94
|
+
});
|
|
95
|
+
return [24, 16, 8, 0].map((shift) => Math.floor(address / 2 ** shift) % 256);
|
|
96
|
+
}
|
|
97
|
+
function ipv4Number(label) {
|
|
98
|
+
if (/^0x[0-9a-f]*$/.test(label)) {
|
|
99
|
+
return label.length === 2 ? 0 : Number.parseInt(label.slice(2), 16);
|
|
100
|
+
}
|
|
101
|
+
if (/^0[0-7]+$/.test(label)) {
|
|
102
|
+
return Number.parseInt(label, 8);
|
|
103
|
+
}
|
|
104
|
+
// A leading 0 means octal, so `09` is not a number.
|
|
105
|
+
return /^(0|[1-9]\d*)$/.test(label) ? Number.parseInt(label, 10) : undefined;
|
|
106
|
+
}
|
|
107
|
+
function parseIpv6(text) {
|
|
108
|
+
const sides = text.split("::");
|
|
109
|
+
if (sides.length > 2) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
const head = groupsOf(sides[0] ?? "", sides.length === 1);
|
|
113
|
+
const tail = sides.length === 2 ? groupsOf(sides[1] ?? "", true) : [];
|
|
114
|
+
if (head === undefined || tail === undefined) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
if (sides.length === 1) {
|
|
118
|
+
return head.length === 8 ? head : undefined;
|
|
119
|
+
}
|
|
120
|
+
const missing = 8 - head.length - tail.length;
|
|
121
|
+
return missing < 1 ? undefined : [...head, ...new Array(missing).fill(0), ...tail];
|
|
122
|
+
}
|
|
123
|
+
/** The groups of one side of an IPv6 address; the end of the address may be an IPv4 address that makes two. */
|
|
124
|
+
function groupsOf(side, endsAddress) {
|
|
125
|
+
if (side === "") {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
const parts = side.split(":");
|
|
129
|
+
const groups = [];
|
|
130
|
+
for (const [index, part] of parts.entries()) {
|
|
131
|
+
if (index === parts.length - 1 && part.includes(".")) {
|
|
132
|
+
const octets = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
|
|
133
|
+
.exec(part)
|
|
134
|
+
?.slice(1)
|
|
135
|
+
.map(Number);
|
|
136
|
+
if (!endsAddress || octets === undefined || octets.some((octet) => octet > 255)) {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
groups.push(octets[0] * 256 + octets[1], octets[2] * 256 + octets[3]);
|
|
140
|
+
}
|
|
141
|
+
else if (/^[0-9a-f]{1,4}$/i.test(part)) {
|
|
142
|
+
groups.push(Number.parseInt(part, 16));
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return groups;
|
|
149
|
+
}
|
|
150
|
+
function hasControlCharacter(text) {
|
|
151
|
+
return [...text].some((character) => {
|
|
152
|
+
const code = character.codePointAt(0) ?? 0;
|
|
153
|
+
return code < 0x20 || code === 0x7f;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/** What the URL rules strip from both ends: control characters and the space, not Unicode spaces. */
|
|
157
|
+
function trimEdges(text) {
|
|
158
|
+
let start = 0;
|
|
159
|
+
let end = text.length;
|
|
160
|
+
while (start < end && text.charCodeAt(start) <= 0x20) {
|
|
161
|
+
start += 1;
|
|
162
|
+
}
|
|
163
|
+
while (end > start && text.charCodeAt(end - 1) <= 0x20) {
|
|
164
|
+
end -= 1;
|
|
165
|
+
}
|
|
166
|
+
return text.slice(start, end);
|
|
167
|
+
}
|
|
168
|
+
function hasNonAscii(text) {
|
|
169
|
+
return [...text].some((character) => (character.codePointAt(0) ?? 0) > 0x7f);
|
|
170
|
+
}
|
|
@@ -16,7 +16,9 @@ export function loadSubject(subject, transport, tokens = emptyTokens) {
|
|
|
16
16
|
// The canary store answers by name, so each secret is picked as itself.
|
|
17
17
|
secretNames: Object.fromEntries(Object.keys(sheet.secrets).map((name) => [name, name])),
|
|
18
18
|
},
|
|
19
|
-
|
|
19
|
+
// A replay answers from the recording and never connects anywhere, so
|
|
20
|
+
// there is no address to check.
|
|
21
|
+
transport: transport,
|
|
20
22
|
secrets: canarySecrets,
|
|
21
23
|
tokens,
|
|
22
24
|
capabilities: sheet.needs,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@halonicjs/testing",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Halonic's test suites for code outside the engine. @halonicjs/testing/integration is the conformance suite every integration runs against recorded responses, with its attack cases.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"NOTICE"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@halonicjs/adapters": "0.1.
|
|
26
|
+
"@halonicjs/adapters": "0.1.1",
|
|
27
27
|
"yaml": "2.9.1",
|
|
28
28
|
"zod": "4.6.7"
|
|
29
29
|
},
|