Merge factors type for authentication
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user