Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5164b1

Browse files
committed
Resolve warnings
1 parent 1919399 commit d5164b1

File tree

7 files changed

+82
-69
lines changed

7 files changed

+82
-69
lines changed

.claude/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"hooks": {
3+
"PostToolUse": [
4+
{
5+
"matcher": "Edit|MultiEdit|Write",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": "cargo fmt"
10+
}
11+
]
12+
}
13+
]
14+
}
15+
}

src/jail/macos.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl MacOSJail {
2929
fn ensure_group(&mut self) -> Result<u32> {
3030
// Check if group already exists
3131
let output = Command::new("dscl")
32-
.args(&[
32+
.args([
3333
".",
3434
"-read",
3535
&format!("/Groups/{}", GROUP_NAME),
@@ -41,20 +41,20 @@ impl MacOSJail {
4141
if output.status.success() {
4242
// Parse GID from output
4343
let stdout = String::from_utf8_lossy(&output.stdout);
44-
if let Some(line) = stdout.lines().find(|l| l.contains("PrimaryGroupID")) {
45-
if let Some(gid_str) = line.split_whitespace().last() {
46-
let gid = gid_str.parse::<u32>().context("Failed to parse GID")?;
47-
info!("Using existing group {} with GID {}", GROUP_NAME, gid);
48-
self.group_gid = Some(gid);
49-
return Ok(gid);
50-
}
44+
if let Some(line) = stdout.lines().find(|l| l.contains("PrimaryGroupID"))
45+
&& let Some(gid_str) = line.split_whitespace().last()
46+
{
47+
let gid = gid_str.parse::<u32>().context("Failed to parse GID")?;
48+
info!("Using existing group {} with GID {}", GROUP_NAME, gid);
49+
self.group_gid = Some(gid);
50+
return Ok(gid);
5151
}
5252
}
5353

5454
// Create group if it doesn't exist
5555
info!("Creating group {}", GROUP_NAME);
5656
let output = Command::new("sudo")
57-
.args(&["dseditgroup", "-o", "create", GROUP_NAME])
57+
.args(["dseditgroup", "-o", "create", GROUP_NAME])
5858
.output()
5959
.context("Failed to create group")?;
6060

@@ -67,7 +67,7 @@ impl MacOSJail {
6767

6868
// Get the newly created group's GID
6969
let output = Command::new("dscl")
70-
.args(&[
70+
.args([
7171
".",
7272
"-read",
7373
&format!("/Groups/{}", GROUP_NAME),
@@ -77,13 +77,13 @@ impl MacOSJail {
7777
.context("Failed to read group GID")?;
7878

7979
let stdout = String::from_utf8_lossy(&output.stdout);
80-
if let Some(line) = stdout.lines().find(|l| l.contains("PrimaryGroupID")) {
81-
if let Some(gid_str) = line.split_whitespace().last() {
82-
let gid = gid_str.parse::<u32>().context("Failed to parse GID")?;
83-
info!("Created group {} with GID {}", GROUP_NAME, gid);
84-
self.group_gid = Some(gid);
85-
return Ok(gid);
86-
}
80+
if let Some(line) = stdout.lines().find(|l| l.contains("PrimaryGroupID"))
81+
&& let Some(gid_str) = line.split_whitespace().last()
82+
{
83+
let gid = gid_str.parse::<u32>().context("Failed to parse GID")?;
84+
info!("Created group {} with GID {}", GROUP_NAME, gid);
85+
self.group_gid = Some(gid);
86+
return Ok(gid);
8787
}
8888

8989
anyhow::bail!("Failed to get GID for group {}", GROUP_NAME)
@@ -122,7 +122,7 @@ pass on lo0
122122
// Load rules into anchor
123123
info!("Loading PF rules from {}", self.pf_rules_path);
124124
let output = Command::new("sudo")
125-
.args(&["pfctl", "-a", PF_ANCHOR_NAME, "-f", &self.pf_rules_path])
125+
.args(["pfctl", "-a", PF_ANCHOR_NAME, "-f", &self.pf_rules_path])
126126
.output()
127127
.context("Failed to load PF rules")?;
128128

@@ -134,7 +134,7 @@ pass on lo0
134134
}
135135

136136
// Enable PF if not already enabled
137-
let _ = Command::new("sudo").args(&["pfctl", "-E"]).output();
137+
let _ = Command::new("sudo").args(["pfctl", "-E"]).output();
138138

139139
info!("PF rules loaded successfully");
140140
Ok(())
@@ -146,7 +146,7 @@ pass on lo0
146146

147147
// Flush the anchor
148148
let output = Command::new("sudo")
149-
.args(&["pfctl", "-a", PF_ANCHOR_NAME, "-F", "all"])
149+
.args(["pfctl", "-a", PF_ANCHOR_NAME, "-F", "all"])
150150
.output()
151151
.context("Failed to flush PF anchor")?;
152152

@@ -170,7 +170,7 @@ impl Jail for MacOSJail {
170170
fn setup(&mut self, _proxy_port: u16) -> Result<()> {
171171
// Check if we have sudo access
172172
let output = Command::new("sudo")
173-
.args(&["-n", "true"])
173+
.args(["-n", "true"])
174174
.output()
175175
.context("Failed to check sudo access")?;
176176

@@ -182,7 +182,7 @@ impl Jail for MacOSJail {
182182

183183
// Check if PF is available
184184
let output = Command::new("pfctl")
185-
.args(&["-s", "info"])
185+
.args(["-s", "info"])
186186
.output()
187187
.context("Failed to check PF availability")?;
188188

src/proxy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ mod tests {
288288

289289
let (http_port, https_port) = proxy.start().await.unwrap();
290290

291-
assert!(http_port >= 8000 && http_port <= 8999);
292-
assert!(https_port >= 8000 && https_port <= 8999);
291+
assert!((8000..=8999).contains(&http_port));
292+
assert!((8000..=8999).contains(&https_port));
293293
assert_ne!(http_port, https_port);
294294
}
295295
}

src/proxy_tls.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,30 +111,30 @@ async fn extract_sni_from_stream(stream: &mut TcpStream) -> Result<Option<String
111111
match parse_tls_plaintext(&buf[..n]) {
112112
Ok((_, record)) => {
113113
// Check if this is a handshake message
114-
if let Some(TlsMessage::Handshake(handshake)) = record.msg.first() {
115-
// Check if it's a ClientHello
116-
if let tls_parser::TlsMessageHandshake::ClientHello(client_hello) = &handshake {
117-
// Look for the SNI extension in the raw extensions
118-
if let Some(ext_data) = client_hello.ext {
119-
// Parse the extensions
120-
if let Ok(exts) = tls_parser::parse_tls_extensions(ext_data) {
121-
for ext in exts.1 {
122-
if let tls_parser::TlsExtension::SNI(sni_list) = ext {
123-
// Get the first hostname from the SNI list
124-
for sni in sni_list.iter() {
125-
if let (tls_parser::SNIType::HostName, data) = sni {
126-
if let Ok(hostname) = std::str::from_utf8(data) {
127-
debug!("Extracted SNI hostname: {}", hostname);
128-
return Ok(Some(hostname.to_string()));
129-
}
130-
}
114+
if let Some(TlsMessage::Handshake(tls_parser::TlsMessageHandshake::ClientHello(
115+
client_hello,
116+
))) = record.msg.first()
117+
{
118+
// Look for the SNI extension in the raw extensions
119+
if let Some(ext_data) = client_hello.ext {
120+
// Parse the extensions
121+
if let Ok(exts) = tls_parser::parse_tls_extensions(ext_data) {
122+
for ext in exts.1 {
123+
if let tls_parser::TlsExtension::SNI(sni_list) = ext {
124+
// Get the first hostname from the SNI list
125+
for sni in sni_list.iter() {
126+
if let (tls_parser::SNIType::HostName, data) = sni
127+
&& let Ok(hostname) = std::str::from_utf8(data)
128+
{
129+
debug!("Extracted SNI hostname: {}", hostname);
130+
return Ok(Some(hostname.to_string()));
131131
}
132132
}
133133
}
134134
}
135135
}
136-
debug!("ClientHello has no SNI extension");
137136
}
137+
debug!("ClientHello has no SNI extension");
138138
}
139139
}
140140
Err(e) => {
@@ -541,12 +541,12 @@ async fn proxy_https_request(
541541
mod tests {
542542
use super::*;
543543
use crate::rules::Rule;
544-
use rustls::{ClientConfig, ServerConfig};
544+
use rustls::ClientConfig;
545545
use std::sync::Arc;
546546
use tempfile::TempDir;
547547
use tokio::io::{AsyncReadExt, AsyncWriteExt};
548548
use tokio::net::{TcpListener, TcpStream};
549-
use tokio_rustls::{TlsAcceptor, TlsConnector};
549+
use tokio_rustls::TlsConnector;
550550

551551
async fn create_test_cert_manager() -> Arc<CertificateManager> {
552552
let temp_dir = TempDir::new().unwrap();

src/tls.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ impl CertificateManager {
197197

198198
// Sign certificate with CA using the shared key pair
199199
let cert = params.signed_by(&self.server_key_pair, &self.ca_cert, &self.ca_key_pair)?;
200-
let cert_der = CertificateDer::from(cert.der().clone());
200+
let cert_der = cert.der().clone();
201201

202202
// Also include CA cert in chain
203203
let ca_cert_der = self.ca_cert.der().clone();
204-
let ca_cert_der = CertificateDer::from(ca_cert_der);
204+
// ca_cert_der is already the correct type
205205
let cert_chain = vec![cert_der, ca_cert_der];
206206

207207
// Cache the certificate chain (not the key, since it's shared)
@@ -241,23 +241,19 @@ impl CertificateManager {
241241
.map(|p| p.to_string_lossy().to_string())
242242
.unwrap_or_else(|| ".".to_string());
243243

244-
let mut env_vars = Vec::new();
245-
246-
// OpenSSL/LibreSSL-based tools (generic)
247-
env_vars.push(("SSL_CERT_FILE".to_string(), ca_path_str.clone()));
248-
env_vars.push(("SSL_CERT_DIR".to_string(), ca_dir));
249-
250-
// curl (works with OpenSSL/LibreSSL builds)
251-
env_vars.push(("CURL_CA_BUNDLE".to_string(), ca_path_str.clone()));
252-
253-
// Git
254-
env_vars.push(("GIT_SSL_CAINFO".to_string(), ca_path_str.clone()));
255-
256-
// Python requests
257-
env_vars.push(("REQUESTS_CA_BUNDLE".to_string(), ca_path_str.clone()));
258-
259-
// Node.js
260-
env_vars.push(("NODE_EXTRA_CA_CERTS".to_string(), ca_path_str));
244+
let env_vars = vec![
245+
// OpenSSL/LibreSSL-based tools (generic)
246+
("SSL_CERT_FILE".to_string(), ca_path_str.clone()),
247+
("SSL_CERT_DIR".to_string(), ca_dir),
248+
// curl (works with OpenSSL/LibreSSL builds)
249+
("CURL_CA_BUNDLE".to_string(), ca_path_str.clone()),
250+
// Git
251+
("GIT_SSL_CAINFO".to_string(), ca_path_str.clone()),
252+
// Python requests
253+
("REQUESTS_CA_BUNDLE".to_string(), ca_path_str.clone()),
254+
// Node.js
255+
("NODE_EXTRA_CA_CERTS".to_string(), ca_path_str),
256+
];
261257

262258
Ok(env_vars)
263259
}

tests/common/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::process::Command;
33
/// Build httpjail binary and return the path
44
pub fn build_httpjail() -> Result<String, String> {
55
let output = Command::new("cargo")
6-
.args(&["build", "--bin", "httpjail"])
6+
.args(["build", "--bin", "httpjail"])
77
.output()
88
.map_err(|e| format!("Failed to build httpjail: {}", e))?;
99

@@ -148,18 +148,20 @@ pub fn has_sudo() -> bool {
148148
#[allow(dead_code)]
149149
pub fn cleanup_pf_rules() {
150150
let _ = Command::new("sudo")
151-
.args(&["pfctl", "-a", "httpjail", "-F", "all"])
151+
.args(["pfctl", "-a", "httpjail", "-F", "all"])
152152
.output();
153153
}
154154

155155
/// Check if running as root (for macOS sudo tests)
156156
#[cfg(target_os = "macos")]
157+
#[allow(dead_code)]
157158
pub fn is_root() -> bool {
158159
unsafe { libc::geteuid() == 0 }
159160
}
160161

161162
/// Skip test if not running as root
162163
#[cfg(target_os = "macos")]
164+
#[allow(dead_code)]
163165
pub fn require_sudo() {
164166
if !is_root() {
165167
eprintln!("\n⚠️ Test requires root privileges.");

tests/jail_integration.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ mod macos_jail_integration {
1111
fn ensure_httpjail_group() -> Result<(), String> {
1212
// Check if group exists
1313
let check = Command::new("dscl")
14-
.args(&[".", "-read", "/Groups/httpjail"])
14+
.args([".", "-read", "/Groups/httpjail"])
1515
.output()
1616
.map_err(|e| format!("Failed to check group: {}", e))?;
1717

1818
if !check.status.success() {
1919
// Create the group
2020
println!("Creating httpjail group...");
2121
let create = Command::new("sudo")
22-
.args(&["dseditgroup", "-o", "create", "httpjail"])
22+
.args(["dseditgroup", "-o", "create", "httpjail"])
2323
.output()
2424
.map_err(|e| format!("Failed to create group: {}", e))?;
2525

@@ -37,15 +37,15 @@ mod macos_jail_integration {
3737
/// Clean up PF rules
3838
fn cleanup_pf_rules() {
3939
let _ = Command::new("sudo")
40-
.args(&["pfctl", "-a", "httpjail", "-F", "all"])
40+
.args(["pfctl", "-a", "httpjail", "-F", "all"])
4141
.output();
4242
}
4343

4444
/// Run httpjail with given arguments
4545
fn run_httpjail(args: Vec<&str>) -> Result<(i32, String, String), String> {
4646
// Build the httpjail binary first
4747
let build = Command::new("cargo")
48-
.args(&["build", "--bin", "httpjail"])
48+
.args(["build", "--bin", "httpjail"])
4949
.output()
5050
.map_err(|e| format!("Failed to build: {}", e))?;
5151

0 commit comments

Comments
 (0)