mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 12:37:00 +01:00
Add test (#2323)
This commit is contained in:
parent
2be287c1ff
commit
b71b0460f3
|
@ -2002,6 +2002,7 @@ mod tests {
|
|||
use crate::idm::server::{IdmServer, IdmServerCredUpdateTransaction, IdmServerDelayed};
|
||||
use crate::idm::AuthState;
|
||||
use crate::prelude::*;
|
||||
use crate::utils::password_from_random_len;
|
||||
use crate::value::CredentialType;
|
||||
|
||||
const TEST_CURRENT_TIME: u64 = 6000;
|
||||
|
@ -2682,9 +2683,9 @@ mod tests {
|
|||
|
||||
// Test initially creating a credential.
|
||||
// - pw first
|
||||
|
||||
let pw = password_from_random_len(8);
|
||||
let err = cutxn
|
||||
.credential_primary_set_password(&cust, ct, "password")
|
||||
.credential_primary_set_password(&cust, ct, &pw)
|
||||
.unwrap_err();
|
||||
trace!(?err);
|
||||
assert!(match err {
|
||||
|
@ -2694,7 +2695,29 @@ mod tests {
|
|||
_ => false,
|
||||
});
|
||||
|
||||
// Test pw len of len minus 1
|
||||
let pw = password_from_random_len(test_pw_min_length - 1);
|
||||
let err = cutxn
|
||||
.credential_primary_set_password(&cust, ct, &pw)
|
||||
.unwrap_err();
|
||||
trace!(?err);
|
||||
assert!(match err {
|
||||
OperationError::PasswordQuality(details)
|
||||
if details == vec!(PasswordFeedback::TooShort(test_pw_min_length),) =>
|
||||
true,
|
||||
_ => false,
|
||||
});
|
||||
|
||||
// Test pw len of exact len
|
||||
let pw = password_from_random_len(test_pw_min_length);
|
||||
let c_status = cutxn
|
||||
.credential_primary_set_password(&cust, ct, &pw)
|
||||
.expect("Failed to update the primary cred password");
|
||||
|
||||
assert!(c_status.can_commit);
|
||||
|
||||
drop(cutxn);
|
||||
commit_session(idms, ct, cust).await;
|
||||
}
|
||||
|
||||
// Test set of primary account password
|
||||
|
|
|
@ -31,9 +31,15 @@ pub fn uuid_from_duration(d: Duration, sid: Sid) -> Uuid {
|
|||
uuid_from_u64_u32(d.as_secs(), d.subsec_nanos(), sid)
|
||||
}
|
||||
|
||||
pub(crate) fn password_from_random_len(len: u32) -> String {
|
||||
thread_rng()
|
||||
.sample_iter(&DistinctAlpha)
|
||||
.take(len as usize)
|
||||
.collect::<String>()
|
||||
}
|
||||
|
||||
pub fn password_from_random() -> String {
|
||||
let rand_string: String = thread_rng().sample_iter(&DistinctAlpha).take(48).collect();
|
||||
rand_string
|
||||
password_from_random_len(48)
|
||||
}
|
||||
|
||||
pub fn backup_code_from_random() -> HashSet<String> {
|
||||
|
|
Loading…
Reference in a new issue