diff options
| author | KunoiSayami <[email protected]> | 2026-06-11 14:53:23 +0800 |
|---|---|---|
| committer | KunoiSayami <[email protected]> | 2026-06-11 14:53:23 +0800 |
| commit | 9e67f120b797bae10bd226bbb4632f8d19a24361 (patch) | |
| tree | d94a9a067eb05cf78bee7282ff7c9f093c360bfc /src/datastructures.rs | |
| parent | c708a63f7e5b9b22f8095ede0be56115eccbbac8 (diff) | |
fix: Fix OsRng import and refactor Redis connection setup
- 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 <[email protected]>
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'src/datastructures.rs')
| -rw-r--r-- | src/datastructures.rs | 11 |
1 files changed, 10 insertions, 1 deletions
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<redis::aio::MultiplexedConnection> { + 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<Option<Self>> { 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) |
