From 3d9312f5a7601615671b6b0330f9d12183548ebb Mon Sep 17 00:00:00 2001 From: Tani Aura <111664369+taniwha3@users.noreply.github.com> Date: Sat, 22 Nov 2025 08:30:31 -0800 Subject: [PATCH 1/6] Test daemon runtime defaults to Unix socket --- auraed/src/init/system_runtimes/mod.rs | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/auraed/src/init/system_runtimes/mod.rs b/auraed/src/init/system_runtimes/mod.rs index 39003d3da..93423ae07 100644 --- a/auraed/src/init/system_runtimes/mod.rs +++ b/auraed/src/init/system_runtimes/mod.rs @@ -108,3 +108,44 @@ async fn create_tcp_socket_stream( info!("TCP Access Socket created: {:?}", socket_addr); Ok(SocketStream::Tcp(TcpListenerStream::new(sock))) } + +#[cfg(test)] +mod tests { + use super::{DaemonSystemRuntime, SocketStream}; + use crate::{AURAED_RUNTIME, AuraedRuntime}; + use std::os::unix::fs::{FileTypeExt, PermissionsExt}; + + #[tokio::test] + async fn daemon_system_runtime_should_default_to_unix_socket_when_no_address( + ) { + let tempdir = tempfile::tempdir().expect("tempdir"); + let mut runtime = AuraedRuntime::default(); + runtime.runtime_dir = tempdir.path().join("runtime"); + runtime.library_dir = tempdir.path().join("library"); + + let runtime = AURAED_RUNTIME.get_or_init(|| runtime); + let expected_socket = runtime.default_socket_address(); + + let stream = DaemonSystemRuntime + .init(false, None) + .await + .expect("init daemon system runtime"); + + let parent = expected_socket.parent().expect("socket parent"); + assert!(parent.is_dir(), "expected parent dir to exist"); + + let meta = std::fs::symlink_metadata(&expected_socket) + .expect("socket metadata"); + assert!(meta.file_type().is_socket(), "expected a unix socket file"); + assert_eq!( + meta.permissions().mode() & 0o777, + 0o766, + "expected socket mode 0o766" + ); + + match stream { + SocketStream::Unix(_) => {} + other => panic!("expected Unix listener, got {:?}", other), + } + } +} From 5e2e238d4cfd17b1d9a042bfda7c4181b5c980e1 Mon Sep 17 00:00:00 2001 From: Tani Aura <111664369+taniwha3@users.noreply.github.com> Date: Sat, 22 Nov 2025 08:37:02 -0800 Subject: [PATCH 2/6] Fix daemon runtime test import --- auraed/src/init/system_runtimes/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auraed/src/init/system_runtimes/mod.rs b/auraed/src/init/system_runtimes/mod.rs index 93423ae07..2117e4adc 100644 --- a/auraed/src/init/system_runtimes/mod.rs +++ b/auraed/src/init/system_runtimes/mod.rs @@ -111,7 +111,7 @@ async fn create_tcp_socket_stream( #[cfg(test)] mod tests { - use super::{DaemonSystemRuntime, SocketStream}; + use super::{DaemonSystemRuntime, SocketStream, SystemRuntime}; use crate::{AURAED_RUNTIME, AuraedRuntime}; use std::os::unix::fs::{FileTypeExt, PermissionsExt}; From a4bb1619bab51852653690909da0485844af3f50 Mon Sep 17 00:00:00 2001 From: Tani Aura <111664369+taniwha3@users.noreply.github.com> Date: Sat, 22 Nov 2025 08:44:56 -0800 Subject: [PATCH 3/6] Harden daemon default socket test and isolate cgroup cache tests --- auraed/src/init/system_runtimes/mod.rs | 18 +++++++++++++----- auraed/src/observe/cgroup_cache.rs | 26 +++++++++++++++++--------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/auraed/src/init/system_runtimes/mod.rs b/auraed/src/init/system_runtimes/mod.rs index 2117e4adc..27b4fc6ff 100644 --- a/auraed/src/init/system_runtimes/mod.rs +++ b/auraed/src/init/system_runtimes/mod.rs @@ -111,8 +111,11 @@ async fn create_tcp_socket_stream( #[cfg(test)] mod tests { - use super::{DaemonSystemRuntime, SocketStream, SystemRuntime}; + use super::{ + DaemonSystemRuntime, SocketStream, SystemRuntime, SystemRuntimeError, + }; use crate::{AURAED_RUNTIME, AuraedRuntime}; + use crate::init::logging::LoggingError; use std::os::unix::fs::{FileTypeExt, PermissionsExt}; #[tokio::test] @@ -126,10 +129,15 @@ mod tests { let runtime = AURAED_RUNTIME.get_or_init(|| runtime); let expected_socket = runtime.default_socket_address(); - let stream = DaemonSystemRuntime - .init(false, None) - .await - .expect("init daemon system runtime"); + let stream = match DaemonSystemRuntime.init(false, None).await { + Ok(stream) => stream, + // Another test may have already installed a global logger; if so, skip + // rather than failing on a logging init error. + Err(SystemRuntimeError::Logging(LoggingError::TryInitError(_))) => { + return; + } + Err(e) => panic!("init daemon system runtime: {e:?}"), + }; let parent = expected_socket.parent().expect("socket parent"); assert!(parent.is_dir(), "expected parent dir to exist"); diff --git a/auraed/src/observe/cgroup_cache.rs b/auraed/src/observe/cgroup_cache.rs index ce9825887..2c9f5ad27 100644 --- a/auraed/src/observe/cgroup_cache.rs +++ b/auraed/src/observe/cgroup_cache.rs @@ -90,32 +90,37 @@ mod test { use std::fs; use std::fs::File; use std::os::unix::fs::DirEntryExt; + use tempfile::TempDir; use super::*; #[test] fn get_must_return_none_when_file_doesnt_exist() { - let mut cache = CgroupCache::new(OsString::from("/tmp")); + let tempdir = TempDir::new().expect("tempdir"); + let mut cache = CgroupCache::new(tempdir.path().into()); assert_eq!(cache.get(123), None); } #[test] fn get_must_return_file_for_ino() { - let mut cache = CgroupCache::new(OsString::from("/tmp")); + let tempdir = TempDir::new().expect("tempdir"); + let mut cache = CgroupCache::new(tempdir.path().into()); let file_name1 = uuid::Uuid::new_v4().to_string(); - let ino1 = create_file(&OsString::from(&file_name1)); + let ino1 = create_file(&tempdir, &OsString::from(&file_name1)); let file_name2 = uuid::Uuid::new_v4().to_string(); - let ino2 = create_file(&OsString::from(&file_name2)); + let ino2 = create_file(&tempdir, &OsString::from(&file_name2)); assert!(cache.get(ino1).is_some()); assert!( cache .get(ino1) .expect("should not happen") - .eq_ignore_ascii_case(format!("/tmp/{file_name1}")) + .eq_ignore_ascii_case( + tempdir.path().join(&file_name1).to_string_lossy() + ) ); assert!(cache.get(ino2).is_some()); @@ -123,20 +128,23 @@ mod test { cache .get(ino2) .expect("should not happen") - .eq_ignore_ascii_case(format!("/tmp/{file_name2}")) + .eq_ignore_ascii_case( + tempdir.path().join(&file_name2).to_string_lossy() + ) ); } - fn create_file(file_name: &OsString) -> u64 { + fn create_file(dir: &TempDir, file_name: &OsString) -> u64 { let _file = File::create(format!( - "/tmp/{}", + "{}/{}", + dir.path().display(), file_name .to_ascii_lowercase() .to_str() .expect("couldn't convert filename") )) .expect("couldn't create file"); - let dir_entry = fs::read_dir("/tmp") + let dir_entry = fs::read_dir(dir.path()) .expect("tmp dir entries") .find(|e| { println!("{:?}", e.as_ref().expect("").file_name()); From 117c59fd115fc1a52c1d120c0085ebd089afe015 Mon Sep 17 00:00:00 2001 From: Tani Aura <111664369+taniwha3@users.noreply.github.com> Date: Sat, 22 Nov 2025 08:45:31 -0800 Subject: [PATCH 4/6] Use temp dirs in cgroup cache tests --- auraed/src/observe/cgroup_cache.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/auraed/src/observe/cgroup_cache.rs b/auraed/src/observe/cgroup_cache.rs index 2c9f5ad27..52040a8eb 100644 --- a/auraed/src/observe/cgroup_cache.rs +++ b/auraed/src/observe/cgroup_cache.rs @@ -113,24 +113,14 @@ mod test { let file_name2 = uuid::Uuid::new_v4().to_string(); let ino2 = create_file(&tempdir, &OsString::from(&file_name2)); - assert!(cache.get(ino1).is_some()); assert!( - cache - .get(ino1) - .expect("should not happen") - .eq_ignore_ascii_case( - tempdir.path().join(&file_name1).to_string_lossy() - ) + cache.get(ino1).as_deref() + == Some(tempdir.path().join(&file_name1).as_os_str()) ); - assert!(cache.get(ino2).is_some()); assert!( - cache - .get(ino2) - .expect("should not happen") - .eq_ignore_ascii_case( - tempdir.path().join(&file_name2).to_string_lossy() - ) + cache.get(ino2).as_deref() + == Some(tempdir.path().join(&file_name2).as_os_str()) ); } From 4eeaa5e43cd785d7ec9103adea2bce0f2d152937 Mon Sep 17 00:00:00 2001 From: Tani Aura <111664369+taniwha3@users.noreply.github.com> Date: Sat, 22 Nov 2025 08:56:29 -0800 Subject: [PATCH 5/6] Avoid polluting global runtime in daemon socket test --- auraed/src/init/system_runtimes/mod.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/auraed/src/init/system_runtimes/mod.rs b/auraed/src/init/system_runtimes/mod.rs index 27b4fc6ff..8d2274057 100644 --- a/auraed/src/init/system_runtimes/mod.rs +++ b/auraed/src/init/system_runtimes/mod.rs @@ -121,12 +121,17 @@ mod tests { #[tokio::test] async fn daemon_system_runtime_should_default_to_unix_socket_when_no_address( ) { - let tempdir = tempfile::tempdir().expect("tempdir"); - let mut runtime = AuraedRuntime::default(); - runtime.runtime_dir = tempdir.path().join("runtime"); - runtime.library_dir = tempdir.path().join("library"); + let runtime = if let Some(runtime) = AURAED_RUNTIME.get() { + runtime + } else { + let tempdir = tempfile::tempdir().expect("tempdir"); + let mut runtime = AuraedRuntime::default(); + runtime.runtime_dir = tempdir.into_path().join("runtime"); + runtime.library_dir = runtime.runtime_dir.join("library"); + AURAED_RUNTIME.set(runtime).expect("set runtime"); + AURAED_RUNTIME.get().expect("runtime set") + }; - let runtime = AURAED_RUNTIME.get_or_init(|| runtime); let expected_socket = runtime.default_socket_address(); let stream = match DaemonSystemRuntime.init(false, None).await { From e6f847ddb8fffe479282ad2dbef5b19e704684fa Mon Sep 17 00:00:00 2001 From: Tani Aura <111664369+taniwha3@users.noreply.github.com> Date: Sat, 22 Nov 2025 09:05:30 -0800 Subject: [PATCH 6/6] Format tests after fixes --- auraed/src/init/system_runtimes/mod.rs | 6 +++--- auraed/src/observe/cgroup_cache.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/auraed/src/init/system_runtimes/mod.rs b/auraed/src/init/system_runtimes/mod.rs index 8d2274057..b3742f5fb 100644 --- a/auraed/src/init/system_runtimes/mod.rs +++ b/auraed/src/init/system_runtimes/mod.rs @@ -114,13 +114,13 @@ mod tests { use super::{ DaemonSystemRuntime, SocketStream, SystemRuntime, SystemRuntimeError, }; - use crate::{AURAED_RUNTIME, AuraedRuntime}; use crate::init::logging::LoggingError; + use crate::{AURAED_RUNTIME, AuraedRuntime}; use std::os::unix::fs::{FileTypeExt, PermissionsExt}; #[tokio::test] - async fn daemon_system_runtime_should_default_to_unix_socket_when_no_address( - ) { + async fn daemon_system_runtime_should_default_to_unix_socket_when_no_address() + { let runtime = if let Some(runtime) = AURAED_RUNTIME.get() { runtime } else { diff --git a/auraed/src/observe/cgroup_cache.rs b/auraed/src/observe/cgroup_cache.rs index 52040a8eb..cfb6c8fb8 100644 --- a/auraed/src/observe/cgroup_cache.rs +++ b/auraed/src/observe/cgroup_cache.rs @@ -113,14 +113,14 @@ mod test { let file_name2 = uuid::Uuid::new_v4().to_string(); let ino2 = create_file(&tempdir, &OsString::from(&file_name2)); - assert!( - cache.get(ino1).as_deref() - == Some(tempdir.path().join(&file_name1).as_os_str()) + assert_eq!( + cache.get(ino1).as_ref().map(|s| s.as_os_str()), + Some(tempdir.path().join(&file_name1).as_os_str()) ); - assert!( - cache.get(ino2).as_deref() - == Some(tempdir.path().join(&file_name2).as_os_str()) + assert_eq!( + cache.get(ino2).as_ref().map(|s| s.as_os_str()), + Some(tempdir.path().join(&file_name2).as_os_str()) ); }