* Exec: harden host env override enforcement and fail closed * Node host: enforce env override diagnostics before shell filtering * Env overrides: align Windows key handling and mac node rejection
57 lines
1.9 KiB
Swift
57 lines
1.9 KiB
Swift
import Testing
|
|
@testable import OpenClaw
|
|
|
|
struct HostEnvSanitizerTests {
|
|
@Test func `sanitize blocks shell trace variables`() {
|
|
let env = HostEnvSanitizer.sanitize(overrides: [
|
|
"SHELLOPTS": "xtrace",
|
|
"PS4": "$(touch /tmp/pwned)",
|
|
"OPENCLAW_TEST": "1",
|
|
])
|
|
#expect(env["SHELLOPTS"] == nil)
|
|
#expect(env["PS4"] == nil)
|
|
#expect(env["OPENCLAW_TEST"] == "1")
|
|
}
|
|
|
|
@Test func `sanitize shell wrapper allows only explicit override keys`() {
|
|
let env = HostEnvSanitizer.sanitize(
|
|
overrides: [
|
|
"LANG": "C",
|
|
"LC_ALL": "C",
|
|
"OPENCLAW_TOKEN": "secret",
|
|
"PS4": "$(touch /tmp/pwned)",
|
|
],
|
|
shellWrapper: true)
|
|
|
|
#expect(env["LANG"] == "C")
|
|
#expect(env["LC_ALL"] == "C")
|
|
#expect(env["OPENCLAW_TOKEN"] == nil)
|
|
#expect(env["PS4"] == nil)
|
|
}
|
|
|
|
@Test func `sanitize non shell wrapper keeps regular overrides`() {
|
|
let env = HostEnvSanitizer.sanitize(overrides: ["OPENCLAW_TOKEN": "secret"])
|
|
#expect(env["OPENCLAW_TOKEN"] == "secret")
|
|
}
|
|
|
|
@Test func `inspect overrides rejects blocked and invalid keys`() {
|
|
let diagnostics = HostEnvSanitizer.inspectOverrides(overrides: [
|
|
"CLASSPATH": "/tmp/evil-classpath",
|
|
"BAD-KEY": "x",
|
|
"ProgramFiles(x86)": "C:\\Program Files (x86)",
|
|
])
|
|
|
|
#expect(diagnostics.blockedKeys == ["CLASSPATH"])
|
|
#expect(diagnostics.invalidKeys == ["BAD-KEY"])
|
|
}
|
|
|
|
@Test func `sanitize accepts Windows-style override key names`() {
|
|
let env = HostEnvSanitizer.sanitize(overrides: [
|
|
"ProgramFiles(x86)": "D:\\SDKs",
|
|
"CommonProgramFiles(x86)": "D:\\Common",
|
|
])
|
|
#expect(env["ProgramFiles(x86)"] == "D:\\SDKs")
|
|
#expect(env["CommonProgramFiles(x86)"] == "D:\\Common")
|
|
}
|
|
}
|