@halonicjs/testing 0.0.0 → 0.1.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/LICENSE +202 -0
- package/NOTICE +1 -0
- package/README.md +41 -1
- package/dist/adapters/http-kit/src/address-class.d.ts +34 -0
- package/dist/adapters/http-kit/src/address-class.js +109 -0
- package/dist/adapters/http-kit/src/index.d.ts +2 -0
- package/dist/adapters/http-kit/src/index.js +2 -0
- package/dist/adapters/http-kit/src/ip-address.d.ts +23 -0
- package/dist/adapters/http-kit/src/ip-address.js +89 -0
- package/dist/adapters/integration-kit/src/declaration.d.ts +14 -0
- package/dist/adapters/integration-kit/src/declaration.js +77 -0
- package/dist/adapters/integration-kit/src/host.d.ts +28 -0
- package/dist/adapters/integration-kit/src/host.js +30 -0
- package/dist/adapters/integration-kit/src/index.d.ts +14 -0
- package/dist/adapters/integration-kit/src/index.js +21 -0
- package/dist/adapters/integration-kit/src/leak-attempt.d.ts +14 -0
- package/dist/adapters/integration-kit/src/leak-attempt.js +16 -0
- package/dist/adapters/integration-kit/src/limited-http.d.ts +49 -0
- package/dist/adapters/integration-kit/src/limited-http.js +182 -0
- package/dist/adapters/integration-kit/src/load-problem.d.ts +20 -0
- package/dist/adapters/integration-kit/src/load-problem.js +1 -0
- package/dist/adapters/integration-kit/src/loader.d.ts +104 -0
- package/dist/adapters/integration-kit/src/loader.js +219 -0
- package/dist/adapters/integration-kit/src/local-address.d.ts +15 -0
- package/dist/adapters/integration-kit/src/local-address.js +25 -0
- package/dist/adapters/integration-kit/src/own-request.d.ts +33 -0
- package/dist/adapters/integration-kit/src/own-request.js +36 -0
- package/dist/adapters/integration-kit/src/plugin-load.d.ts +14 -0
- package/dist/adapters/integration-kit/src/plugin-load.js +58 -0
- package/dist/adapters/integration-kit/src/policy.d.ts +55 -0
- package/dist/adapters/integration-kit/src/policy.js +37 -0
- package/dist/adapters/integration-kit/src/request-body.d.ts +38 -0
- package/dist/adapters/integration-kit/src/request-body.js +68 -0
- package/dist/adapters/integration-kit/src/request-log.d.ts +25 -0
- package/dist/adapters/integration-kit/src/request-log.js +17 -0
- package/dist/adapters/integration-kit/src/response-body.d.ts +23 -0
- package/dist/adapters/integration-kit/src/response-body.js +117 -0
- package/dist/adapters/integration-kit/src/scoped-tokens.d.ts +14 -0
- package/dist/adapters/integration-kit/src/scoped-tokens.js +27 -0
- package/dist/adapters/integration-kit/src/secret-filter.d.ts +84 -0
- package/dist/adapters/integration-kit/src/secret-filter.js +205 -0
- package/dist/adapters/integration-kit/src/secret-in-request.d.ts +59 -0
- package/dist/adapters/integration-kit/src/secret-in-request.js +133 -0
- package/dist/adapters/integration-kit/src/secret-placement.d.ts +36 -0
- package/dist/adapters/integration-kit/src/secret-placement.js +190 -0
- package/dist/adapters/integration-kit/src/wait.d.ts +16 -0
- package/dist/adapters/integration-kit/src/wait.js +35 -0
- package/dist/core/events/src/add-usage.d.ts +10 -0
- package/dist/core/events/src/add-usage.js +27 -0
- package/dist/core/events/src/agent-resume.d.ts +24 -0
- package/dist/core/events/src/agent-resume.js +1 -0
- package/dist/core/events/src/home-path.d.ts +13 -0
- package/dist/core/events/src/home-path.js +26 -0
- package/dist/core/events/src/index.d.ts +13 -0
- package/dist/core/events/src/index.js +7 -0
- package/dist/core/events/src/run-basics.d.ts +205 -0
- package/dist/core/events/src/run-basics.js +1 -0
- package/dist/core/events/src/run-event.d.ts +434 -0
- package/dist/core/events/src/run-event.js +1 -0
- package/dist/core/events/src/run-summary.d.ts +108 -0
- package/dist/core/events/src/run-summary.js +1 -0
- package/dist/core/events/src/sandbox-blocked.d.ts +42 -0
- package/dist/core/events/src/sandbox-blocked.js +26 -0
- package/dist/core/events/src/sandbox-opened-read.d.ts +17 -0
- package/dist/core/events/src/sandbox-opened-read.js +63 -0
- package/dist/core/events/src/sandbox-opened.d.ts +94 -0
- package/dist/core/events/src/sandbox-opened.js +52 -0
- package/dist/core/events/src/summarize.d.ts +14 -0
- package/dist/core/events/src/summarize.js +188 -0
- package/dist/core/events/src/timeline-entry.d.ts +21 -0
- package/dist/core/events/src/timeline-entry.js +105 -0
- package/dist/core/events/src/upgrade.d.ts +23 -0
- package/dist/core/events/src/upgrade.js +49 -0
- package/dist/core/format/src/compact.d.ts +30 -0
- package/dist/core/format/src/compact.js +72 -0
- package/dist/core/format/src/index.d.ts +37 -0
- package/dist/core/format/src/index.js +23 -0
- package/dist/core/format/src/integration/index.d.ts +6 -0
- package/dist/core/format/src/integration/index.js +9 -0
- package/dist/core/format/src/json-schema.d.ts +26 -0
- package/dist/core/format/src/json-schema.js +48 -0
- package/dist/core/format/src/kind.d.ts +65 -0
- package/dist/core/format/src/kind.js +1 -0
- package/dist/core/format/src/kinds/agent/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/agent/kind.js +10 -0
- package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +89 -0
- package/dist/core/format/src/kinds/agent/sandbox-fields.js +197 -0
- package/dist/core/format/src/kinds/agent/schema.d.ts +147 -0
- package/dist/core/format/src/kinds/agent/schema.js +107 -0
- package/dist/core/format/src/kinds/agent/working-folder-start.d.ts +74 -0
- package/dist/core/format/src/kinds/agent/working-folder-start.js +312 -0
- package/dist/core/format/src/kinds/collection/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/collection/kind.js +14 -0
- package/dist/core/format/src/kinds/collection/schema.d.ts +89 -0
- package/dist/core/format/src/kinds/collection/schema.js +90 -0
- package/dist/core/format/src/kinds/connector/is-local.d.ts +10 -0
- package/dist/core/format/src/kinds/connector/is-local.js +43 -0
- package/dist/core/format/src/kinds/connector/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/connector/kind.js +119 -0
- package/dist/core/format/src/kinds/connector/schema.d.ts +50 -0
- package/dist/core/format/src/kinds/connector/schema.js +92 -0
- package/dist/core/format/src/kinds/deployments/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/deployments/kind.js +25 -0
- package/dist/core/format/src/kinds/deployments/schema.d.ts +37 -0
- package/dist/core/format/src/kinds/deployments/schema.js +42 -0
- package/dist/core/format/src/kinds/hub/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/hub/kind.js +10 -0
- package/dist/core/format/src/kinds/hub/schema.d.ts +54 -0
- package/dist/core/format/src/kinds/hub/schema.js +34 -0
- package/dist/core/format/src/kinds/integration/kind.d.ts +16 -0
- package/dist/core/format/src/kinds/integration/kind.js +138 -0
- package/dist/core/format/src/kinds/integration/parse-sheet.d.ts +19 -0
- package/dist/core/format/src/kinds/integration/parse-sheet.js +24 -0
- package/dist/core/format/src/kinds/integration/policy.d.ts +67 -0
- package/dist/core/format/src/kinds/integration/policy.js +268 -0
- package/dist/core/format/src/kinds/integration/schema.d.ts +233 -0
- package/dist/core/format/src/kinds/integration/schema.js +233 -0
- package/dist/core/format/src/kinds/knowledge/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/knowledge/kind.js +13 -0
- package/dist/core/format/src/kinds/knowledge/schema.d.ts +18 -0
- package/dist/core/format/src/kinds/knowledge/schema.js +25 -0
- package/dist/core/format/src/kinds/models/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/models/kind.js +10 -0
- package/dist/core/format/src/kinds/models/schema.d.ts +92 -0
- package/dist/core/format/src/kinds/models/schema.js +38 -0
- package/dist/core/format/src/kinds/plugin/backend.d.ts +22 -0
- package/dist/core/format/src/kinds/plugin/backend.js +31 -0
- package/dist/core/format/src/kinds/plugin/checks.d.ts +13 -0
- package/dist/core/format/src/kinds/plugin/checks.js +131 -0
- package/dist/core/format/src/kinds/plugin/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/plugin/kind.js +16 -0
- package/dist/core/format/src/kinds/plugin/problems.d.ts +24 -0
- package/dist/core/format/src/kinds/plugin/problems.js +65 -0
- package/dist/core/format/src/kinds/plugin/schema.d.ts +542 -0
- package/dist/core/format/src/kinds/plugin/schema.js +261 -0
- package/dist/core/format/src/kinds/plugin/setting-values.d.ts +17 -0
- package/dist/core/format/src/kinds/plugin/setting-values.js +38 -0
- package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +8 -0
- package/dist/core/format/src/kinds/plugin/ui-checks.js +94 -0
- package/dist/core/format/src/kinds/provider/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/provider/kind.js +24 -0
- package/dist/core/format/src/kinds/provider/schema.d.ts +17 -0
- package/dist/core/format/src/kinds/provider/schema.js +22 -0
- package/dist/core/format/src/kinds/routine/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/routine/kind.js +25 -0
- package/dist/core/format/src/kinds/routine/schema.d.ts +84 -0
- package/dist/core/format/src/kinds/routine/schema.js +93 -0
- package/dist/core/format/src/kinds/runtime/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/runtime/kind.js +13 -0
- package/dist/core/format/src/kinds/runtime/schema.d.ts +10 -0
- package/dist/core/format/src/kinds/runtime/schema.js +12 -0
- package/dist/core/format/src/kinds/skill/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/skill/kind.js +10 -0
- package/dist/core/format/src/kinds/skill/schema.d.ts +17 -0
- package/dist/core/format/src/kinds/skill/schema.js +17 -0
- package/dist/core/format/src/kinds/skill/scripts-folder.d.ts +27 -0
- package/dist/core/format/src/kinds/skill/scripts-folder.js +37 -0
- package/dist/core/format/src/kinds/workflow/kind.d.ts +8 -0
- package/dist/core/format/src/kinds/workflow/kind.js +14 -0
- package/dist/core/format/src/kinds/workflow/schema.d.ts +162 -0
- package/dist/core/format/src/kinds/workflow/schema.js +106 -0
- package/dist/core/format/src/kinds/workflow-test/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/workflow-test/kind.js +14 -0
- package/dist/core/format/src/kinds/workflow-test/schema.d.ts +67 -0
- package/dist/core/format/src/kinds/workflow-test/schema.js +59 -0
- package/dist/core/format/src/kinds/workspace/kind.d.ts +4 -0
- package/dist/core/format/src/kinds/workspace/kind.js +10 -0
- package/dist/core/format/src/kinds/workspace/schema.d.ts +72 -0
- package/dist/core/format/src/kinds/workspace/schema.js +66 -0
- package/dist/core/format/src/parse-file.d.ts +69 -0
- package/dist/core/format/src/parse-file.js +105 -0
- package/dist/core/format/src/recording/format.d.ts +81 -0
- package/dist/core/format/src/recording/format.js +102 -0
- package/dist/core/format/src/recording/index.d.ts +1 -0
- package/dist/core/format/src/recording/index.js +3 -0
- package/dist/core/format/src/registry.d.ts +64 -0
- package/dist/core/format/src/registry.js +61 -0
- package/dist/core/format/src/reserved.d.ts +20 -0
- package/dist/core/format/src/reserved.js +30 -0
- package/dist/core/format/src/shared/fields.d.ts +37 -0
- package/dist/core/format/src/shared/fields.js +54 -0
- package/dist/core/format/src/shared/guard.d.ts +32 -0
- package/dist/core/format/src/shared/guard.js +16 -0
- package/dist/core/format/src/shared/key-in-value.d.ts +28 -0
- package/dist/core/format/src/shared/key-in-value.js +82 -0
- package/dist/core/format/src/shared/legacy-keys.d.ts +8 -0
- package/dist/core/format/src/shared/legacy-keys.js +17 -0
- package/dist/core/format/src/shared/program-start.d.ts +60 -0
- package/dist/core/format/src/shared/program-start.js +99 -0
- package/dist/core/format/src/shared/relative-path.d.ts +29 -0
- package/dist/core/format/src/shared/relative-path.js +50 -0
- package/dist/core/format/src/shared/secret-name.d.ts +24 -0
- package/dist/core/format/src/shared/secret-name.js +107 -0
- package/dist/core/format/src/source.d.ts +16 -0
- package/dist/core/format/src/source.js +73 -0
- package/dist/core/ports/src/agent-placement-store.d.ts +74 -0
- package/dist/core/ports/src/agent-placement-store.js +27 -0
- package/dist/core/ports/src/blob-store.d.ts +33 -0
- package/dist/core/ports/src/blob-store.js +2 -0
- package/dist/core/ports/src/cant-try-error.d.ts +35 -0
- package/dist/core/ports/src/cant-try-error.js +44 -0
- package/dist/core/ports/src/chat.d.ts +127 -0
- package/dist/core/ports/src/chat.js +1 -0
- package/dist/core/ports/src/clock.d.ts +7 -0
- package/dist/core/ports/src/clock.js +2 -0
- package/dist/core/ports/src/connection-settings-store.d.ts +57 -0
- package/dist/core/ports/src/connection-settings-store.js +2 -0
- package/dist/core/ports/src/connector-client.d.ts +259 -0
- package/dist/core/ports/src/connector-client.js +2 -0
- package/dist/core/ports/src/coordination.d.ts +84 -0
- package/dist/core/ports/src/coordination.js +2 -0
- package/dist/core/ports/src/definition-store.d.ts +208 -0
- package/dist/core/ports/src/definition-store.js +122 -0
- package/dist/core/ports/src/digest.d.ts +14 -0
- package/dist/core/ports/src/digest.js +2 -0
- package/dist/core/ports/src/folder-reader.d.ts +89 -0
- package/dist/core/ports/src/folder-reader.js +2 -0
- package/dist/core/ports/src/harness-bridge-server.d.ts +189 -0
- package/dist/core/ports/src/harness-bridge-server.js +37 -0
- package/dist/core/ports/src/harness.d.ts +250 -0
- package/dist/core/ports/src/harness.js +45 -0
- package/dist/core/ports/src/http-client.d.ts +27 -0
- package/dist/core/ports/src/http-client.js +2 -0
- package/dist/core/ports/src/id-generator.d.ts +14 -0
- package/dist/core/ports/src/id-generator.js +2 -0
- package/dist/core/ports/src/index.d.ts +37 -0
- package/dist/core/ports/src/index.js +36 -0
- package/dist/core/ports/src/integration.d.ts +178 -0
- package/dist/core/ports/src/integration.js +13 -0
- package/dist/core/ports/src/knowledge-provider.d.ts +65 -0
- package/dist/core/ports/src/knowledge-provider.js +2 -0
- package/dist/core/ports/src/llm-cache.d.ts +13 -0
- package/dist/core/ports/src/llm-cache.js +2 -0
- package/dist/core/ports/src/llm-provider.d.ts +184 -0
- package/dist/core/ports/src/llm-provider.js +136 -0
- package/dist/core/ports/src/model-price.d.ts +34 -0
- package/dist/core/ports/src/model-price.js +25 -0
- package/dist/core/ports/src/password-hasher.d.ts +47 -0
- package/dist/core/ports/src/password-hasher.js +2 -0
- package/dist/core/ports/src/plugin-folder-writer.d.ts +104 -0
- package/dist/core/ports/src/plugin-folder-writer.js +95 -0
- package/dist/core/ports/src/port-versions.d.ts +44 -0
- package/dist/core/ports/src/port-versions.js +74 -0
- package/dist/core/ports/src/program-probe.d.ts +46 -0
- package/dist/core/ports/src/program-probe.js +2 -0
- package/dist/core/ports/src/record-store.d.ts +62 -0
- package/dist/core/ports/src/record-store.js +38 -0
- package/dist/core/ports/src/resource-probe.d.ts +59 -0
- package/dist/core/ports/src/resource-probe.js +2 -0
- package/dist/core/ports/src/run-executor.d.ts +302 -0
- package/dist/core/ports/src/run-executor.js +2 -0
- package/dist/core/ports/src/run-failure-error.d.ts +49 -0
- package/dist/core/ports/src/run-failure-error.js +47 -0
- package/dist/core/ports/src/run-store.d.ts +194 -0
- package/dist/core/ports/src/run-store.js +131 -0
- package/dist/core/ports/src/sandbox.d.ts +247 -0
- package/dist/core/ports/src/sandbox.js +34 -0
- package/dist/core/ports/src/scheduler.d.ts +85 -0
- package/dist/core/ports/src/scheduler.js +2 -0
- package/dist/core/ports/src/secrets.d.ts +128 -0
- package/dist/core/ports/src/secrets.js +144 -0
- package/dist/core/ports/src/token-store.d.ts +19 -0
- package/dist/core/ports/src/token-store.js +2 -0
- package/dist/core/ports/src/tool-approval-store.d.ts +211 -0
- package/dist/core/ports/src/tool-approval-store.js +57 -0
- package/dist/core/ports/src/trust-store.d.ts +72 -0
- package/dist/core/ports/src/trust-store.js +2 -0
- package/dist/core/ports/src/unfenced-run-consent-store.d.ts +43 -0
- package/dist/core/ports/src/unfenced-run-consent-store.js +2 -0
- package/dist/core/ports/src/vcs.d.ts +394 -0
- package/dist/core/ports/src/vcs.js +48 -0
- package/dist/core/schema-kit/src/builders.d.ts +50 -0
- package/dist/core/schema-kit/src/builders.js +72 -0
- package/dist/core/schema-kit/src/depth.d.ts +15 -0
- package/dist/core/schema-kit/src/depth.js +37 -0
- package/dist/core/schema-kit/src/index.d.ts +6 -0
- package/dist/core/schema-kit/src/index.js +6 -0
- package/dist/core/schema-kit/src/issue.d.ts +22 -0
- package/dist/core/schema-kit/src/issue.js +23 -0
- package/dist/core/schema-kit/src/json-schema.d.ts +23 -0
- package/dist/core/schema-kit/src/json-schema.js +22 -0
- package/dist/core/schema-kit/src/parse.d.ts +17 -0
- package/dist/core/schema-kit/src/parse.js +25 -0
- package/dist/core/schema-kit/src/schema.d.ts +12 -0
- package/dist/core/schema-kit/src/schema.js +1 -0
- package/dist/core/std/src/ascii-host.d.ts +18 -0
- package/dist/core/std/src/ascii-host.js +110 -0
- package/dist/core/std/src/assert.d.ts +39 -0
- package/dist/core/std/src/assert.js +59 -0
- package/dist/core/std/src/base64url.d.ts +23 -0
- package/dist/core/std/src/base64url.js +65 -0
- package/dist/core/std/src/canonical-json.d.ts +18 -0
- package/dist/core/std/src/canonical-json.js +56 -0
- package/dist/core/std/src/clock.d.ts +27 -0
- package/dist/core/std/src/clock.js +33 -0
- package/dist/core/std/src/constant-time.d.ts +16 -0
- package/dist/core/std/src/constant-time.js +26 -0
- package/dist/core/std/src/content-digest.d.ts +24 -0
- package/dist/core/std/src/content-digest.js +28 -0
- package/dist/core/std/src/deep-clone.d.ts +15 -0
- package/dist/core/std/src/deep-clone.js +59 -0
- package/dist/core/std/src/deep-equal.d.ts +23 -0
- package/dist/core/std/src/deep-equal.js +64 -0
- package/dist/core/std/src/emitter.d.ts +42 -0
- package/dist/core/std/src/emitter.js +74 -0
- package/dist/core/std/src/error-kind.d.ts +88 -0
- package/dist/core/std/src/error-kind.js +98 -0
- package/dist/core/std/src/hex.d.ts +10 -0
- package/dist/core/std/src/hex.js +16 -0
- package/dist/core/std/src/ids.d.ts +45 -0
- package/dist/core/std/src/ids.js +49 -0
- package/dist/core/std/src/index.d.ts +25 -0
- package/dist/core/std/src/index.js +26 -0
- package/dist/core/std/src/keyed-queue.d.ts +18 -0
- package/dist/core/std/src/keyed-queue.js +32 -0
- package/dist/core/std/src/line-diff.d.ts +83 -0
- package/dist/core/std/src/line-diff.js +179 -0
- package/dist/core/std/src/line-merge.d.ts +63 -0
- package/dist/core/std/src/line-merge.js +138 -0
- package/dist/core/std/src/plain-data.d.ts +32 -0
- package/dist/core/std/src/plain-data.js +57 -0
- package/dist/core/std/src/posix-path.d.ts +61 -0
- package/dist/core/std/src/posix-path.js +121 -0
- package/dist/core/std/src/result.d.ts +55 -0
- package/dist/core/std/src/result.js +52 -0
- package/dist/core/std/src/secret-scrubber.d.ts +54 -0
- package/dist/core/std/src/secret-scrubber.js +124 -0
- package/dist/core/std/src/secret-shape.d.ts +20 -0
- package/dist/core/std/src/secret-shape.js +53 -0
- package/dist/core/std/src/stop-signal.d.ts +44 -0
- package/dist/core/std/src/stop-signal.js +77 -0
- package/dist/core/std/src/text.d.ts +28 -0
- package/dist/core/std/src/text.js +54 -0
- package/dist/core/std/src/utf8.d.ts +23 -0
- package/dist/core/std/src/utf8.js +110 -0
- package/dist/core/std/src/version.d.ts +48 -0
- package/dist/core/std/src/version.js +103 -0
- package/dist/core/yaml/src/depth.d.ts +14 -0
- package/dist/core/yaml/src/depth.js +140 -0
- package/dist/core/yaml/src/edit-data.d.ts +47 -0
- package/dist/core/yaml/src/edit-data.js +286 -0
- package/dist/core/yaml/src/edit-text.d.ts +92 -0
- package/dist/core/yaml/src/edit-text.js +267 -0
- package/dist/core/yaml/src/edit.d.ts +47 -0
- package/dist/core/yaml/src/edit.js +198 -0
- package/dist/core/yaml/src/index.d.ts +5 -0
- package/dist/core/yaml/src/index.js +4 -0
- package/dist/core/yaml/src/problem.d.ts +20 -0
- package/dist/core/yaml/src/problem.js +1 -0
- package/dist/core/yaml/src/read.d.ts +47 -0
- package/dist/core/yaml/src/read.js +130 -0
- package/dist/core/yaml/src/splice-node.d.ts +47 -0
- package/dist/core/yaml/src/splice-node.js +333 -0
- package/dist/core/yaml/src/splice.d.ts +13 -0
- package/dist/core/yaml/src/splice.js +174 -0
- package/dist/core/yaml/src/unsupported.d.ts +26 -0
- package/dist/core/yaml/src/unsupported.js +70 -0
- package/dist/core/yaml/src/write.d.ts +35 -0
- package/dist/core/yaml/src/write.js +44 -0
- package/dist/testing/integration/src/canaries.d.ts +14 -0
- package/dist/testing/integration/src/canaries.js +17 -0
- package/dist/testing/integration/src/checks.d.ts +37 -0
- package/dist/testing/integration/src/checks.js +195 -0
- package/dist/testing/integration/src/describe.d.ts +35 -0
- package/dist/testing/integration/src/describe.js +74 -0
- package/dist/testing/integration/src/failure.d.ts +6 -0
- package/dist/testing/integration/src/failure.js +8 -0
- package/dist/testing/integration/src/fake-wait.d.ts +18 -0
- package/dist/testing/integration/src/fake-wait.js +21 -0
- package/dist/testing/integration/src/index.d.ts +10 -0
- package/dist/testing/integration/src/index.js +11 -0
- package/dist/testing/integration/src/load.d.ts +14 -0
- package/dist/testing/integration/src/load.js +45 -0
- package/dist/testing/integration/src/plugin-folder.d.ts +23 -0
- package/dist/testing/integration/src/plugin-folder.js +59 -0
- package/dist/testing/integration/src/plugin.d.ts +32 -0
- package/dist/testing/integration/src/plugin.js +57 -0
- package/dist/testing/integration/src/recording.d.ts +84 -0
- package/dist/testing/integration/src/recording.js +164 -0
- package/dist/testing/integration/src/run.d.ts +60 -0
- package/dist/testing/integration/src/run.js +81 -0
- package/dist/testing/integration/src/source-scan.d.ts +16 -0
- package/dist/testing/integration/src/source-scan.js +40 -0
- package/package.json +34 -3
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { SecretPlacement } from "../../../core/ports/src/index.js";
|
|
2
|
+
import { secretRemoved } from "../../../core/std/src/index.js";
|
|
3
|
+
/** What a secret value is replaced with wherever the filter finds it. */
|
|
4
|
+
export { secretRemoved };
|
|
5
|
+
/** A secret value, and where the kit placed it, if it did. */
|
|
6
|
+
export interface SecretOnWire {
|
|
7
|
+
readonly value: string;
|
|
8
|
+
/** How the kit put it in a request, so the placed forms are matched whole. */
|
|
9
|
+
readonly placements?: readonly SecretPlacement[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Every form of a set of secrets the filter looks for, longest first. Build
|
|
13
|
+
* it once with {@link secretForms} and pass it to {@link removeSecrets} or
|
|
14
|
+
* {@link SecretRemover}. Only {@link secretForms} makes one: `texts`, `bytes`
|
|
15
|
+
* and `longest` must agree, or the filter misses a form.
|
|
16
|
+
*/
|
|
17
|
+
export interface SecretForms {
|
|
18
|
+
readonly texts: readonly string[];
|
|
19
|
+
/** The same forms as UTF-8 bytes, for bodies. */
|
|
20
|
+
readonly bytes: readonly Uint8Array[];
|
|
21
|
+
/** The length in bytes of the longest form, or 0 when there are none. */
|
|
22
|
+
readonly longest: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The forms of each secret the filter matches: the raw value; the exact
|
|
26
|
+
* text the kit put on the wire (`Bearer <value>`, the header prefix plus the
|
|
27
|
+
* value, `field=<form-encoded value>`); and the URL-encoded, form-encoded
|
|
28
|
+
* and JSON-escaped copies of each. Base64, reversed, split or otherwise
|
|
29
|
+
* transformed copies are not matched: a host allowed to receive a key can
|
|
30
|
+
* always send it back in some other form.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const forms = secretForms([{ value: key, placements: [{ secret: "example-key", as: "bearer" }] }]);
|
|
34
|
+
* removeSecrets(`{"auth":"Bearer ${key}"}`, forms); // '{"auth":"[secret removed]"}'
|
|
35
|
+
*/
|
|
36
|
+
export declare function secretForms(secrets: Iterable<SecretOnWire>): SecretForms;
|
|
37
|
+
/**
|
|
38
|
+
* The text with every form of the secrets replaced by `[secret removed]`.
|
|
39
|
+
* For headers, URLs, tool results, error messages and log lines.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* removeSecrets(String(error), forms)
|
|
43
|
+
*/
|
|
44
|
+
export declare function removeSecrets(text: string, forms: SecretForms): string;
|
|
45
|
+
/**
|
|
46
|
+
* The error with every form of the secrets removed from its message, its
|
|
47
|
+
* stack and its causes. A kit error can repeat a URL a server chose, such as
|
|
48
|
+
* a redirect target, so every error leaving a request goes through here.
|
|
49
|
+
* The error is changed in place, so its class and `code` stay; one that
|
|
50
|
+
* can't be changed is replaced by a plain `Error` with the filtered message.
|
|
51
|
+
*/
|
|
52
|
+
export declare function removeSecretsFromError(error: unknown, forms: SecretForms): unknown;
|
|
53
|
+
/**
|
|
54
|
+
* Removes the secrets from a body that arrives in pieces, without holding
|
|
55
|
+
* the whole body. It holds back the last `longest form − 1` bytes of each
|
|
56
|
+
* piece, so a value split across two pieces is still found.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const remover = new SecretRemover(forms);
|
|
60
|
+
* for (const piece of pieces) send(remover.push(piece));
|
|
61
|
+
* send(remover.flush());
|
|
62
|
+
*/
|
|
63
|
+
export declare class SecretRemover {
|
|
64
|
+
#private;
|
|
65
|
+
constructor(forms: SecretForms);
|
|
66
|
+
/** How many secrets it has replaced so far. */
|
|
67
|
+
get removed(): number;
|
|
68
|
+
/** The filtered bytes that are safe to pass on; may be empty while bytes are held back. */
|
|
69
|
+
push(piece: Uint8Array): Uint8Array;
|
|
70
|
+
/** The filtered bytes still held back, at the end of the body. */
|
|
71
|
+
flush(): Uint8Array;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A stream step that removes the secrets, for the bridge's stderr and log.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* runner.stderr.pipeThrough(removeSecretsStream(forms))
|
|
78
|
+
*/
|
|
79
|
+
export declare function removeSecretsStream(forms: SecretForms): TransformStream<Uint8Array, Uint8Array>;
|
|
80
|
+
/**
|
|
81
|
+
* The headers with the secrets removed from every value. A header whose
|
|
82
|
+
* name holds a secret is left out, because a name can't hold the marker.
|
|
83
|
+
*/
|
|
84
|
+
export declare function removeSecretsFromHeaders(headers: Headers, forms: SecretForms): Headers;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { secretRemoved, secretTextForms } from "../../../core/std/src/index.js";
|
|
2
|
+
/** What a secret value is replaced with wherever the filter finds it. */
|
|
3
|
+
export { secretRemoved };
|
|
4
|
+
const utf8 = new TextEncoder();
|
|
5
|
+
const removedBytes = utf8.encode(secretRemoved);
|
|
6
|
+
/**
|
|
7
|
+
* The forms of each secret the filter matches: the raw value; the exact
|
|
8
|
+
* text the kit put on the wire (`Bearer <value>`, the header prefix plus the
|
|
9
|
+
* value, `field=<form-encoded value>`); and the URL-encoded, form-encoded
|
|
10
|
+
* and JSON-escaped copies of each. Base64, reversed, split or otherwise
|
|
11
|
+
* transformed copies are not matched: a host allowed to receive a key can
|
|
12
|
+
* always send it back in some other form.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const forms = secretForms([{ value: key, placements: [{ secret: "example-key", as: "bearer" }] }]);
|
|
16
|
+
* removeSecrets(`{"auth":"Bearer ${key}"}`, forms); // '{"auth":"[secret removed]"}'
|
|
17
|
+
*/
|
|
18
|
+
export function secretForms(secrets) {
|
|
19
|
+
const texts = new Set();
|
|
20
|
+
for (const { value, placements = [] } of secrets) {
|
|
21
|
+
if (value === "")
|
|
22
|
+
continue;
|
|
23
|
+
for (const onWire of [value, ...placements.map((placement) => placed(placement, value))]) {
|
|
24
|
+
for (const copy of secretTextForms(onWire))
|
|
25
|
+
texts.add(copy);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const sorted = [...texts].sort((a, b) => utf8.encode(b).length - utf8.encode(a).length);
|
|
29
|
+
const bytes = sorted.map((text) => utf8.encode(text));
|
|
30
|
+
return { texts: sorted, bytes, longest: bytes[0]?.length ?? 0 };
|
|
31
|
+
}
|
|
32
|
+
/** The exact text the kit puts on the wire for one placement. */
|
|
33
|
+
function placed(placement, value) {
|
|
34
|
+
switch (placement.as) {
|
|
35
|
+
case "bearer":
|
|
36
|
+
return `Bearer ${value}`;
|
|
37
|
+
case "header":
|
|
38
|
+
return `${placement.prefix ?? ""}${value}`;
|
|
39
|
+
case "form":
|
|
40
|
+
return new URLSearchParams([[placement.field, value]]).toString();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The text with every form of the secrets replaced by `[secret removed]`.
|
|
45
|
+
* For headers, URLs, tool results, error messages and log lines.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* removeSecrets(String(error), forms)
|
|
49
|
+
*/
|
|
50
|
+
export function removeSecrets(text, forms) {
|
|
51
|
+
let filtered = text;
|
|
52
|
+
for (const form of forms.texts)
|
|
53
|
+
filtered = filtered.replaceAll(form, secretRemoved);
|
|
54
|
+
return filtered;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The error with every form of the secrets removed from its message, its
|
|
58
|
+
* stack and its causes. A kit error can repeat a URL a server chose, such as
|
|
59
|
+
* a redirect target, so every error leaving a request goes through here.
|
|
60
|
+
* The error is changed in place, so its class and `code` stay; one that
|
|
61
|
+
* can't be changed is replaced by a plain `Error` with the filtered message.
|
|
62
|
+
*/
|
|
63
|
+
export function removeSecretsFromError(error, forms) {
|
|
64
|
+
return withoutSecrets(error, forms, new Set());
|
|
65
|
+
}
|
|
66
|
+
function withoutSecrets(error, forms, seen) {
|
|
67
|
+
if (forms.longest === 0)
|
|
68
|
+
return error;
|
|
69
|
+
if (typeof error === "string")
|
|
70
|
+
return removeSecrets(error, forms);
|
|
71
|
+
if (!(error instanceof Error) || seen.has(error))
|
|
72
|
+
return error;
|
|
73
|
+
seen.add(error);
|
|
74
|
+
const message = removeSecrets(error.message, forms);
|
|
75
|
+
const stack = error.stack;
|
|
76
|
+
const cause = withoutSecrets(error.cause, forms, seen);
|
|
77
|
+
try {
|
|
78
|
+
if (message !== error.message)
|
|
79
|
+
error.message = message;
|
|
80
|
+
if (stack !== undefined)
|
|
81
|
+
error.stack = removeSecrets(stack, forms);
|
|
82
|
+
if (cause !== error.cause)
|
|
83
|
+
error.cause = cause;
|
|
84
|
+
return error;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return new Error(message);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Removes the secrets from a body that arrives in pieces, without holding
|
|
92
|
+
* the whole body. It holds back the last `longest form − 1` bytes of each
|
|
93
|
+
* piece, so a value split across two pieces is still found.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* const remover = new SecretRemover(forms);
|
|
97
|
+
* for (const piece of pieces) send(remover.push(piece));
|
|
98
|
+
* send(remover.flush());
|
|
99
|
+
*/
|
|
100
|
+
export class SecretRemover {
|
|
101
|
+
#forms;
|
|
102
|
+
/** The forms by their first byte, longest first, to skip most bytes quickly. */
|
|
103
|
+
#byFirstByte = new Map();
|
|
104
|
+
#held = new Uint8Array(0);
|
|
105
|
+
#removed = 0;
|
|
106
|
+
constructor(forms) {
|
|
107
|
+
this.#forms = forms;
|
|
108
|
+
for (const form of forms.bytes) {
|
|
109
|
+
const first = form[0];
|
|
110
|
+
this.#byFirstByte.set(first, [...(this.#byFirstByte.get(first) ?? []), form]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** How many secrets it has replaced so far. */
|
|
114
|
+
get removed() {
|
|
115
|
+
return this.#removed;
|
|
116
|
+
}
|
|
117
|
+
/** The filtered bytes that are safe to pass on; may be empty while bytes are held back. */
|
|
118
|
+
push(piece) {
|
|
119
|
+
if (this.#forms.longest === 0)
|
|
120
|
+
return piece;
|
|
121
|
+
const data = concat([this.#held, piece]);
|
|
122
|
+
const { output, rest } = this.#scan(data, data.length - (this.#forms.longest - 1));
|
|
123
|
+
this.#held = rest;
|
|
124
|
+
return output;
|
|
125
|
+
}
|
|
126
|
+
/** The filtered bytes still held back, at the end of the body. */
|
|
127
|
+
flush() {
|
|
128
|
+
const { output } = this.#scan(this.#held, this.#held.length);
|
|
129
|
+
this.#held = new Uint8Array(0);
|
|
130
|
+
return output;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Replaces matches that start before `end`. Every form fits in `data`
|
|
134
|
+
* from any such start, so a match is never cut off. Returns what follows
|
|
135
|
+
* the last byte looked at, to be scanned with the next piece.
|
|
136
|
+
*/
|
|
137
|
+
#scan(data, end) {
|
|
138
|
+
const pieces = [];
|
|
139
|
+
let kept = 0;
|
|
140
|
+
let at = 0;
|
|
141
|
+
while (at < end) {
|
|
142
|
+
const match = this.#matchAt(data, at);
|
|
143
|
+
if (match === 0) {
|
|
144
|
+
at++;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
pieces.push(data.subarray(kept, at), removedBytes);
|
|
148
|
+
this.#removed++;
|
|
149
|
+
at += match;
|
|
150
|
+
kept = at;
|
|
151
|
+
}
|
|
152
|
+
pieces.push(data.subarray(kept, at));
|
|
153
|
+
return { output: concat(pieces), rest: data.slice(at) };
|
|
154
|
+
}
|
|
155
|
+
/** The length of the longest form that starts at `at`, or 0. */
|
|
156
|
+
#matchAt(data, at) {
|
|
157
|
+
for (const form of this.#byFirstByte.get(data[at]) ?? []) {
|
|
158
|
+
if (at + form.length <= data.length && form.every((byte, i) => data[at + i] === byte)) {
|
|
159
|
+
return form.length;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return 0;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* A stream step that removes the secrets, for the bridge's stderr and log.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* runner.stderr.pipeThrough(removeSecretsStream(forms))
|
|
170
|
+
*/
|
|
171
|
+
export function removeSecretsStream(forms) {
|
|
172
|
+
const remover = new SecretRemover(forms);
|
|
173
|
+
return new TransformStream({
|
|
174
|
+
transform: (piece, controller) => enqueueIfAny(controller, remover.push(piece)),
|
|
175
|
+
flush: (controller) => enqueueIfAny(controller, remover.flush()),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function enqueueIfAny(controller, bytes) {
|
|
179
|
+
if (bytes.length > 0)
|
|
180
|
+
controller.enqueue(bytes);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The headers with the secrets removed from every value. A header whose
|
|
184
|
+
* name holds a secret is left out, because a name can't hold the marker.
|
|
185
|
+
*/
|
|
186
|
+
export function removeSecretsFromHeaders(headers, forms) {
|
|
187
|
+
const filtered = new Headers();
|
|
188
|
+
for (const [name, value] of headers) {
|
|
189
|
+
if (removeSecrets(name, forms) !== name)
|
|
190
|
+
continue;
|
|
191
|
+
filtered.append(name, removeSecrets(value, forms));
|
|
192
|
+
}
|
|
193
|
+
return filtered;
|
|
194
|
+
}
|
|
195
|
+
function concat(pieces) {
|
|
196
|
+
if (pieces.length === 1)
|
|
197
|
+
return pieces[0];
|
|
198
|
+
const joined = new Uint8Array(pieces.reduce((sum, piece) => sum + piece.length, 0));
|
|
199
|
+
let offset = 0;
|
|
200
|
+
for (const piece of pieces) {
|
|
201
|
+
joined.set(piece, offset);
|
|
202
|
+
offset += piece.length;
|
|
203
|
+
}
|
|
204
|
+
return joined;
|
|
205
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Secrets } from "../../../core/ports/src/index.js";
|
|
2
|
+
import { IntegrationRefusedError } from "@halonicjs/adapters/integration-kit";
|
|
3
|
+
import type { IntegrationPolicy } from "./policy.js";
|
|
4
|
+
import type { Body } from "./request-body.js";
|
|
5
|
+
import { type SecretForms } from "./secret-filter.js";
|
|
6
|
+
/**
|
|
7
|
+
* The values of every secret the integration declares and the workspace
|
|
8
|
+
* has set up, whether this request places them or not. The kit refuses a
|
|
9
|
+
* request that carries one of them anywhere it didn't put it.
|
|
10
|
+
*/
|
|
11
|
+
export declare function readDeclaredSecrets(policy: IntegrationPolicy, secrets: Secrets): Promise<Map<string, string>>;
|
|
12
|
+
/** The parts of a request the integration wrote, before the kit places any secret. */
|
|
13
|
+
export interface OwnParts {
|
|
14
|
+
/** The method as the integration gave it. */
|
|
15
|
+
readonly method?: string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The method the kit sends, uppercased. Matching is case-sensitive, so a
|
|
18
|
+
* key in capitals given as a lower-case method only shows up here.
|
|
19
|
+
*/
|
|
20
|
+
readonly sentMethod?: string;
|
|
21
|
+
/** As the integration wrote it, or a redirect's `Location`, resolved against `base`. */
|
|
22
|
+
readonly url: string;
|
|
23
|
+
readonly base?: URL;
|
|
24
|
+
readonly headers?: Headers;
|
|
25
|
+
readonly body?: Body;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Refuses the request as `secret-in-request` when the integration's own
|
|
29
|
+
* method, as given or as sent, URL, headers or body hold a secret value in any form the filter
|
|
30
|
+
* knows. Runs before placement, so a secret the kit puts in is never counted.
|
|
31
|
+
*/
|
|
32
|
+
export declare function refuseCarriedSecrets(policy: IntegrationPolicy, forms: SecretForms, parts: OwnParts): void;
|
|
33
|
+
/**
|
|
34
|
+
* Refuses a redirect as `secret-in-redirect` when its `Location` holds a
|
|
35
|
+
* secret value, so the kit doesn't follow it: a server can put a value it
|
|
36
|
+
* was sent into the next URL. The server chose that URL, not the
|
|
37
|
+
* integration, so this is not one of the `leakAttemptCodes`. The
|
|
38
|
+
* message names the two hosts only, with any secret removed.
|
|
39
|
+
*/
|
|
40
|
+
export declare function refuseRedirectCarryingSecrets(policy: IntegrationPolicy, forms: SecretForms, location: string, from: URL): void;
|
|
41
|
+
/** The forms of the secret values, matched raw and in every encoding the filter knows. */
|
|
42
|
+
export declare function carriedForms(values: Iterable<string>): SecretForms;
|
|
43
|
+
/**
|
|
44
|
+
* A request that carries a secret value the kit didn't place. It names only
|
|
45
|
+
* the host, with any secret removed, never the path: the parsed path can
|
|
46
|
+
* hold the value in an encoding the filter doesn't match.
|
|
47
|
+
*/
|
|
48
|
+
export declare class SecretInRequestError extends IntegrationRefusedError {
|
|
49
|
+
/** For the request log: the method and host, each with any secret removed, and no path. */
|
|
50
|
+
readonly logged: {
|
|
51
|
+
readonly method: string;
|
|
52
|
+
readonly host: string;
|
|
53
|
+
readonly path: string;
|
|
54
|
+
};
|
|
55
|
+
constructor(policy: IntegrationPolicy, shown: {
|
|
56
|
+
method: string;
|
|
57
|
+
host: string;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { IntegrationRefusedError } from "@halonicjs/adapters/integration-kit";
|
|
2
|
+
import { removeSecrets, SecretRemover, secretForms, secretRemoved, } from "./secret-filter.js";
|
|
3
|
+
/**
|
|
4
|
+
* The values of every secret the integration declares and the workspace
|
|
5
|
+
* has set up, whether this request places them or not. The kit refuses a
|
|
6
|
+
* request that carries one of them anywhere it didn't put it.
|
|
7
|
+
*/
|
|
8
|
+
export async function readDeclaredSecrets(policy, secrets) {
|
|
9
|
+
const values = new Map();
|
|
10
|
+
for (const name of Object.keys(policy.secrets)) {
|
|
11
|
+
const value = await secrets.get(name);
|
|
12
|
+
if (value !== null && value !== "")
|
|
13
|
+
values.set(name, value);
|
|
14
|
+
}
|
|
15
|
+
return values;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Refuses the request as `secret-in-request` when the integration's own
|
|
19
|
+
* method, as given or as sent, URL, headers or body hold a secret value in any form the filter
|
|
20
|
+
* knows. Runs before placement, so a secret the kit puts in is never counted.
|
|
21
|
+
*/
|
|
22
|
+
export function refuseCarriedSecrets(policy, forms, parts) {
|
|
23
|
+
if (carriesSecret(forms, parts)) {
|
|
24
|
+
throw new SecretInRequestError(policy, {
|
|
25
|
+
method: shown((parts.method ?? "GET").toUpperCase(), forms),
|
|
26
|
+
host: shown(hostOf(parts.url, parts.base), forms),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Refuses a redirect as `secret-in-redirect` when its `Location` holds a
|
|
32
|
+
* secret value, so the kit doesn't follow it: a server can put a value it
|
|
33
|
+
* was sent into the next URL. The server chose that URL, not the
|
|
34
|
+
* integration, so this is not one of the `leakAttemptCodes`. The
|
|
35
|
+
* message names the two hosts only, with any secret removed.
|
|
36
|
+
*/
|
|
37
|
+
export function refuseRedirectCarryingSecrets(policy, forms, location, from) {
|
|
38
|
+
if (carriesSecret(forms, { url: location, base: from })) {
|
|
39
|
+
throw new IntegrationRefusedError("secret-in-redirect", `${policy.name}: ${from.host} redirected to ${shown(hostOf(location, from), forms)} with the value of a secret in the URL, so the kit didn't follow it`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Whether the parts hold a secret value in any form the filter knows. */
|
|
43
|
+
function carriesSecret(forms, parts) {
|
|
44
|
+
if (forms.longest === 0)
|
|
45
|
+
return false;
|
|
46
|
+
const headerLines = [...(parts.headers ?? [])].map(([name, value]) => `${name}: ${value}`);
|
|
47
|
+
const url = [parts.url, withEscapesDecoded(parts.url), parsed(parts.url, parts.base)];
|
|
48
|
+
const texts = [parts.method ?? "", parts.sentMethod ?? "", ...url, ...headerLines];
|
|
49
|
+
return texts.some((text) => holds(text, forms)) || bodyHolds(parts.body ?? null, forms);
|
|
50
|
+
}
|
|
51
|
+
/** The forms of the secret values, matched raw and in every encoding the filter knows. */
|
|
52
|
+
export function carriedForms(values) {
|
|
53
|
+
return secretForms([...values].map((value) => ({ value })));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A request that carries a secret value the kit didn't place. It names only
|
|
57
|
+
* the host, with any secret removed, never the path: the parsed path can
|
|
58
|
+
* hold the value in an encoding the filter doesn't match.
|
|
59
|
+
*/
|
|
60
|
+
export class SecretInRequestError extends IntegrationRefusedError {
|
|
61
|
+
/** For the request log: the method and host, each with any secret removed, and no path. */
|
|
62
|
+
logged;
|
|
63
|
+
constructor(policy, shown) {
|
|
64
|
+
super("secret-in-request", `${policy.name}: a request to ${shown.host} carries the value of a secret the kit didn't put there, so nothing was sent`);
|
|
65
|
+
this.logged = { method: shown.method, host: shown.host, path: "" };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function holds(text, forms) {
|
|
69
|
+
return removeSecrets(text, forms) !== text;
|
|
70
|
+
}
|
|
71
|
+
function bodyHolds(body, forms) {
|
|
72
|
+
if (typeof body === "string")
|
|
73
|
+
return holds(body, forms) || holds(withEscapesDecoded(body), forms);
|
|
74
|
+
if (body instanceof URLSearchParams)
|
|
75
|
+
return holds(body.toString(), forms);
|
|
76
|
+
let bytes;
|
|
77
|
+
if (body instanceof ArrayBuffer)
|
|
78
|
+
bytes = new Uint8Array(body);
|
|
79
|
+
else if (ArrayBuffer.isView(body)) {
|
|
80
|
+
bytes = new Uint8Array(body.buffer, body.byteOffset, body.byteLength);
|
|
81
|
+
}
|
|
82
|
+
else
|
|
83
|
+
return false; // none, or a body `checkBody` has already refused
|
|
84
|
+
const remover = new SecretRemover(forms);
|
|
85
|
+
remover.push(bytes);
|
|
86
|
+
remover.flush();
|
|
87
|
+
return remover.removed > 0;
|
|
88
|
+
}
|
|
89
|
+
const escapeRun = /(?:%[0-9A-Fa-f]{2})+/g;
|
|
90
|
+
const oneEscape = /%[0-9A-Fa-f]{2}/g;
|
|
91
|
+
/**
|
|
92
|
+
* The text with its percent-escapes undone, so a value encoded only in part
|
|
93
|
+
* is still found. `decodeURIComponent` throws on the whole text for one bad
|
|
94
|
+
* escape, so each run of escapes is decoded on its own: a malformed `%ZZ`
|
|
95
|
+
* stays as it is. A run that isn't valid UTF-8, such as `%2D%FF`, is decoded
|
|
96
|
+
* one escape at a time, so its `%2D` still becomes `-`.
|
|
97
|
+
*/
|
|
98
|
+
function withEscapesDecoded(text) {
|
|
99
|
+
return text.replace(escapeRun, (run) => decodedOrNull(run) ?? run.replace(oneEscape, (single) => decodedOrNull(single) ?? single));
|
|
100
|
+
}
|
|
101
|
+
function decodedOrNull(escapes) {
|
|
102
|
+
try {
|
|
103
|
+
return decodeURIComponent(escapes);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** The URL as `fetch` will send it: parsing lowercases the host and encodes the path. */
|
|
110
|
+
function parsed(url, base) {
|
|
111
|
+
try {
|
|
112
|
+
return new URL(url, base).href;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return url;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function hostOf(url, base) {
|
|
119
|
+
try {
|
|
120
|
+
return new URL(url, base).host;
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return "an invalid URL";
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The text, or `[secret removed]` when it holds a secret. URL parsing
|
|
128
|
+
* lowercases a host and the log uppercases a method, so this ignores case.
|
|
129
|
+
*/
|
|
130
|
+
function shown(text, forms) {
|
|
131
|
+
const lower = text.toLowerCase();
|
|
132
|
+
return forms.texts.some((form) => lower.includes(form.toLowerCase())) ? secretRemoved : text;
|
|
133
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SecretPlacement, Secrets } from "../../../core/ports/src/index.js";
|
|
2
|
+
import { type IntegrationPolicy } from "./policy.js";
|
|
3
|
+
/**
|
|
4
|
+
* Copies the placements the integration's code gave into frozen objects of
|
|
5
|
+
* text fields, reading each field once. The kit checks and places only
|
|
6
|
+
* these copies: the code keeps its own objects and could change them, or
|
|
7
|
+
* give a getter, after the check and before the secret is placed. A field
|
|
8
|
+
* that isn't text is refused here, because an object could turn into other
|
|
9
|
+
* text each time it is read.
|
|
10
|
+
*/
|
|
11
|
+
export declare function copyPlacements(policy: IntegrationPolicy, placements: readonly unknown[]): readonly SecretPlacement[];
|
|
12
|
+
/**
|
|
13
|
+
* Checks every placement against the sheet before a secret value is read.
|
|
14
|
+
* Give it the copies from {@link copyPlacements}, never the code's own
|
|
15
|
+
* objects. Where the secret may go is for {@link checkPlacementHosts}.
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkPlacements(policy: IntegrationPolicy, placements: readonly SecretPlacement[]): void;
|
|
18
|
+
/**
|
|
19
|
+
* Checks that every placed secret may go to the request's first host, once
|
|
20
|
+
* the URL is parsed. {@link checkPlacements} has already run, so every
|
|
21
|
+
* secret is declared.
|
|
22
|
+
*/
|
|
23
|
+
export declare function checkPlacementHosts(policy: IntegrationPolicy, placements: readonly SecretPlacement[], url: URL): void;
|
|
24
|
+
/**
|
|
25
|
+
* Reads each secret's value once. The values never leave the kit. An
|
|
26
|
+
* optional secret without a value gets no entry, so `place` leaves it out.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readSecrets(policy: IntegrationPolicy, secrets: Secrets, placements: readonly SecretPlacement[]): Promise<Map<string, string>>;
|
|
29
|
+
/**
|
|
30
|
+
* Puts the secrets allowed for this hop's host into the headers and the form
|
|
31
|
+
* body. A placement whose secret may not go to this hop is left out, which
|
|
32
|
+
* happens after a redirect to another declared host.
|
|
33
|
+
*
|
|
34
|
+
* @returns the form body to send, when a placement wrote into it
|
|
35
|
+
*/
|
|
36
|
+
export declare function place(policy: IntegrationPolicy, placements: readonly SecretPlacement[], values: ReadonlyMap<string, string>, url: URL, headers: Headers, form: URLSearchParams | undefined): URLSearchParams | undefined;
|