fix: Password uses char count not byte length, redact Debug output, tighten test assertion
Some checks failed
CI / Check / Test (push) Failing after 49s

This commit is contained in:
2026-06-10 03:23:23 +02:00
parent c4d6b68ef9
commit deae83cfd1
2 changed files with 10 additions and 3 deletions

View File

@@ -60,5 +60,6 @@ async fn test_register_short_password_fails() {
},
)
.await;
assert!(result.is_err());
let err = result.unwrap_err().to_string();
assert!(err.contains("8 characters"), "expected password length error, got: {err}");
}

View File

@@ -252,14 +252,20 @@ impl PosterUrl {
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, PartialEq, Eq)]
pub struct Password(String);
impl std::fmt::Debug for Password {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("Password([REDACTED])")
}
}
impl Password {
const MIN_LENGTH: usize = 8;
pub fn new(raw: String) -> Result<Self, DomainError> {
if raw.len() < Self::MIN_LENGTH {
if raw.chars().count() < Self::MIN_LENGTH {
Err(DomainError::ValidationError(
"Password must be at least 8 characters".into(),
))