use owlen_core::consent::{ConsentManager, ConsentScope}; #[test] fn test_consent_scopes() { let mut manager = ConsentManager::new(); // Test session consent manager.grant_consent_with_scope( "test_tool", vec!["data".to_string()], vec!["https://example.com".to_string()], ConsentScope::Session, ); assert!(manager.has_consent("test_tool")); // Clear session consent and verify it's gone manager.clear_session_consent(); assert!(!manager.has_consent("test_tool")); // Test permanent consent survives session clear manager.grant_consent_with_scope( "test_tool_permanent", vec!["data".to_string()], vec!["https://example.com".to_string()], ConsentScope::Permanent, ); assert!(manager.has_consent("test_tool_permanent")); manager.clear_session_consent(); assert!(manager.has_consent("test_tool_permanent")); // Verify revoke works for permanent consent manager.revoke_consent("test_tool_permanent"); assert!(!manager.has_consent("test_tool_permanent")); } #[test] fn test_pending_requests_prevents_duplicates() { let mut manager = ConsentManager::new(); // Simulate concurrent consent requests by checking pending state // In real usage, multiple threads would call request_consent simultaneously // First, verify a tool has no consent assert!(!manager.has_consent("web_search")); // The pending_requests map is private, but we can test the behavior // by checking that consent checks work correctly assert!(manager.check_consent_needed("web_search").is_some()); // Grant session consent manager.grant_consent_with_scope( "web_search", vec!["search queries".to_string()], vec!["https://api.search.com".to_string()], ConsentScope::Session, ); // Now it should have consent assert!(manager.has_consent("web_search")); assert!(manager.check_consent_needed("web_search").is_none()); } #[test] fn test_consent_record_separation() { let mut manager = ConsentManager::new(); // Add permanent consent manager.grant_consent_with_scope( "perm_tool", vec!["data".to_string()], vec!["https://perm.com".to_string()], ConsentScope::Permanent, ); // Add session consent manager.grant_consent_with_scope( "session_tool", vec!["data".to_string()], vec!["https://session.com".to_string()], ConsentScope::Session, ); // Both should have consent assert!(manager.has_consent("perm_tool")); assert!(manager.has_consent("session_tool")); // Clear session consent manager.clear_session_consent(); // Only permanent should remain assert!(manager.has_consent("perm_tool")); assert!(!manager.has_consent("session_tool")); // Clear all manager.clear_all_consent(); assert!(!manager.has_consent("perm_tool")); }