Skip to content

Commit 652c8cb

Browse files
committed
style: apply clippy lint
1 parent 9bab212 commit 652c8cb

File tree

6 files changed

+54
-77
lines changed

6 files changed

+54
-77
lines changed

tuic-client/src/config.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ mod tests {
423423

424424
let config_path = temp_dir.path().join(format!("config{}", extension));
425425

426-
fs::write(&config_path, &config_content).unwrap();
426+
fs::write(&config_path, config_content).unwrap();
427427

428428
// Temporarily set command line arguments for clap to parse
429429
let os_args = vec![
@@ -519,7 +519,7 @@ mod tests {
519519

520520
let config = config.unwrap();
521521
assert_eq!(config.log_level, "debug");
522-
assert_eq!(config.relay.zero_rtt_handshake, true);
522+
assert!(config.relay.zero_rtt_handshake);
523523
}
524524

525525
#[test]
@@ -533,23 +533,22 @@ mod tests {
533533
assert_eq!(config.relay.ipstack_prefer, StackPrefer::V4first);
534534
assert_eq!(config.relay.udp_relay_mode, UdpRelayMode::Native);
535535
assert_eq!(config.relay.congestion_control, CongestionControl::Bbr);
536-
assert_eq!(config.relay.zero_rtt_handshake, false);
537-
assert_eq!(config.relay.disable_sni, false);
536+
assert!(!config.relay.zero_rtt_handshake);
537+
assert!(!config.relay.disable_sni);
538538
assert_eq!(config.relay.timeout, Duration::from_secs(8));
539539
assert_eq!(config.relay.heartbeat, Duration::from_secs(3));
540-
assert_eq!(config.relay.disable_native_certs, false);
540+
assert!(!config.relay.disable_native_certs);
541541
assert_eq!(config.relay.send_window, 16 * 1024 * 1024);
542542
assert_eq!(config.relay.receive_window, 8 * 1024 * 1024);
543543
assert_eq!(config.relay.initial_mtu, 1200);
544544
assert_eq!(config.relay.min_mtu, 1200);
545-
assert_eq!(config.relay.gso, true);
546-
assert_eq!(config.relay.pmtu, true);
545+
assert!(config.relay.gso);
546+
assert!(config.relay.pmtu);
547547
assert_eq!(config.relay.gc_interval, Duration::from_secs(3));
548548
assert_eq!(config.relay.gc_lifetime, Duration::from_secs(15));
549-
assert_eq!(config.relay.skip_cert_verify, false);
549+
assert!(!config.relay.skip_cert_verify);
550550
assert_eq!(config.local.max_packet_size, 1500);
551551
}
552-
553552
#[test]
554553
fn test_tcp_udp_forward() {
555554
let json5_config = include_str!("../tests/config/tcp_udp_forward.json5");

tuic-core/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ fn test_heartbeat_creation() {
159159

160160
#[test]
161161
fn test_heartbeat_default() {
162-
let _hb = Heartbeat::default();
162+
let _hb = Heartbeat;
163163
assert_eq!(Heartbeat::type_code(), 0x04);
164164
}
165165

tuic-server/src/acl.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub enum AclAddress {
5959

6060
/// Represents port specifications with optional protocols
6161
#[derive(Debug, Clone, PartialEq, Serialize, Display)]
62-
#[display("{}", format_port_list(&entries))]
62+
#[display("{}", format_port_list(entries))]
6363
pub struct AclPorts {
6464
/// List of port ranges or single ports with optional protocols
6565
pub entries: Vec<AclPortEntry>,
@@ -120,10 +120,8 @@ impl AclRule {
120120
/// Check if the rule matches the given IP address
121121
fn matches_address(&self, ip: IpAddr) -> bool {
122122
match &self.addr {
123-
AclAddress::Ip(ip_str) => ip_str.parse::<IpAddr>().map_or(false, |parsed| parsed == ip),
124-
AclAddress::Cidr(cidr_str) => cidr_str
125-
.parse::<ip_network::IpNetwork>()
126-
.map_or(false, |net| net.contains(ip)),
123+
AclAddress::Ip(ip_str) => ip_str.parse::<IpAddr>() == Ok(ip),
124+
AclAddress::Cidr(cidr_str) => cidr_str.parse::<ip_network::IpNetwork>().is_ok_and(|net| net.contains(ip)),
127125
AclAddress::Domain(domain) => Self::match_domain(domain, ip),
128126
AclAddress::WildcardDomain(pattern) => Self::match_wildcard_domain(pattern, ip),
129127
AclAddress::Localhost => Self::is_loopback(ip),
@@ -148,7 +146,7 @@ impl AclRule {
148146
(domain, 0)
149147
.to_socket_addrs()
150148
.ok()
151-
.map_or(false, |mut iter| iter.any(|sa| sa.ip() == ip))
149+
.is_some_and(|mut iter| iter.any(|sa| sa.ip() == ip))
152150
}
153151

154152
/// Match a wildcard domain against an IP address
@@ -164,7 +162,7 @@ impl AclRule {
164162
(stripped, 0)
165163
.to_socket_addrs()
166164
.ok()
167-
.map_or(false, |mut iter| iter.any(|sa| sa.ip() == ip))
165+
.is_some_and(|mut iter| iter.any(|sa| sa.ip() == ip))
168166
}
169167
}
170168

tuic-server/src/config.rs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ mod tests {
703703
let temp_dir = tempdir().unwrap();
704704
let config_path = temp_dir.path().join(format!("config{}", extension));
705705

706-
fs::write(&config_path, &config_content).unwrap();
706+
fs::write(&config_path, config_content).unwrap();
707707

708708
// Temporarily set command line arguments for clap to parse
709709
let os_args = vec![
@@ -716,11 +716,8 @@ mod tests {
716716
let cli = Cli::try_parse_from(os_args)?;
717717

718718
// Call parse_config with the CLI and env_state
719-
let result = parse_config(cli, env_state).await;
720-
721-
result
719+
parse_config(cli, env_state).await
722720
}
723-
724721
#[tokio::test]
725722
async fn test_valid_toml_config() -> eyre::Result<()> {
726723
let config = include_str!("../tests/config/valid_toml_config.toml");
@@ -729,13 +726,12 @@ mod tests {
729726

730727
assert_eq!(result.log_level, LogLevel::Warn);
731728
assert_eq!(result.server, "127.0.0.1:8080".parse().unwrap());
732-
assert_eq!(result.udp_relay_ipv6, false);
733-
assert_eq!(result.zero_rtt_handshake, true);
729+
assert!(!result.udp_relay_ipv6);
730+
assert!(result.zero_rtt_handshake);
734731

735-
assert_eq!(result.tls.self_sign, true);
736-
assert_eq!(result.tls.auto_ssl, true);
732+
assert!(result.tls.self_sign);
733+
assert!(result.tls.auto_ssl);
737734
assert_eq!(result.tls.hostname, "testhost");
738-
739735
assert_eq!(result.quic.initial_mtu, 1400);
740736
assert_eq!(result.quic.min_mtu, 1300);
741737
assert_eq!(result.quic.send_window, 10000000);
@@ -772,10 +768,9 @@ mod tests {
772768
let uuid = Uuid::parse_str("123e4567-e89b-12d3-a456-426614174002").unwrap();
773769
assert_eq!(result.users.get(&uuid), Some(&"old_password".to_string()));
774770

775-
assert_eq!(result.tls.self_sign, false);
776-
assert!(result.data_dir.ends_with("__test__legacy_data"));
777771

778-
// Cleanup test directories
772+
assert!(!result.tls.self_sign);
773+
assert!(result.data_dir.ends_with("__test__legacy_data")); // Cleanup test directories
779774
let _ = tokio::fs::remove_dir_all("__test__legacy_data").await;
780775
}
781776

@@ -1009,17 +1004,16 @@ mod tests {
10091004
// Check default values
10101005
assert_eq!(result.log_level, LogLevel::Info);
10111006
assert_eq!(result.server, "[::]:8443".parse().unwrap());
1012-
assert_eq!(result.udp_relay_ipv6, true);
1013-
assert_eq!(result.zero_rtt_handshake, false);
1014-
assert_eq!(result.dual_stack, true);
1007+
assert!(result.udp_relay_ipv6);
1008+
assert!(!result.zero_rtt_handshake);
1009+
assert!(result.dual_stack);
10151010
assert_eq!(result.auth_timeout, Duration::from_secs(3));
10161011
assert_eq!(result.task_negotiation_timeout, Duration::from_secs(3));
10171012
assert_eq!(result.gc_interval, Duration::from_secs(10));
10181013
assert_eq!(result.gc_lifetime, Duration::from_secs(30));
10191014
assert_eq!(result.max_external_packet_size, 1500);
10201015
assert_eq!(result.stream_timeout, Duration::from_secs(60));
10211016
}
1022-
10231017
#[tokio::test]
10241018
async fn test_invalid_uuid() {
10251019
let config = include_str!("../tests/config/invalid_uuid.toml");
@@ -1097,14 +1091,13 @@ mod tests {
10971091
let result = test_parse_config(config, ".json").await.unwrap();
10981092

10991093
// Verify migration worked
1100-
assert_eq!(result.tls.self_sign, true);
1094+
assert!(result.tls.self_sign);
11011095
assert!(result.tls.certificate.ends_with("cert.pem"));
11021096
assert!(result.tls.private_key.ends_with("key.pem"));
11031097
assert_eq!(result.tls.hostname, "example.com");
11041098
assert_eq!(result.quic.congestion_control.controller, CongestionController::Bbr);
11051099
assert_eq!(result.quic.max_idle_time, Duration::from_secs(60));
11061100
assert_eq!(result.quic.initial_mtu, 1500);
1107-
11081101
assert!(result.restful.is_some());
11091102
assert_eq!(result.restful.unwrap().addr, "0.0.0.0:8080".parse().unwrap());
11101103
}
@@ -1188,15 +1181,14 @@ mod tests {
11881181

11891182
assert_eq!(result.log_level, LogLevel::Info);
11901183
assert_eq!(result.server, "127.0.0.1:9443".parse().unwrap());
1191-
assert_eq!(result.udp_relay_ipv6, false);
1192-
assert_eq!(result.zero_rtt_handshake, true);
1184+
assert!(!result.udp_relay_ipv6);
1185+
assert!(result.zero_rtt_handshake);
11931186

11941187
assert_eq!(result.users.len(), 2);
11951188

1196-
assert_eq!(result.tls.self_sign, true);
1197-
assert_eq!(result.tls.auto_ssl, true);
1189+
assert!(result.tls.self_sign);
1190+
assert!(result.tls.auto_ssl);
11981191
assert_eq!(result.tls.hostname, "json5.example.com");
1199-
12001192
assert_eq!(result.quic.initial_mtu, 1400);
12011193
assert_eq!(result.quic.min_mtu, 1300);
12021194
assert_eq!(result.quic.send_window, 8000000);
@@ -1239,9 +1231,8 @@ mod tests {
12391231
let result = test_parse_config(config, ".json5").await.unwrap();
12401232
assert_eq!(result.log_level, LogLevel::Error);
12411233
assert_eq!(result.server, "192.168.1.1:8443".parse().unwrap());
1242-
assert_eq!(result.tls.self_sign, false);
1234+
assert!(!result.tls.self_sign);
12431235
}
1244-
12451236
#[tokio::test]
12461237
async fn test_dir_parameter_finds_config() {
12471238
// Test that --dir finds the first config file in a directory

tuic-server/src/utils.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,14 @@ mod tests {
5050
#[test]
5151
fn test_stack_prefer_variants() {
5252
// Test all variants exist and are distinct
53-
let modes = vec![
53+
let modes = [
5454
StackPrefer::V4only,
5555
StackPrefer::V6only,
5656
StackPrefer::V4first,
5757
StackPrefer::V6first,
5858
];
5959

60-
assert_eq!(modes.len(), 4);
61-
62-
// Test equality
60+
assert_eq!(modes.len(), 4); // Test equality
6361
assert_eq!(StackPrefer::V4only, StackPrefer::V4only);
6462
assert_ne!(StackPrefer::V4only, StackPrefer::V6only);
6563
}

tuic-tests/tests/integration_tests.rs

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -532,14 +532,12 @@ async fn test_server_client_integration() {
532532
eprintln!("[TCP Test] Failed to read response: {}", e);
533533
// Try regular read to see what we can get
534534
let mut fallback_buffer = vec![0u8; 1024];
535-
if let Ok(n) = timeout(Duration::from_secs(1), stream.read(&mut fallback_buffer)).await {
536-
if let Ok(bytes) = n {
537-
eprintln!(
538-
"[TCP Test] Fallback read got {} bytes: {:?}",
539-
bytes,
540-
&fallback_buffer[..bytes]
541-
);
542-
}
535+
if let Ok(Ok(bytes)) = timeout(Duration::from_secs(1), stream.read(&mut fallback_buffer)).await {
536+
eprintln!(
537+
"[TCP Test] Fallback read got {} bytes: {:?}",
538+
bytes,
539+
&fallback_buffer[..bytes]
540+
);
543541
}
544542
}
545543
Err(_) => {
@@ -596,31 +594,24 @@ async fn test_server_client_integration() {
596594
let echo_task = tokio::spawn(async move {
597595
let mut buf = vec![0u8; 1024];
598596
println!("[UDP Echo Server] Waiting for packets...");
599-
loop {
600-
match timeout(Duration::from_secs(5), echo_server_clone.recv_from(&mut buf)).await {
601-
Ok(Ok((n, addr))) => {
602-
println!("[UDP Echo Server] Received {} bytes from {}", n, addr);
603-
println!("[UDP Echo Server] Data: {:?}", &buf[..n]);
604-
if let Err(e) = echo_server_clone.send_to(&buf[..n], addr).await {
605-
eprintln!("[UDP Echo Server] Failed to send response: {}", e);
606-
} else {
607-
println!("[UDP Echo Server] Echoed {} bytes back to {}", n, addr);
608-
}
609-
break;
610-
}
611-
Ok(Err(e)) => {
612-
eprintln!("[UDP Echo Server] Error receiving: {}", e);
613-
break;
614-
}
615-
Err(_) => {
616-
eprintln!("[UDP Echo Server] Timeout waiting for data (no packets received)");
617-
break;
597+
match timeout(Duration::from_secs(5), echo_server_clone.recv_from(&mut buf)).await {
598+
Ok(Ok((n, addr))) => {
599+
println!("[UDP Echo Server] Received {} bytes from {}", n, addr);
600+
println!("[UDP Echo Server] Data: {:?}", &buf[..n]);
601+
if let Err(e) = echo_server_clone.send_to(&buf[..n], addr).await {
602+
eprintln!("[UDP Echo Server] Failed to send response: {}", e);
603+
} else {
604+
println!("[UDP Echo Server] Echoed {} bytes back to {}", n, addr);
618605
}
619606
}
607+
Ok(Err(e)) => {
608+
eprintln!("[UDP Echo Server] Error receiving: {}", e);
609+
}
610+
Err(_) => {
611+
eprintln!("[UDP Echo Server] Timeout waiting for data (no packets received)");
612+
}
620613
}
621-
});
622-
623-
// Give server time to start
614+
}); // Give server time to start
624615
tokio::time::sleep(Duration::from_millis(100)).await;
625616

626617
// Connect to SOCKS5 proxy using fast-socks5's UDP API

0 commit comments

Comments
 (0)