@@ -3,11 +3,21 @@ use std::error::Error;
33use crate :: assert_error;
44use crate :: auth_monitor_options:: AuthMonitorOptions ;
55use crate :: auth_monitor_params:: {
6- AuthMonitorParams , MAX_FAILED_ATTEMPTS_OPTION , RESET_AFTER_SECONDS_OPTION ,
6+ AuthMonitorParams , IGNORE_SUBSEQUENT_FAILS_MS_OPTION , MAX_FAILED_ATTEMPTS_OPTION ,
7+ RESET_AFTER_SECONDS_OPTION ,
78} ;
89
910const FILEPATH : & str = "/var/log/auth.log" ;
10- const ALL_OPTIONS : [ & str ; 2 ] = [ MAX_FAILED_ATTEMPTS_OPTION , RESET_AFTER_SECONDS_OPTION ] ;
11+ const ALL_OPTIONS : [ & str ; 3 ] = [
12+ MAX_FAILED_ATTEMPTS_OPTION ,
13+ RESET_AFTER_SECONDS_OPTION ,
14+ IGNORE_SUBSEQUENT_FAILS_MS_OPTION ,
15+ ] ;
16+
17+ const ZERO_VALUE_ALLOWED_OPTIONS : [ & str ; 1 ] = [ IGNORE_SUBSEQUENT_FAILS_MS_OPTION ] ;
18+
19+ const ZERO_VALUE_NOT_ALLOWED_OPTIONS : [ & str ; 2 ] =
20+ [ MAX_FAILED_ATTEMPTS_OPTION , RESET_AFTER_SECONDS_OPTION ] ;
1121
1222type AuthMonitorResult = Result < AuthMonitorParams , Box < dyn Error > > ;
1323
@@ -94,11 +104,16 @@ fn when_parsing_filepath_with_one_option_with_correct_value_then_return_params_w
94104 true => value,
95105 false => default_params. options . reset_after_seconds ,
96106 } ;
107+ let ignore_subsequent_fails_ms = match option == IGNORE_SUBSEQUENT_FAILS_MS_OPTION {
108+ true => value,
109+ false => default_params. options . ignore_subsequent_fails_ms ,
110+ } ;
97111 let expected = AuthMonitorParams {
98112 filepath : String :: from ( FILEPATH ) ,
99113 options : AuthMonitorOptions {
100114 max_failed_attempts,
101115 reset_after_seconds,
116+ ignore_subsequent_fails_ms,
102117 } ,
103118 } ;
104119 expect_equals ( AuthMonitorParams :: from_arguments ( & arguments) , & expected) ;
@@ -141,32 +156,48 @@ fn when_parsing_option_with_no_value_then_return_no_value_error() {
141156}
142157
143158#[ test]
144- fn when_parsing_option_with_value_less_than_0_then_invalid_value_error ( ) {
145- let invalid_values = [ 0 , -1 , -1024 , i32:: MIN ] ;
146- for option in ALL_OPTIONS {
147- for value in invalid_values {
159+ fn when_parsing_option_with_out_of_range_value_then_return_value_out_of_range_error ( ) {
160+ let zero_not_allowed_invalid_values = [ 0 , -1 , -1024 , i32:: MIN ] ;
161+ for option in ZERO_VALUE_NOT_ALLOWED_OPTIONS {
162+ for value in zero_not_allowed_invalid_values {
148163 let option_argument = format ! ( "--{}={}" , option, value) ;
149164 let arguments = [ String :: from ( FILEPATH ) , option_argument] ;
150165 let expected = format ! ( "{} must be greater than 0" , option) ;
151166 assert_error ! ( AuthMonitorParams :: from_arguments( & arguments) , expected) ;
152167 }
153168 }
169+
170+ let zero_allowed_invalid_values = [ -1 , -1024 , i32:: MIN ] ;
171+ for option in ZERO_VALUE_ALLOWED_OPTIONS {
172+ for value in zero_allowed_invalid_values {
173+ let option_argument = format ! ( "--{}={}" , option, value) ;
174+ let arguments = [ String :: from ( FILEPATH ) , option_argument] ;
175+ let expected = format ! ( "{} must be greater than or equal 0" , option) ;
176+ assert_error ! ( AuthMonitorParams :: from_arguments( & arguments) , expected) ;
177+ }
178+ }
154179}
155180
156181#[ test]
157182fn when_parsing_filename_and_multiple_options_then_return_params_with_parsed_values ( ) {
158183 let max_failed_attempts = 10 ;
159184 let reset_after_seconds = 3600 ;
185+ let ignore_subsequent_fails_ms = 350 ;
160186 let arguments = [
161187 String :: from ( FILEPATH ) ,
162188 format ! ( "--{}={}" , MAX_FAILED_ATTEMPTS_OPTION , max_failed_attempts) ,
163189 format ! ( "--{}={}" , RESET_AFTER_SECONDS_OPTION , reset_after_seconds) ,
190+ format ! (
191+ "--{}={}" ,
192+ IGNORE_SUBSEQUENT_FAILS_MS_OPTION , ignore_subsequent_fails_ms
193+ ) ,
164194 ] ;
165195 let expected = AuthMonitorParams {
166196 filepath : String :: from ( FILEPATH ) ,
167197 options : AuthMonitorOptions {
168198 max_failed_attempts,
169199 reset_after_seconds,
200+ ignore_subsequent_fails_ms,
170201 } ,
171202 } ;
172203 expect_equals ( AuthMonitorParams :: from_arguments ( & arguments) , & expected) ;
0 commit comments