Skip to content

Commit 652482f

Browse files
fix: resolve remaining clippy warnings in tests and examples
1 parent 74731a2 commit 652482f

File tree

7 files changed

+37
-31
lines changed

7 files changed

+37
-31
lines changed

examples/memory_profile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use zentinel_agent_waf::{WafConfig, WafEngine};
1010
fn separator(char: char, width: usize) {
1111
println!(
1212
"{}",
13-
std::iter::repeat(char).take(width).collect::<String>()
13+
std::iter::repeat_n(char, width).collect::<String>()
1414
);
1515
}
1616

src/bot/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ mod tests {
333333
let mut detector = BotDetector::new(BotConfig::default());
334334
let headers = HashMap::new();
335335

336-
let (classification, detections) = detector.analyze(Some(""), &headers, None, None);
336+
let (_classification, detections) = detector.analyze(Some(""), &headers, None, None);
337337
assert!(!detections.is_empty());
338338
}
339339

src/federated/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ mod tests {
568568
let output = fl.forward(&model, &features);
569569

570570
// Output should be between 0 and 1 (sigmoid)
571-
assert!(output >= 0.0 && output <= 1.0);
571+
assert!((0.0..=1.0).contains(&output));
572572
}
573573

574574
#[test]

src/federated/privacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ mod tests {
394394
assert_eq!(shares.len(), 3);
395395

396396
// Sum of shares should equal original
397-
let mut sum = vec![0.0; 3];
397+
let mut sum = [0.0; 3];
398398
for share in &shares {
399399
for (i, &v) in share.iter().enumerate() {
400400
sum[i] += v;

tests/crs_compatibility.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ fn create_engine() -> WafEngine {
1313
}
1414

1515
fn create_paranoid_engine(level: u8) -> WafEngine {
16-
let mut config = WafConfig::default();
17-
config.paranoia_level = level;
16+
let config = WafConfig {
17+
paranoia_level: level,
18+
..Default::default()
19+
};
1820
WafEngine::new(config).expect("Failed to create engine")
1921
}
2022

tests/integration_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ mod api_security {
336336
let deep_json =
337337
r#"{"a":{"b":{"c":{"d":{"e":{"f":{"g":{"h":{"i":{"j":{"k":"deep"}}}}}}}}}}}"#;
338338

339-
let detections = engine.check(deep_json, "body");
339+
let _detections = engine.check(deep_json, "body");
340340
// Detection depends on JSON parsing in check flow
341341
}
342342
}

tests/websocket_tests.rs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,32 @@ use zentinel_agent_waf::{WafAgent, WafConfig, WebSocketConfig};
1010

1111
/// Create a WebSocket-enabled agent for testing
1212
fn create_websocket_agent() -> WafAgent {
13-
let mut config = WafConfig::default();
14-
config.websocket = WebSocketConfig {
15-
enabled: true,
16-
inspect_text_frames: true,
17-
inspect_binary_frames: false,
18-
max_frame_size: 65536,
19-
block_mode: true,
20-
accumulate_fragments: true,
21-
max_message_size: 1048576,
22-
block_close_code: 1008,
23-
block_close_reason: "WAF policy violation".to_string(),
13+
let config = WafConfig {
14+
websocket: WebSocketConfig {
15+
enabled: true,
16+
inspect_text_frames: true,
17+
inspect_binary_frames: false,
18+
max_frame_size: 65536,
19+
block_mode: true,
20+
accumulate_fragments: true,
21+
max_message_size: 1048576,
22+
block_close_code: 1008,
23+
block_close_reason: "WAF policy violation".to_string(),
24+
},
25+
..Default::default()
2426
};
2527
WafAgent::new(config).expect("Failed to create agent")
2628
}
2729

2830
/// Create a WebSocket agent with custom config
2931
fn create_websocket_agent_with_config(f: impl FnOnce(&mut WebSocketConfig)) -> WafAgent {
30-
let mut config = WafConfig::default();
31-
config.websocket = WebSocketConfig::default();
32-
config.websocket.enabled = true;
32+
let mut config = WafConfig {
33+
websocket: WebSocketConfig {
34+
enabled: true,
35+
..Default::default()
36+
},
37+
..Default::default()
38+
};
3339
f(&mut config.websocket);
3440
WafAgent::new(config).expect("Failed to create agent")
3541
}
@@ -88,20 +94,18 @@ fn continuation_frame(
8894

8995
/// Check if response indicates a block (close connection)
9096
fn is_blocked(response: &AgentResponse) -> bool {
91-
match &response.websocket_decision {
92-
Some(WebSocketDecision::Close { .. }) => true,
93-
Some(WebSocketDecision::Drop) => true,
94-
_ => false,
95-
}
97+
matches!(
98+
&response.websocket_decision,
99+
Some(WebSocketDecision::Close { .. }) | Some(WebSocketDecision::Drop)
100+
)
96101
}
97102

98103
/// Check if response indicates allow
99104
fn is_allowed(response: &AgentResponse) -> bool {
100-
match &response.websocket_decision {
101-
Some(WebSocketDecision::Allow) => true,
102-
None => true, // Default is allow
103-
_ => false,
104-
}
105+
matches!(
106+
&response.websocket_decision,
107+
Some(WebSocketDecision::Allow) | None
108+
)
105109
}
106110

107111
// =============================================================================

0 commit comments

Comments
 (0)