From 93a9a9678c3e91e122ff4e22063a4ce9e9262ffa Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 00:58:14 +0530 Subject: [PATCH 1/2] test(artifacts): move the guarded-file tests out of tiny_store_tests.rs tiny_store_tests.rs had grown to 784 lines, over rust:layout's 750-line limit. The trailing file-root and protected-file tests move unchanged into tiny_store_guard_tests.rs, a child module of the same tests module, so they keep the shared helpers through super::*. --- .../src/artifacts/tiny_store_guard_tests.rs | 125 +++++++++++++++++ .../src/artifacts/tiny_store_tests.rs | 127 +----------------- 2 files changed, 128 insertions(+), 124 deletions(-) create mode 100644 crates/openhuman-core/src/artifacts/tiny_store_guard_tests.rs diff --git a/crates/openhuman-core/src/artifacts/tiny_store_guard_tests.rs b/crates/openhuman-core/src/artifacts/tiny_store_guard_tests.rs new file mode 100644 index 00000000000..f40a71a4278 --- /dev/null +++ b/crates/openhuman-core/src/artifacts/tiny_store_guard_tests.rs @@ -0,0 +1,125 @@ +use super::*; + +#[cfg(feature = "security-module")] +#[tokio::test] +async fn a_file_in_an_earlier_files_folder_can_still_be_revised() { + let _floor = crate::modules::security::gap::install_path_floor_port( + crate::modules::security::gap::ScriptedPathFloorPort::new([], vec![]), + ); + let (workspace, files) = temp_dirs(); + let earlier = files.parent().unwrap().join("OldFiles"); + std::fs::create_dir_all(&earlier).unwrap(); + let old = earlier.join("deck.pptx"); + std::fs::write(&old, b"v1").unwrap(); + // The files folder moved; the earlier one stays trusted. + let roots = FileRoots::new(&files).with_trusted([earlier.clone()]); + let ctx = crate::core::runtime::DispatchCtx::process_default(); + let artifacts = artifacts_service(&workspace, roots, None, None, &ctx); + let id = artifacts + .create( + ArtifactKind::File, + "Deck", + Content::File(old.display().to_string()), + &Author::agent("agent"), + None, + ) + .await + .unwrap() + .record + .id; + std::fs::write(&old, b"v2").unwrap(); + let saved = artifacts + .revise( + &id, + Content::File(old.display().to_string()), + &Author::agent("agent"), + None, + ) + .await + .unwrap(); + assert_eq!(saved.version, 2); +} + +#[tokio::test] +async fn a_protected_file_inside_the_working_folder_is_refused() { + let (workspace, files) = temp_dirs(); + let action = workspace.parent().unwrap().join("home"); + let ssh = action.join(".ssh"); + std::fs::create_dir_all(&ssh).unwrap(); + std::fs::write(ssh.join("id_ed25519"), b"PRIVATE").unwrap(); + let ctx = crate::core::runtime::DispatchCtx::process_default(); + let artifacts = artifacts_service( + &workspace, + FileRoots::new(&files), + Some(&action), + None, + &ctx, + ); + + let err = artifacts + .create( + ArtifactKind::File, + "Key", + Content::File(".ssh/id_ed25519".into()), + &Author::agent("agent"), + None, + ) + .await + .unwrap_err(); + assert!(err.to_string().contains("protected location"), "{err}"); +} + +#[cfg(feature = "security-module")] +#[tokio::test] +async fn the_guarded_roots_refuse_to_read_a_protected_file() { + let (workspace, _files) = temp_dirs(); + let home = workspace.parent().unwrap().join("home"); + std::fs::create_dir_all(home.join(".ssh")).unwrap(); + std::fs::write(home.join(".ssh/id_ed25519"), b"PRIVATE").unwrap(); + std::fs::write(home.join("notes.txt"), b"hello").unwrap(); + let key = home.join(".ssh/id_ed25519").canonicalize().unwrap(); + let _floor = crate::modules::security::gap::install_path_floor_port( + crate::modules::security::gap::ScriptedPathFloorPort::new([key], vec![]), + ); + let roots = guarded_roots(vec![home]); + + let err = roots.read(".ssh/id_ed25519").await.unwrap_err(); + assert!(err.to_string().contains("protected location"), "{err}"); + let (_, bytes) = roots.read("notes.txt").await.unwrap(); + assert_eq!(bytes, b"hello"); +} + +#[test] +fn a_working_folder_that_contains_the_workspace_is_not_trusted() { + let (workspace, files) = temp_dirs(); + let home = workspace.parent().unwrap().to_path_buf(); + let roots = file_roots(&workspace, &FileRoots::new(&files), Some(&home)); + assert!(!roots.contains(&home), "{roots:?}"); + assert!(roots.contains(&files)); + // A working folder beside the workspace stays the first root. + let beside = home.join("projects"); + let roots = file_roots(&workspace, &FileRoots::new(&files), Some(&beside)); + assert_eq!(roots.first(), Some(&beside)); +} + +#[test] +fn a_stored_file_key_resolves_under_the_version_files_folder_and_an_absolute_one_stays() { + let workspace = Path::new("/ws"); + let kept = tiny_artifacts::FileRef { + key: "artifacts/files/a1/v2.pptx".into(), + size_bytes: 1, + media_type: None, + }; + assert_eq!( + stored_file_path(workspace, &kept), + version_files_dir(workspace).join("artifacts/files/a1/v2.pptx") + ); + let legacy = tiny_artifacts::FileRef { + key: "/elsewhere/old.pptx".into(), + ..kept + }; + assert_eq!( + stored_file_path(workspace, &legacy), + PathBuf::from("/elsewhere/old.pptx") + ); +} diff --git a/crates/openhuman-core/src/artifacts/tiny_store_tests.rs b/crates/openhuman-core/src/artifacts/tiny_store_tests.rs index c08ba797a23..9973e303f18 100644 --- a/crates/openhuman-core/src/artifacts/tiny_store_tests.rs +++ b/crates/openhuman-core/src/artifacts/tiny_store_tests.rs @@ -9,6 +9,9 @@ use tiny_artifacts::{ use super::*; +#[path = "tiny_store_guard_tests.rs"] +mod guard_tests; + struct UnusedPublisher; #[derive(Default)] @@ -658,127 +661,3 @@ fn share_artifact_is_offered_only_with_a_publisher() { let with = names(true); assert!(with.contains(&"share_artifact".to_string()), "{with:?}"); } - -#[cfg(feature = "security-module")] -#[tokio::test] -async fn a_file_in_an_earlier_files_folder_can_still_be_revised() { - let _floor = crate::modules::security::gap::install_path_floor_port( - crate::modules::security::gap::ScriptedPathFloorPort::new([], vec![]), - ); - let (workspace, files) = temp_dirs(); - let earlier = files.parent().unwrap().join("OldFiles"); - std::fs::create_dir_all(&earlier).unwrap(); - let old = earlier.join("deck.pptx"); - std::fs::write(&old, b"v1").unwrap(); - // The files folder moved; the earlier one stays trusted. - let roots = FileRoots::new(&files).with_trusted([earlier.clone()]); - let ctx = crate::core::runtime::DispatchCtx::process_default(); - let artifacts = artifacts_service(&workspace, roots, None, None, &ctx); - let id = artifacts - .create( - ArtifactKind::File, - "Deck", - Content::File(old.display().to_string()), - &Author::agent("agent"), - None, - ) - .await - .unwrap() - .record - .id; - std::fs::write(&old, b"v2").unwrap(); - let saved = artifacts - .revise( - &id, - Content::File(old.display().to_string()), - &Author::agent("agent"), - None, - ) - .await - .unwrap(); - assert_eq!(saved.version, 2); -} - -#[tokio::test] -async fn a_protected_file_inside_the_working_folder_is_refused() { - let (workspace, files) = temp_dirs(); - let action = workspace.parent().unwrap().join("home"); - let ssh = action.join(".ssh"); - std::fs::create_dir_all(&ssh).unwrap(); - std::fs::write(ssh.join("id_ed25519"), b"PRIVATE").unwrap(); - let ctx = crate::core::runtime::DispatchCtx::process_default(); - let artifacts = artifacts_service( - &workspace, - FileRoots::new(&files), - Some(&action), - None, - &ctx, - ); - - let err = artifacts - .create( - ArtifactKind::File, - "Key", - Content::File(".ssh/id_ed25519".into()), - &Author::agent("agent"), - None, - ) - .await - .unwrap_err(); - assert!(err.to_string().contains("protected location"), "{err}"); -} - -#[cfg(feature = "security-module")] -#[tokio::test] -async fn the_guarded_roots_refuse_to_read_a_protected_file() { - let (workspace, _files) = temp_dirs(); - let home = workspace.parent().unwrap().join("home"); - std::fs::create_dir_all(home.join(".ssh")).unwrap(); - std::fs::write(home.join(".ssh/id_ed25519"), b"PRIVATE").unwrap(); - std::fs::write(home.join("notes.txt"), b"hello").unwrap(); - let key = home.join(".ssh/id_ed25519").canonicalize().unwrap(); - let _floor = crate::modules::security::gap::install_path_floor_port( - crate::modules::security::gap::ScriptedPathFloorPort::new([key], vec![]), - ); - let roots = guarded_roots(vec![home]); - - let err = roots.read(".ssh/id_ed25519").await.unwrap_err(); - assert!(err.to_string().contains("protected location"), "{err}"); - let (_, bytes) = roots.read("notes.txt").await.unwrap(); - assert_eq!(bytes, b"hello"); -} - -#[test] -fn a_working_folder_that_contains_the_workspace_is_not_trusted() { - let (workspace, files) = temp_dirs(); - let home = workspace.parent().unwrap().to_path_buf(); - let roots = file_roots(&workspace, &FileRoots::new(&files), Some(&home)); - assert!(!roots.contains(&home), "{roots:?}"); - assert!(roots.contains(&files)); - // A working folder beside the workspace stays the first root. - let beside = home.join("projects"); - let roots = file_roots(&workspace, &FileRoots::new(&files), Some(&beside)); - assert_eq!(roots.first(), Some(&beside)); -} - -#[test] -fn a_stored_file_key_resolves_under_the_version_files_folder_and_an_absolute_one_stays() { - let workspace = Path::new("/ws"); - let kept = tiny_artifacts::FileRef { - key: "artifacts/files/a1/v2.pptx".into(), - size_bytes: 1, - media_type: None, - }; - assert_eq!( - stored_file_path(workspace, &kept), - version_files_dir(workspace).join("artifacts/files/a1/v2.pptx") - ); - let legacy = tiny_artifacts::FileRef { - key: "/elsewhere/old.pptx".into(), - ..kept - }; - assert_eq!( - stored_file_path(workspace, &legacy), - PathBuf::from("/elsewhere/old.pptx") - ); -} From 6786d69b0729325e93494935697d78d4f4ffb8e2 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 04:17:53 +0530 Subject: [PATCH 2/2] test(artifacts): gate the protected-file refusal test on security-module a_protected_file_inside_the_working_folder_is_refused asserts TinySecurity's protected-path floor. Without security-module, security is disabled and there is no floor, so the create succeeds and the test failed in that build. It now runs only where the floor exists, like its sibling the_guarded_roots_refuse_to_read_a_protected_file. --- crates/openhuman-core/src/artifacts/tiny_store_guard_tests.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/openhuman-core/src/artifacts/tiny_store_guard_tests.rs b/crates/openhuman-core/src/artifacts/tiny_store_guard_tests.rs index f40a71a4278..a453d610ffc 100644 --- a/crates/openhuman-core/src/artifacts/tiny_store_guard_tests.rs +++ b/crates/openhuman-core/src/artifacts/tiny_store_guard_tests.rs @@ -40,6 +40,9 @@ async fn a_file_in_an_earlier_files_folder_can_still_be_revised() { assert_eq!(saved.version, 2); } +// The refusal is TinySecurity's protected-path floor: a build without the +// security module has security disabled and no floor (`security::switch`). +#[cfg(feature = "security-module")] #[tokio::test] async fn a_protected_file_inside_the_working_folder_is_refused() { let (workspace, files) = temp_dirs();