Merge factors type for authentication

This commit is contained in:
2022-11-11 12:26:02 +01:00
parent 8d231c0b45
commit af383720b7
44 changed files with 1177 additions and 674 deletions

View File

@@ -19,7 +19,6 @@ pub struct CountFailedAttempt {
pub ip: IpAddr,
}
#[derive(Debug, Default)]
pub struct BruteForceActor {
failed_attempts: HashMap<IpAddr, Vec<u64>>,
@@ -28,10 +27,7 @@ pub struct BruteForceActor {
impl BruteForceActor {
pub fn clean_attempts(&mut self) {
#[allow(clippy::map_clone)]
let keys = self.failed_attempts
.keys()
.map(|i| *i)
.collect::<Vec<_>>();
let keys = self.failed_attempts.keys().map(|i| *i).collect::<Vec<_>>();
for ip in keys {
// Remove old attempts
@@ -102,7 +98,9 @@ mod test {
let mut actor = BruteForceActor::default();
actor.failed_attempts.insert(IP_1, vec![1, 10]);
actor.failed_attempts.insert(IP_2, vec![1, 10, time() + 10]);
actor.failed_attempts.insert(IP_3, vec![time() + 10, time() + 20]);
actor
.failed_attempts
.insert(IP_3, vec![time() + 10, time() + 20]);
actor.clean_attempts();