From 9e67f120b797bae10bd226bbb4632f8d19a24361 Mon Sep 17 00:00:00 2001 From: KunoiSayami Date: Thu, 11 Jun 2026 14:53:23 +0800 Subject: fix: Fix OsRng import and refactor Redis connection setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix password-hash version mismatch (0.6→0.5) causing OsRng to be gated behind missing getrandom feature; enable argon2 rand feature - Extract get_redis_connection() helper to deduplicate Redis client setup across authentication, repo control, and tests - Tighten username validation regex to require ≥2 chars and disallow leading/trailing dots or hyphens - Handle malformed cookies without split_once gracefully (continue instead of panic) - Fix typos: "rated commands" → "related commands" in CLI help text Co-Authored-By: Claude Sonnet 4.6 Signed-off-by: KunoiSayami --- src/datastructures.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/datastructures.rs') diff --git a/src/datastructures.rs b/src/datastructures.rs index 4ca1a00..82c0325 100644 --- a/src/datastructures.rs +++ b/src/datastructures.rs @@ -71,6 +71,13 @@ pub fn rand_str(len: usize) -> String { password } +pub(crate) async fn get_redis_connection( + redis_url: &str, +) -> Result { + let client = redis::Client::open(redis_url)?; + Ok(client.get_multiplexed_async_connection().await?) +} + pub(crate) trait TestSuite { fn generate_test_config() -> Self; } @@ -532,7 +539,9 @@ impl Cookie { pub fn load_from_request(cookies: &str) -> Result> { let mut cookie_self = None; for cookie in cookies.split(';').map(|x| x.trim()) { - let (key, value) = cookie.split_once('=').unwrap(); + let Some((key, value)) = cookie.split_once('=') else { + continue; + }; if key.eq("cgit_auth") { let value = base64::engine::general_purpose::STANDARD .decode(value) -- cgit v1.3.1