From aa27c72cbb9ffda6fc4b0c8e3d3eb4956192f222 Mon Sep 17 00:00:00 2001 From: "ilblackdragon@gmail.com" Date: Wed, 25 Mar 2026 18:58:26 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20resolve=20CI=20failures=20=E2=80=94=20fo?= =?UTF-8?q?rmatting,=20no-panics=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Run cargo fmt on test code - Replace .expect() with const NonZeroUsize in DbAuthenticator - Add // safety: comments for test-only code in multi_tenant.rs Co-Authored-By: Claude Opus 4.6 (1M context) --- src/channels/web/auth.rs | 11 ++++++----- src/channels/web/tests/multi_tenant.rs | 27 +++++++------------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/channels/web/auth.rs b/src/channels/web/auth.rs index 7a4afd05..15c2e53f 100644 --- a/src/channels/web/auth.rs +++ b/src/channels/web/auth.rs @@ -142,15 +142,16 @@ impl DbAuthenticator { /// Cache TTL — how long a successful auth is cached before re-querying the DB. const CACHE_TTL_SECS: u64 = 60; /// Maximum cache entries to prevent unbounded growth. - const MAX_CACHE_ENTRIES: usize = 1024; + // SAFETY: 1024 is non-zero, so the unwrap in `new()` is infallible. + const MAX_CACHE_ENTRIES: NonZeroUsize = match NonZeroUsize::new(1024) { + Some(v) => v, + None => unreachable!(), + }; pub fn new(store: Arc) -> Self { Self { store, - cache: Arc::new(RwLock::new(lru::LruCache::new( - NonZeroUsize::new(Self::MAX_CACHE_ENTRIES) - .expect("MAX_CACHE_ENTRIES must be non-zero"), - ))), + cache: Arc::new(RwLock::new(lru::LruCache::new(Self::MAX_CACHE_ENTRIES))), } } diff --git a/src/channels/web/tests/multi_tenant.rs b/src/channels/web/tests/multi_tenant.rs index c53436ba..f92073a4 100644 --- a/src/channels/web/tests/multi_tenant.rs +++ b/src/channels/web/tests/multi_tenant.rs @@ -856,8 +856,8 @@ mod auth_enforcement { mod admin_role_enforcement { use super::*; use crate::channels::web::handlers::users::{ - users_activate_handler, users_detail_handler, users_list_handler, - users_suspend_handler, users_update_handler, + users_activate_handler, users_detail_handler, users_list_handler, users_suspend_handler, + users_update_handler, }; use axum::routing::patch; @@ -888,10 +888,7 @@ mod admin_role_enforcement { .route("/api/admin/users", get(users_list_handler)) .route("/api/admin/users/{id}", get(users_detail_handler)) .route("/api/admin/users/{id}", patch(users_update_handler)) - .route( - "/api/admin/users/{id}/suspend", - post(users_suspend_handler), - ) + .route("/api/admin/users/{id}/suspend", post(users_suspend_handler)) .route( "/api/admin/users/{id}/activate", post(users_activate_handler), @@ -926,18 +923,8 @@ mod admin_role_enforcement { assert_forbidden_for_member(&app, Method::GET, "/api/admin/users").await; assert_forbidden_for_member(&app, Method::GET, "/api/admin/users/some-id").await; - assert_forbidden_for_member( - &app, - Method::POST, - "/api/admin/users/some-id/suspend", - ) - .await; - assert_forbidden_for_member( - &app, - Method::POST, - "/api/admin/users/some-id/activate", - ) - .await; + assert_forbidden_for_member(&app, Method::POST, "/api/admin/users/some-id/suspend").await; + assert_forbidden_for_member(&app, Method::POST, "/api/admin/users/some-id/activate").await; } #[tokio::test] @@ -972,7 +959,7 @@ mod db_auth_cache { // Access the internal cache and verify LRU eviction. // We can't easily test through `authenticate()` since it hits the DB, // so we test the LRU cache directly. - let cap = std::num::NonZeroUsize::new(4).unwrap(); + let cap = std::num::NonZeroUsize::new(4).unwrap(); // safety: test-only, 4 is non-zero let cache: lru::LruCache<[u8; 32], (UserIdentity, Instant)> = lru::LruCache::new(cap); let cache = Arc::new(tokio::sync::RwLock::new(cache)); @@ -994,7 +981,7 @@ mod db_auth_cache { ); } // Cache must be bounded at capacity, not grown to 10. - assert_eq!(c.len(), 4, "cache should be bounded to capacity"); + assert_eq!(c.len(), 4, "cache should be bounded to capacity"); // safety: test assertion } } }