Little bit of refactoring

merge-requests/254/head
Torsten Flammiger 2 years ago
parent 4aefc29650
commit fc39b3447c

@ -10,7 +10,6 @@ use ruma::{
}; };
use std::{collections::BTreeMap, convert::TryInto, mem, sync::Arc}; use std::{collections::BTreeMap, convert::TryInto, mem, sync::Arc};
use tracing::warn; use tracing::warn;
use tracing::info;
use super::abstraction::Tree; use super::abstraction::Tree;
@ -137,31 +136,23 @@ impl Users {
Ok(users) Ok(users)
} }
/// A private helper to avoid double filtering the iterator in get_local_users(). /// Will only return with Some(username) if the password was not empty and the
/// username could be successfully parsed.
/// If utils::string_from_bytes(...) returns an error that username will be skipped /// If utils::string_from_bytes(...) returns an error that username will be skipped
/// and the error will be logged. TODO: add error cause. /// and the error will be logged.
#[tracing::instrument(skip(self))] #[tracing::instrument(skip(self))]
fn get_username_with_valid_password(&self, username: &[u8], password: &[u8]) -> Option<String> { fn get_username_with_valid_password(&self, username: &[u8], password: &[u8]) -> Option<String> {
// A valid password is not empty // A valid password is not empty
if password.len() > 0 { if password.is_empty() {
None
} else {
match utils::string_from_bytes(username) { match utils::string_from_bytes(username) {
Ok(u) => { Ok(u) => Some(u),
info!("list_local_users_test: found user {}", u); Err(e) => {
Some(u) warn!("Failed to parse username while calling get_local_users(): {}", e.to_string());
},
Err(_) => {
// let msg: String = format!(
// "Failed to parse username while calling get_local_users(): {}",
// e.to_string()
// );
Error::bad_database(
"Failed to parse username while calling get_username_on_valid_password",
);
None None
} }
} }
} else {
None
} }
} }

Loading…
Cancel
Save