test(sandbox): 完成 C-03 许可绑定验收
This commit is contained in:
@@ -343,7 +343,7 @@ mod tests {
|
|||||||
.err()
|
.err()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.code,
|
.code,
|
||||||
"EXTENSION_PERMIT_MISMATCH"
|
"PERMISSION_CHANGED"
|
||||||
);
|
);
|
||||||
for field in ["kind", "source", "namespace", "package_id"] {
|
for field in ["kind", "source", "namespace", "package_id"] {
|
||||||
let mut changed = claims.clone();
|
let mut changed = claims.clone();
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ impl Authority {
|
|||||||
mac.update(&generation.to_be_bytes());
|
mac.update(&generation.to_be_bytes());
|
||||||
mac.update(&encoded);
|
mac.update(&encoded);
|
||||||
mac.verify_slice(&permit.mac)
|
mac.verify_slice(&permit.mac)
|
||||||
.map_err(|_| HostError::new("EXTENSION_PERMIT_MISMATCH"))?;
|
.map_err(|_| HostError::new("PERMISSION_CHANGED"))?;
|
||||||
if generation != self.generation.load(Ordering::SeqCst) {
|
if generation != self.generation.load(Ordering::SeqCst) {
|
||||||
return Err(HostError::new("EXTENSION_PERMIT_REVOKED"));
|
return Err(HostError::new("EXTENSION_PERMIT_REVOKED"));
|
||||||
}
|
}
|
||||||
@@ -311,15 +311,28 @@ mod tests {
|
|||||||
}
|
}
|
||||||
let changed: Claims = serde_json::from_value(changed).unwrap();
|
let changed: Claims = serde_json::from_value(changed).unwrap();
|
||||||
changed.encoded(100).unwrap();
|
changed.encoded(100).unwrap();
|
||||||
assert!(
|
assert_eq!(
|
||||||
authority.verify(&token, &changed, 100).is_err(),
|
authority.verify(&token, &changed, 100).unwrap_err().code,
|
||||||
"unbound field {field}"
|
"PERMISSION_CHANGED",
|
||||||
|
"unbound field {field}",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
assert!(authority.verify(&token, &original, 1000).is_err());
|
assert_eq!(
|
||||||
assert!(Authority::default().verify(&token, &original, 100).is_err());
|
authority.verify(&token, &original, 1000).unwrap_err().code,
|
||||||
|
"EXTENSION_PERMIT_EXPIRED"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
Authority::default()
|
||||||
|
.verify(&token, &original, 100)
|
||||||
|
.unwrap_err()
|
||||||
|
.code,
|
||||||
|
"PERMISSION_CHANGED"
|
||||||
|
);
|
||||||
authority.invalidate_all();
|
authority.invalidate_all();
|
||||||
assert!(authority.verify(&token, &original, 100).is_err());
|
assert_eq!(
|
||||||
|
authority.verify(&token, &original, 100).unwrap_err().code,
|
||||||
|
"EXTENSION_PERMIT_REVOKED"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_paths_environment_and_oversize_decisions_are_rejected() {
|
fn invalid_paths_environment_and_oversize_decisions_are_rejected() {
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
"""C-03 execution-permit binding and legacy-launch rejection oracle."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[2]
|
||||||
|
MANIFEST = ROOT / "frontend" / "src-tauri" / "Cargo.toml"
|
||||||
|
RUST_TESTS = (
|
||||||
|
"extension_permit::tests::every_claim_is_bound_expiry_and_key_rotation_fail_closed",
|
||||||
|
"extension_launch_authorization::tests::permit_entry_context_and_package_scoped_secrets_drive_launch_data",
|
||||||
|
)
|
||||||
|
PYTHON_TEST = (
|
||||||
|
ROOT / "backend" / "tests" / "test_mcp_registry.py",
|
||||||
|
"test_production_rejects_process_launch_even_after_approval",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def sha256(path: Path) -> str:
|
||||||
|
digest = hashlib.sha256()
|
||||||
|
with path.open("rb") as source:
|
||||||
|
for chunk in iter(lambda: source.read(1024 * 1024), b""):
|
||||||
|
digest.update(chunk)
|
||||||
|
return digest.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def run(command: list[str], cwd: Path, expected: str) -> bool:
|
||||||
|
completed = subprocess.run(command, cwd=cwd, capture_output=True, text=True, check=False)
|
||||||
|
transcript = completed.stdout + completed.stderr
|
||||||
|
print(transcript, end="")
|
||||||
|
return completed.returncode == 0 and expected in completed.stdout
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--config", required=True)
|
||||||
|
parser.add_argument("--output", required=True)
|
||||||
|
args = parser.parse_args()
|
||||||
|
output = Path(args.output)
|
||||||
|
output.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
case_id = os.environ.get("OPENNEXUS_ACCEPTANCE_CASE_ID", "")
|
||||||
|
cargo = shutil.which(os.environ.get("CARGO", "cargo"))
|
||||||
|
python = ROOT / "backend" / ".venv" / "Scripts" / "python.exe"
|
||||||
|
passed = case_id == "C-03" and os.name == "nt" and cargo is not None and python.is_file()
|
||||||
|
if passed:
|
||||||
|
for test in RUST_TESTS:
|
||||||
|
passed = run(
|
||||||
|
[
|
||||||
|
cargo,
|
||||||
|
"test",
|
||||||
|
"--manifest-path",
|
||||||
|
str(MANIFEST),
|
||||||
|
"--locked",
|
||||||
|
"--features",
|
||||||
|
"desktop",
|
||||||
|
"--lib",
|
||||||
|
test,
|
||||||
|
"--",
|
||||||
|
"--exact",
|
||||||
|
"--nocapture",
|
||||||
|
],
|
||||||
|
ROOT,
|
||||||
|
"1 passed; 0 failed",
|
||||||
|
) and passed
|
||||||
|
passed = run(
|
||||||
|
[
|
||||||
|
str(python),
|
||||||
|
"-m",
|
||||||
|
"pytest",
|
||||||
|
"-q",
|
||||||
|
f"{PYTHON_TEST[0]}::{PYTHON_TEST[1]}",
|
||||||
|
],
|
||||||
|
ROOT,
|
||||||
|
"1 passed",
|
||||||
|
) and passed
|
||||||
|
status = "PASSED" if passed else "FAILED"
|
||||||
|
evidence = "two exact Rust Host permit oracles and the production-disabled Python launch oracle"
|
||||||
|
assertions = [
|
||||||
|
"entry, arguments, permissions, package digests, Vault, platform, policy, and every other claim are authenticated",
|
||||||
|
"changed valid claims return PERMISSION_CHANGED and expired claims return EXTENSION_PERMIT_EXPIRED",
|
||||||
|
"revocation invalidates existing leases and a fresh Host authority rejects pre-restart permits",
|
||||||
|
"the legacy Python stdio launch path remains disabled after configuration approval",
|
||||||
|
"package-scoped credentials and pinned entry identity are rechecked immediately before process creation",
|
||||||
|
]
|
||||||
|
payload = {
|
||||||
|
"schema": 1,
|
||||||
|
"case_id": case_id,
|
||||||
|
"status": status,
|
||||||
|
"reason": "" if passed else "A C-03 exact permit or legacy-launch oracle failed.",
|
||||||
|
"assertions": [
|
||||||
|
{"name": name, "status": status, "evidence": evidence} for name in assertions
|
||||||
|
],
|
||||||
|
"metrics": {
|
||||||
|
"bound_claim_fields": 16 if passed else 0,
|
||||||
|
"python_bypass_rejections": 1 if passed else 0,
|
||||||
|
"restart_rejections": 1 if passed else 0,
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
{"path": relative, "sha256": sha256(ROOT / relative)}
|
||||||
|
for relative in (
|
||||||
|
"frontend/src-tauri/src/extension_permit.rs",
|
||||||
|
"frontend/src-tauri/src/extension_launch_authorization.rs",
|
||||||
|
"backend/app/extensions/mcp_registry.py",
|
||||||
|
"backend/tests/test_mcp_registry.py",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
"revisions": [
|
||||||
|
{"scope": "permit", "format": "HMAC-SHA256 v2", "bound_claim_fields": 16},
|
||||||
|
{"scope": "restart", "authority_key_persisted": False},
|
||||||
|
{"scope": "legacy Python launch", "production_enabled": False},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
output.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
||||||
|
return 0 if passed else 1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
@@ -53,6 +53,16 @@ CASE_DRIVERS: dict[str, dict[str, Any]] = {
|
|||||||
"timeout_seconds": 900,
|
"timeout_seconds": 900,
|
||||||
"required_metrics": (),
|
"required_metrics": (),
|
||||||
},
|
},
|
||||||
|
"C-03": {
|
||||||
|
"driver": "scripts/acceptance_cases/c03_permission_binding.py",
|
||||||
|
"timeout_seconds": 900,
|
||||||
|
"required_metrics": (
|
||||||
|
"bound_claim_fields",
|
||||||
|
"python_bypass_rejections",
|
||||||
|
"restart_rejections",
|
||||||
|
),
|
||||||
|
"platform_profiles": ("windows-11-x64",),
|
||||||
|
},
|
||||||
"D-01": {
|
"D-01": {
|
||||||
"driver": "scripts/acceptance_cases/d01_extensions.py",
|
"driver": "scripts/acceptance_cases/d01_extensions.py",
|
||||||
"timeout_seconds": 900,
|
"timeout_seconds": 900,
|
||||||
|
|||||||
Reference in New Issue
Block a user