grapsus_agent_protocol/
lib.rs1#![allow(clippy::large_enum_variant)]
3
4#![allow(dead_code)]
36
37pub mod binary;
38pub mod buffer_pool;
39mod errors;
40pub mod headers;
41#[cfg(feature = "mmap-buffers")]
42pub mod mmap_buffer;
43mod protocol;
44
45pub mod v2;
47
48pub mod grpc_v2 {
50 tonic::include_proto!("grapsus.agent.v2");
51}
52
53pub use errors::AgentProtocolError;
55
56pub use protocol::{
58 AgentResponse, AuditMetadata, BinaryRequestBodyChunkEvent, BinaryResponseBodyChunkEvent,
59 BodyMutation, Decision, DetectionSeverity, EventType, GuardrailDetection,
60 GuardrailInspectEvent, GuardrailInspectionType, GuardrailResponse, HeaderOp,
61 RequestBodyChunkEvent, RequestCompleteEvent, RequestHeadersEvent, RequestMetadata,
62 ResponseBodyChunkEvent, ResponseHeadersEvent, TextSpan, WebSocketDecision, WebSocketFrameEvent,
63 WebSocketOpcode, MAX_MESSAGE_SIZE,
64};
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn test_body_mutation_types() {
72 let pass_through = BodyMutation::pass_through(0);
74 assert!(pass_through.is_pass_through());
75 assert!(!pass_through.is_drop());
76 assert_eq!(pass_through.chunk_index, 0);
77
78 let drop = BodyMutation::drop_chunk(1);
80 assert!(!drop.is_pass_through());
81 assert!(drop.is_drop());
82 assert_eq!(drop.chunk_index, 1);
83
84 let replace = BodyMutation::replace(2, "modified content".to_string());
86 assert!(!replace.is_pass_through());
87 assert!(!replace.is_drop());
88 assert_eq!(replace.chunk_index, 2);
89 assert_eq!(replace.data, Some("modified content".to_string()));
90 }
91
92 #[test]
93 fn test_agent_response_streaming() {
94 let response = AgentResponse::needs_more_data();
96 assert!(response.needs_more);
97 assert_eq!(response.decision, Decision::Allow);
98
99 let mutation = BodyMutation::replace(0, "new content".to_string());
101 let response = AgentResponse::default_allow().with_request_body_mutation(mutation.clone());
102 assert!(!response.needs_more);
103 assert!(response.request_body_mutation.is_some());
104 assert_eq!(
105 response.request_body_mutation.unwrap().data,
106 Some("new content".to_string())
107 );
108
109 let response = AgentResponse::default_allow().set_needs_more(true);
111 assert!(response.needs_more);
112 }
113}