Improve Playwright tests (#7752)

* Allow to lower KDF iterations for tests

* Only read CLIENT_KDF_ITER in builds with unsafe_test_mode

---------

Co-authored-by: Timshel <timshel@users.noreply.github.com>
Co-authored-by: Daniel García <dani-garcia@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-23 02:17:01 +01:00
1 parent cdf2035433
commit 6f7a7f7034
6 files changed
+67 -12

No files matched your search

+1 -1
View File
@@ -24,7 +24,7 @@ if [[ ! -z "$REPO_URL" ]] && [[ ! -z "$COMMIT_HASH" ]] ; then
fi
# Lower the KDF iterations default for faster tests.
sed -i 's/(6e5,2e6,6e5)/(1e5,2e6,1e5)/' /web-vault/app/main.*.js
sed -i 's/(6e5,2e6,6e5)/(6e3,2e6,6e3)/' /web-vault/app/main.*.js
# Generate a self signed cert
mkdir -p /data/ssl; cd /data/ssl
+4
View File
@@ -6,6 +6,8 @@ services:
build:
context: ..
dockerfile: Dockerfile
args:
DB: sqlite,mysql,postgresql,unsafe_test_mode
entrypoint: /bin/bash
restart: "no"
@@ -23,12 +25,14 @@ services:
env_file: ${DC_ENV_FILE:-.env}
environment:
- ADMIN_TOKEN
- CLIENT_KDF_ITER
- DATABASE_URL
- CLIENT_SUPPRESS_ONBOARDING
- EMAIL_2FA_AUTO_FALLBACK
- I_REALLY_WANT_VOLATILE_STORAGE
- LOG_LEVEL
- LOGIN_RATELIMIT_MAX_BURST
- PASSWORD_ITERATIONS
- SMTP_HOST
- SMTP_FROM
- SMTP_DEBUG
+2
View File
@@ -58,6 +58,8 @@ LOG_LEVEL=info,oidcwarden::sso=debug
LOGIN_RATELIMIT_MAX_BURST=100
ADMIN_TOKEN=admin
CLIENT_SUPPRESS_ONBOARDING=true
PASSWORD_ITERATIONS=6000
CLIENT_KDF_ITER=6000
SMTP_SECURITY=off
SMTP_PORT=${MAILDEV_SMTP_PORT}
+6 -6
View File
@@ -1039,8 +1039,8 @@ async fn post_password(data: Json<ChangePassData>, headers: Headers, conn: DbCon
}
fn set_kdf_data(user: &mut User, data: &KDFData) -> EmptyResult {
if data.kdf == UserKdfType::Pbkdf2 as i32 && data.kdf_iterations < 100_000 {
err!("PBKDF2 KDF iterations must be at least 100000.")
if data.kdf == UserKdfType::Pbkdf2 as i32 && data.kdf_iterations < CONFIG.client_kdf_iter() {
err!(format!("PBKDF2 KDF iterations must be at least {}.", CONFIG.client_kdf_iter()))
}
if data.kdf == UserKdfType::Argon2id as i32 {
@@ -2219,15 +2219,15 @@ fn unknown_email_kdf(email: &str) -> (i32, i32, Option<i32>, Option<i32>) {
const PBKDF2: i32 = UserKdfType::Pbkdf2 as i32;
const ARGON2ID: i32 = UserKdfType::Argon2id as i32;
// Same list as upstream, the default is in it twice to give it more weight
const KDF_SETTINGS: [(i32, i32, Option<i32>, Option<i32>); 6] = [
(User::CLIENT_KDF_TYPE_DEFAULT, User::CLIENT_KDF_ITER_DEFAULT, None, None),
(User::CLIENT_KDF_TYPE_DEFAULT, User::CLIENT_KDF_ITER_DEFAULT, None, None),
let kdf_settings: [(i32, i32, Option<i32>, Option<i32>); 6] = [
(User::CLIENT_KDF_TYPE_DEFAULT, CONFIG.client_kdf_iter(), None, None),
(User::CLIENT_KDF_TYPE_DEFAULT, CONFIG.client_kdf_iter(), None, None),
(PBKDF2, 100_000, None, None),
(PBKDF2, 5_000, None, None),
(ARGON2ID, 3, Some(64), Some(4)),
(ARGON2ID, 6, Some(32), Some(4)),
];
KDF_SETTINGS[crate::auth::prelogin_kdf_index(email, KDF_SETTINGS.len())]
kdf_settings[crate::auth::prelogin_kdf_index(email, kdf_settings.len())]
}
pub async fn prelogin(data: Json<PreloginData>, ip: ClientIp, conn: DbConn) -> JsonResult {
+53 -3
View File
@@ -71,9 +71,16 @@ macro_rules! make_config {
( @type $ty:ty, option) => { Option<$ty> };
( @type $ty:ty, $id:ident) => { $ty };
// Options that only builds with the `unsafe_test_mode` feature read
( @test_only test_def ) => { true };
( @test_only $none_action:ident ) => { false };
// Generate the values depending on none_action
( @build $value:expr, $config:expr, option, ) => { $value };
( @build $value:expr, $config:expr, def, $default:expr ) => { $value.unwrap_or($default) };
( @build $value:expr, $config:expr, test_def, $default:expr ) => {
if cfg!(feature = "unsafe_test_mode") { $value.unwrap_or($default) } else { $default }
};
( @build $value:expr, $config:expr, auto, $default_fn:expr ) => {{
match $value {
Some(v) => v,
@@ -286,6 +293,22 @@ macro_rules! make_config {
)+)+
}
/// Warns about each set `test_def` option in a build without the `unsafe_test_mode` feature, which ignores them.
fn warn_test_only_options(&self) {
if cfg!(feature = "unsafe_test_mode") {
return;
}
$($(
if make_config! { @test_only $none_action } && self.$name.is_some() {
// We can't use warn! here because logging isn't setup yet.
println!(
"[WARNING] {} is only read by builds with the `unsafe_test_mode` feature, ignoring it.",
pastey::paste!(stringify!([<$name:upper>]))
);
}
)+)+
}
/// Merges the values of both builders into a new builder.
/// If both have the same element, `other` wins.
fn merge(&self, other: &Self, show_overrides: bool, overrides: &mut Vec<&str>) -> Self {
@@ -352,6 +375,8 @@ macro_rules! make_config {
r#type: &'static str,
doc: ElementDoc,
overridden: bool,
#[serde(skip)]
test_only: bool,
}
#[derive(Serialize)]
@@ -411,10 +436,20 @@ macro_rules! make_config {
r#type: get_form_type(stringify!($ty)),
doc: get_doc(concat!($($doc),+)),
overridden: overridden.contains(&pastey::paste!(stringify!([<$name:upper>]))),
test_only: make_config! { @test_only $none_action },
},
)+], // End of elements repetition
},
)+]; // End of groups repetition
// Options only test builds read aren't shown in the others
let data: Vec<GroupData> = data
.into_iter()
.map(|mut group| {
group.elements.retain(|e| !e.test_only || cfg!(feature = "unsafe_test_mode"));
group
})
.collect();
serde_json::to_value(data).unwrap()
}
@@ -513,6 +548,8 @@ macro_rules! make_config {
//
// Where action applied when the value wasn't provided and can be:
// def: Use a default value
// test_def: Use a default value, which only builds with the `unsafe_test_mode` feature let you change. Other builds
// warn at startup when it's set, ignore it, and don't show it in the admin panel
// auto: Value is auto generated based on other values
// option: Value is optional
// generated: Value is always autogenerated and it's original value ignored
@@ -682,6 +719,8 @@ make_config! {
client {
/// Control whether clients onboarding interstitials are suppressed |> post-login welcome dialogs, extension install prompts, setup extension redirects, and premium upsell modals
client_suppress_onboarding: bool, true, def, false;
/// In most cases this value is set by the client |> Will block clients from setting too low of a value in `accounts::post_kdf`
client_kdf_iter: i32, false, test_def, 600_000;
},
/// Advanced settings
@@ -961,6 +1000,17 @@ make_config! {
},
}
fn check_iterations(iterations: i32, key: &str) -> Result<(), Error> {
if iterations < 100_000 {
#[cfg(feature = "unsafe_test_mode")]
println!("[WARNING] {key} should be at least 100000 or higher. The default is 600000!");
#[cfg(not(feature = "unsafe_test_mode"))]
err!(format!("{key} should be at least 100000 or higher. The default is 600000!"));
}
Ok(())
}
fn validate_config(cfg: &ConfigItems, on_update: bool) -> Result<(), Error> {
// Validate connection URL is valid and DB feature is enabled
#[cfg(sqlite)]
@@ -995,9 +1045,8 @@ fn validate_config(cfg: &ConfigItems, on_update: bool) -> Result<(), Error> {
}
}
if cfg.password_iterations < 100_000 {
err!("PASSWORD_ITERATIONS should be at least 100000 or higher. The default is 600000!");
}
check_iterations(cfg.password_iterations, "PASSWORD_ITERATIONS")?;
check_iterations(cfg.client_kdf_iter, "CLIENT_KDF_ITER")?;
let limit = 256;
if !(1..=limit).contains(&cfg.database_max_conns) {
@@ -1554,6 +1603,7 @@ impl Config {
// Fill any missing with defaults
let config = builder.build();
if !SKIP_CONFIG_VALIDATION.load(Ordering::Relaxed) {
builder.warn_test_only_options();
validate_config(&config, false)?;
}
+1 -2
View File
@@ -134,7 +134,6 @@ impl UserStampException {
/// Local methods
impl User {
pub const CLIENT_KDF_TYPE_DEFAULT: i32 = UserKdfType::Pbkdf2 as i32;
pub const CLIENT_KDF_ITER_DEFAULT: i32 = 600_000;
pub fn new(email: &str, name: Option<String>) -> Self {
let now = Utc::now().naive_utc();
@@ -172,7 +171,7 @@ impl User {
excluded_globals: "[]".to_owned(),
client_kdf_type: Self::CLIENT_KDF_TYPE_DEFAULT,
client_kdf_iter: Self::CLIENT_KDF_ITER_DEFAULT,
client_kdf_iter: CONFIG.client_kdf_iter(),
client_kdf_memory: None,
client_kdf_parallelism: None,