mirror of
https://tangled.org/tranquil.farm/tranquil-pds
synced 2026-09-26 04:04:14 +00:00
test: lower bcrypt cost in tests
The default is 12 but we can go down to 4 to waste less time on this.
This commit is contained in:
@@ -51,3 +51,4 @@ webauthn-rs = { workspace = true }
|
||||
[features]
|
||||
bsky = ["bsky-support"]
|
||||
bsky-support = []
|
||||
low-bcrypt-cost = []
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use bcrypt::{DEFAULT_COST, hash};
|
||||
use bcrypt::hash;
|
||||
use chrono::{DateTime, Utc};
|
||||
use std::collections::HashMap;
|
||||
use tracing::{error, warn};
|
||||
@@ -8,6 +8,12 @@ use 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,
|
||||
@@ -278,7 +284,7 @@ pub async fn verify_credential(
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -288,7 +294,7 @@ pub fn hash_or_internal_error(value: &str) -> Result<PasswordHash, ApiError> {
|
||||
|
||||
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);
|
||||
|
||||
@@ -98,7 +98,7 @@ test-store-asan:
|
||||
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:
|
||||
@@ -136,10 +136,10 @@ test-one 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
|
||||
|
||||
Reference in New Issue
Block a user