test: lower bcrypt cost in tests
The default is 12 but we can go down to 4 to waste less time on this.
96 unmodified lines97989910010110110210310410529 unmodified lines13513613713813913914014114214214314414514652 unmodified lines96 unmodified lines
test-unit: SQLX_OFFLINE=true cargo test --test it -- dpop_unit:: validation_edge_cases:: scope_edge_cases::
store_run := "SQLX_OFFLINE=true TRANQUIL_TEST_BACKEND=store TRANQUIL_PDS_ALLOW_INSECURE_SECRETS=1 DISABLE_RATE_LIMITING=1 TRANQUIL_LEXICON_OFFLINE=1 SKIP_IMPORT_VERIFICATION=true cargo nextest run --workspace --exclude tranquil-store --features tranquil-store/skip-fsync"store_run := "SQLX_OFFLINE=true TRANQUIL_TEST_BACKEND=store TRANQUIL_PDS_ALLOW_INSECURE_SECRETS=1 DISABLE_RATE_LIMITING=1 TRANQUIL_LEXICON_OFFLINE=1 SKIP_IMPORT_VERIFICATION=true cargo nextest run --workspace --exclude tranquil-store --features tranquil-store/skip-fsync,tranquil-api/low-bcrypt-cost"store_test := store_run + " -E 'not (binary(it) and test(/^store_parity::/)) and not (package(tranquil-signal) and test(/^tests::/))'"
test-auth: {{store_run}} --test it -E 'test(/^(oauth|oauth_lifecycle|oauth_scopes|oauth_security|jwt_security|session_management|change_password|password_reset)::/)'29 unmodified lines {{store_run}} --test it -E 'test(/^{{name}}::/)'
test-full *args: @just services-up eval "$(tranquil-dev-services env)" && SQLX_OFFLINE=true cargo nextest run --workspace --exclude tranquil-store --features tranquil-pds/s3 {{args}} eval "$(tranquil-dev-services env)" && SQLX_OFFLINE=true cargo nextest run --workspace --exclude tranquil-store --features tranquil-pds/s3,tranquil-api/low-bcrypt-cost {{args}}
test-pg *args: SQLX_OFFLINE=true ./scripts/run-tests.sh {{args}} SQLX_OFFLINE=true ./scripts/run-tests.sh --features tranquil-api/low-bcrypt-cost {{args}}
services-up: tranquil-dev-services up
52 unmodified lines49 unmodified lines505152535449 unmodified lines
[features]bsky = ["bsky-support"]bsky-support = []low-bcrypt-cost = []1123451 unmodified line7891011121314151617181920262 unmodified linesExpand all2832842852862812872882892902911 unmodified line29329429529629129729829930030123 unmodified linesuse bcrypt::{DEFAULT_COST, hash};use bcrypt::hash;use chrono::{DateTime, Utc};use std::collections::HashMap;use tracing::{error, warn};use tranquil_db_traits::{CommsChannel, DidWebOverrides, SessionRepository, UserRepository};1 unmodified lineuse tranquil_pds::api::error::DbResultExt;use tranquil_pds::types::{AtIdentifier, Did, Handle, PasswordHash};use tranquil_types::{DiscordUsername, SignalUsername, TelegramUsername};
#[cfg(not(feature = "low-bcrypt-cost"))]const PASSWORD_HASH_COST: u32 = bcrypt::DEFAULT_COST;// Use a lower bcrypt cost in tests.#[cfg(feature = "low-bcrypt-cost")]const PASSWORD_HASH_COST: u32 = 4;
pub struct ResolvedRepo { pub user_id: uuid::Uuid, pub did: Did, pub handle: Handle,262 unmodified linesExpand all })}
pub fn hash_or_internal_error(value: &str) -> Result<PasswordHash, ApiError> { bcrypt::hash(value, DEFAULT_COST) bcrypt::hash(value, PASSWORD_HASH_COST) .map(PasswordHash::new) .map_err(|e| { error!("Bcrypt hash error: {:?}", e); ApiError::InternalError(None)1 unmodified line}
pub async fn hash_password_async(password: &str) -> Result<PasswordHash, ApiError> { let password = password.to_string(); tokio::task::spawn_blocking(move || hash(password, DEFAULT_COST)) tokio::task::spawn_blocking(move || hash(password, PASSWORD_HASH_COST)) .await .map_err(|e| { error!("Failed to spawn blocking task: {:?}", e); ApiError::InternalError(None)23 unmodified lines