v0.3.7-pre.002
This commit is contained in:
115
crates/ksp-app-backfill-desk/tests/desktop_security.rs
Normal file
115
crates/ksp-app-backfill-desk/tests/desktop_security.rs
Normal file
@@ -0,0 +1,115 @@
|
||||
// file: crates/ksp-app-backfill-desk/tests/desktop_security.rs
|
||||
// version: 1
|
||||
|
||||
//! Security and dependency-boundary checks for the Backfill Desk scaffold.
|
||||
|
||||
#![forbid(unsafe_code)]
|
||||
#![deny(unreachable_pub)]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
fn app_root() -> std::path::PathBuf {
|
||||
return std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
}
|
||||
|
||||
fn collect_files(directory: &std::path::Path, extension: &str, files: &mut std::vec::Vec<std::path::PathBuf>) {
|
||||
let entries = std::fs::read_dir(directory);
|
||||
let entries = match entries {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return,
|
||||
};
|
||||
for entry in entries {
|
||||
let entry = match entry {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => continue,
|
||||
};
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
collect_files(path.as_path(), extension, files);
|
||||
continue;
|
||||
}
|
||||
if path.extension().and_then(std::ffi::OsStr::to_str) == std::option::Option::Some(extension) {
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn read_text(path: &std::path::Path) -> String {
|
||||
let source = std::fs::read_to_string(path);
|
||||
assert!(source.is_ok(), "unable to read {}", path.display());
|
||||
return match source {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => String::new(),
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pre_002_capability_surface_is_core_plus_tracing_only() {
|
||||
let root = app_root();
|
||||
let capability = read_text(root.join("capabilities/default.json").as_path());
|
||||
assert!(capability.contains("\"core:default\""));
|
||||
assert!(capability.contains("\"tracing:default\""));
|
||||
for forbidden in ["dialog:", "fs:", "http:", "shell:"] {
|
||||
assert!(!capability.contains(forbidden));
|
||||
}
|
||||
let manifest = read_text(root.join("Cargo.toml").as_path());
|
||||
assert!(manifest.contains("tauri-plugin-tracing.workspace = true"));
|
||||
for forbidden in
|
||||
["ksp-job-backfill-lib", "ksp-onchain-transport-lib", "ksp-store-lib", "ksp-store-api", "ksp-store-postgres-lib", "reqwest", "tokio-postgres"]
|
||||
{
|
||||
assert!(!manifest.contains(forbidden), "pre.002 opens a later-layer dependency: {forbidden}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pre_002_frontend_has_no_network_persistence_or_native_dialog_surface() {
|
||||
let root = app_root();
|
||||
let mut typescript = std::vec::Vec::new();
|
||||
collect_files(root.join("frontend/ts").as_path(), "ts", &mut typescript);
|
||||
assert!(!typescript.is_empty());
|
||||
for path in typescript {
|
||||
let source = read_text(path.as_path());
|
||||
for forbidden in ["fetch(", "XMLHttpRequest", "localStorage", "sessionStorage", "window.alert(", "window.confirm(", "window.prompt("] {
|
||||
assert!(!source.contains(forbidden), "{} contains forbidden scaffold surface {forbidden}", path.display());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pre_002_tauri_commands_remain_centralized() {
|
||||
let root = app_root();
|
||||
let mut rust_files = std::vec::Vec::new();
|
||||
collect_files(root.join("src").as_path(), "rs", &mut rust_files);
|
||||
let mut command_count = 0usize;
|
||||
for path in rust_files {
|
||||
let source = read_text(path.as_path());
|
||||
let count = source.matches("#[tauri::command]").count();
|
||||
if path.file_name().and_then(std::ffi::OsStr::to_str) == std::option::Option::Some("tauri.rs") {
|
||||
command_count += count;
|
||||
} else {
|
||||
assert_eq!(count, 0, "{} declares a Tauri command outside tauri.rs", path.display());
|
||||
}
|
||||
}
|
||||
assert_eq!(command_count, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pre_002_frontend_instrumentation_avoids_business_or_secret_payloads() {
|
||||
let root = app_root();
|
||||
let main = read_text(root.join("frontend/ts/main.ts").as_path());
|
||||
for required in [
|
||||
"Backfill Desk frontend control clicked",
|
||||
"Backfill Desk navigation tab clicked",
|
||||
"Backfill Desk runtime status refresh button clicked",
|
||||
"Frontend IPC command requested",
|
||||
] {
|
||||
if required == "Frontend IPC command requested" {
|
||||
let invoke = read_text(root.join("frontend/ts/invoke.ts").as_path());
|
||||
assert!(invoke.contains(required));
|
||||
} else {
|
||||
assert!(main.contains(required));
|
||||
}
|
||||
}
|
||||
for forbidden in ["JSON.stringify(status)", "signature", "address", "apiKey", "authorization", "database_url"] {
|
||||
assert!(!main.contains(forbidden));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user