test(host): cover C ABI version/mode fail-closed paths
- Build a second C provider reporting ABI v2 and assert registration fails with resource.unsupported. - Assert pure/strict refuse a registered C provider kind with permission.denied. - Refresh the C ABI evidence/test README. Gate: fmt, clippy -D warnings, 436 tests passed.
This commit is contained in:
1 parent
d909de5c68
commit
5e5c3a84d9
3 files changed
+56
-6
No files matched your search
@@ -26,7 +26,7 @@ fn cc_available() -> bool {
|
|||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_provider(dir: &Path) -> PathBuf {
|
fn build_provider_with_version(dir: &Path, version: u32) -> PathBuf {
|
||||||
let source = dir.join("provider.c");
|
let source = dir.join("provider.c");
|
||||||
std::fs::write(
|
std::fs::write(
|
||||||
&source,
|
&source,
|
||||||
@@ -39,7 +39,10 @@ static const char DATA[] = "c-abi";
|
|||||||
static size_t position = 0;
|
static size_t position = 0;
|
||||||
static uint64_t next_token = 1;
|
static uint64_t next_token = 1;
|
||||||
|
|
||||||
uint32_t marqdo_resource_provider_abi_version(void) { return 1u; }
|
#ifndef PROVIDER_VERSION
|
||||||
|
#define PROVIDER_VERSION 1u
|
||||||
|
#endif
|
||||||
|
uint32_t marqdo_resource_provider_abi_version(void) { return PROVIDER_VERSION; }
|
||||||
|
|
||||||
int32_t marqdo_resource_open(const char *kind, const char *descriptor,
|
int32_t marqdo_resource_open(const char *kind, const char *descriptor,
|
||||||
const char *rights_csv, uint64_t *out_token) {
|
const char *rights_csv, uint64_t *out_token) {
|
||||||
@@ -85,7 +88,13 @@ int32_t marqdo_resource_last_error(char *buffer, uint32_t capacity) {
|
|||||||
};
|
};
|
||||||
let library = dir.join(format!("libecho_provider.{extension}"));
|
let library = dir.join(format!("libecho_provider.{extension}"));
|
||||||
let status = Command::new("cc")
|
let status = Command::new("cc")
|
||||||
.args(["-shared", "-fPIC", "-O2", "-o"])
|
.args([
|
||||||
|
"-shared",
|
||||||
|
"-fPIC",
|
||||||
|
"-O2",
|
||||||
|
&format!("-DPROVIDER_VERSION={version}"),
|
||||||
|
"-o",
|
||||||
|
])
|
||||||
.arg(&library)
|
.arg(&library)
|
||||||
.arg(&source)
|
.arg(&source)
|
||||||
.status()
|
.status()
|
||||||
@@ -94,6 +103,10 @@ int32_t marqdo_resource_last_error(char *buffer, uint32_t capacity) {
|
|||||||
library
|
library
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build_provider(dir: &Path) -> PathBuf {
|
||||||
|
build_provider_with_version(dir, 1)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn c_abi_provider_round_trips() {
|
fn c_abi_provider_round_trips() {
|
||||||
if !cc_available() {
|
if !cc_available() {
|
||||||
@@ -146,3 +159,38 @@ fn c_abi_provider_loading_fails_closed() {
|
|||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
assert_eq!(error.category, ErrorCategory::KernelUnavailable);
|
assert_eq!(error.category, ErrorCategory::KernelUnavailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn c_abi_version_mismatch_and_modes_fail_closed() {
|
||||||
|
if !cc_available() {
|
||||||
|
eprintln!("skipping C provider test: cc is unavailable");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let wrong = build_provider_with_version(dir.path(), 2);
|
||||||
|
let project = tempfile::tempdir().unwrap();
|
||||||
|
let mut host = StdHost::new(
|
||||||
|
SandboxMode::Project,
|
||||||
|
Capabilities::project().allow_resource_provider("cabi"),
|
||||||
|
project.path(),
|
||||||
|
);
|
||||||
|
let error = host
|
||||||
|
.register_c_resource_provider("cabi", &["cabi.sensor"], &wrong)
|
||||||
|
.unwrap_err();
|
||||||
|
assert_eq!(error.category, ErrorCategory::ResourceUnsupported);
|
||||||
|
|
||||||
|
let good = build_provider(dir.path());
|
||||||
|
for mode in [SandboxMode::Pure, SandboxMode::Strict] {
|
||||||
|
let mut host = StdHost::new(
|
||||||
|
mode,
|
||||||
|
Capabilities::project().allow_resource_provider("cabi"),
|
||||||
|
project.path(),
|
||||||
|
);
|
||||||
|
host.register_c_resource_provider("cabi", &["cabi.sensor"], &good)
|
||||||
|
.unwrap();
|
||||||
|
let error = host
|
||||||
|
.resource_open("cabi.sensor", "s", &["read".to_string()], &context())
|
||||||
|
.unwrap_err();
|
||||||
|
assert_eq!(error.category, ErrorCategory::PermissionDenied);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,7 +33,9 @@ token enter a language `Value`, wire frame or trace.
|
|||||||
grant;
|
grant;
|
||||||
3. `resource.open/read/write/close` round-trips `c-`/`abi`, `write=3`, second
|
3. `resource.open/read/write/close` round-trips `c-`/`abi`, `write=3`, second
|
||||||
close `resource.closed`;
|
close `resource.closed`;
|
||||||
4. a missing library path fails with `kernel.unavailable`.
|
4. a missing library path fails with `kernel.unavailable`;
|
||||||
|
5. a library reporting ABI version 2 fails with `resource.unsupported`;
|
||||||
|
6. pure/strict refuse the C provider kind with `permission.denied`.
|
||||||
|
|
||||||
No Rust runtime/`HostOp`/parser change was needed; language code still sees the
|
No Rust runtime/`HostOp`/parser change was needed; language code still sees the
|
||||||
same `resource.*` surface.
|
same `resource.*` surface.
|
||||||
|
|||||||
+2
-2
@@ -179,8 +179,8 @@ grant/pure/strict/DNS refusal) and
|
|||||||
|
|
||||||
RFC-CM CM-A09 C ABI provider (ADR-0036) is pinned by
|
RFC-CM CM-A09 C ABI provider (ADR-0036) is pinned by
|
||||||
`crates/marqdo-host/tests/c_provider.rs`, which compiles a small C shared
|
`crates/marqdo-host/tests/c_provider.rs`, which compiles a small C shared
|
||||||
library, registers it, round-trips `resource.*` and checks missing-library
|
library, registers it, round-trips `resource.*`, checks missing-library,
|
||||||
fail-closed behavior.
|
wrong-ABI-version and pure/strict fail-closed behavior.
|
||||||
|
|
||||||
RFC-CM CM-A09 worker provider transport (ADR-0035) is pinned by
|
RFC-CM CM-A09 worker provider transport (ADR-0035) is pinned by
|
||||||
`crates/marqdo-host/tests/worker_provider.rs`: a Python helper is spawned,
|
`crates/marqdo-host/tests/worker_provider.rs`: a Python helper is spawned,
|
||||||
|
|||||||
Reference in new issue
Block a user