@@ -55,58 +55,58 @@ public function testCheckRateLimitWithinEmailLimitReturnsAllowed()
55555656 $ ip = '192.168.1.1 ' ;
5757
58- // 4回の失敗を記録
59- for ($ i = 0 ; $ i < 4 ; $ i ++) {
58+ // 3回の失敗を記録(制限よりも十分に少ない)
59+ for ($ i = 0 ; $ i < 3 ; $ i ++) {
6060 SC_Helper_LoginRateLimit_Ex::recordLoginAttempt ($ email , $ ip , 'TestAgent ' , 0 );
6161 }
6262
6363 $ result = SC_Helper_LoginRateLimit_Ex::checkRateLimit ($ email , $ ip );
6464
6565 $ this ->assertTrue ($ result ['allowed ' ]);
66- $ this ->assertEquals (4 , $ result ['email_count ' ]);
66+ $ this ->assertEquals (3 , $ result ['email_count ' ]);
6767 }
6868
6969 /**
7070 * Test checkRateLimit at email limit boundary
7171 *
72- * メールアドレスのレート制限境界値(5回 )の場合、allowedを返す
72+ * メールアドレスのレート制限境界値(4回 )の場合、allowedを返す(5回目の試行まで許可)
7373 */
7474 public function testCheckRateLimitAtEmailLimitBoundaryReturnsAllowed ()
7575 {
76767777 $ ip = '192.168.1.1 ' ;
7878
79- // 5回の失敗を記録
80- for ($ i = 0 ; $ i < 5 ; $ i ++) {
79+ // 4回の失敗を記録(5回目の試行まで許可、6回目でブロック)
80+ for ($ i = 0 ; $ i < 4 ; $ i ++) {
8181 SC_Helper_LoginRateLimit_Ex::recordLoginAttempt ($ email , $ ip , 'TestAgent ' , 0 );
8282 }
8383
8484 $ result = SC_Helper_LoginRateLimit_Ex::checkRateLimit ($ email , $ ip );
8585
8686 $ this ->assertTrue ($ result ['allowed ' ]);
87- $ this ->assertEquals (5 , $ result ['email_count ' ]);
87+ $ this ->assertEquals (4 , $ result ['email_count ' ]);
8888 }
8989
9090 /**
9191 * Test checkRateLimit exceeds email limit
9292 *
93- * メールアドレスのレート制限超過(6回以上 )の場合、blockedを返す
93+ * メールアドレスのレート制限超過(5回以上 )の場合、blockedを返す(6回目の試行でブロック)
9494 */
9595 public function testCheckRateLimitExceedsEmailLimitReturnsBlocked ()
9696 {
97979898 $ ip = '192.168.1.1 ' ;
9999
100- // 6回の失敗を記録
101- for ($ i = 0 ; $ i < 6 ; $ i ++) {
100+ // 5回の失敗を記録(6回目の試行でブロック)
101+ for ($ i = 0 ; $ i < 5 ; $ i ++) {
102102 SC_Helper_LoginRateLimit_Ex::recordLoginAttempt ($ email , $ ip , 'TestAgent ' , 0 );
103103 }
104104
105105 $ result = SC_Helper_LoginRateLimit_Ex::checkRateLimit ($ email , $ ip );
106106
107107 $ this ->assertFalse ($ result ['allowed ' ]);
108108 $ this ->assertEquals ('email ' , $ result ['reason ' ]);
109- $ this ->assertEquals (6 , $ result ['email_count ' ]);
109+ $ this ->assertEquals (5 , $ result ['email_count ' ]);
110110 }
111111
112112 /**
@@ -118,56 +118,56 @@ public function testCheckRateLimitWithinIPLimitReturnsAllowed()
118118 {
119119 $ ip = '192.168.1.1 ' ;
120120
121- // 9回の失敗を異なるメールアドレスで記録
122- for ($ i = 0 ; $ i < 9 ; $ i ++) {
121+ // 8回の失敗を異なるメールアドレスで記録(制限よりも十分に少ない)
122+ for ($ i = 0 ; $ i < 8 ; $ i ++) {
123123 SC_Helper_LoginRateLimit_Ex::recordLoginAttempt ("test {$ i }@example.com " , $ ip , 'TestAgent ' , 0 );
124124 }
125125
126126 $ result = SC_Helper_LoginRateLimit_Ex::
checkRateLimit (
'[email protected] ' ,
$ ip);
127127
128128 $ this ->assertTrue ($ result ['allowed ' ]);
129- $ this ->assertEquals (9 , $ result ['ip_count ' ]);
129+ $ this ->assertEquals (8 , $ result ['ip_count ' ]);
130130 }
131131
132132 /**
133133 * Test checkRateLimit at IP limit boundary
134134 *
135- * IPアドレスのレート制限境界値(10回 )の場合、allowedを返す
135+ * IPアドレスのレート制限境界値(9回 )の場合、allowedを返す
136136 */
137137 public function testCheckRateLimitAtIPLimitBoundaryReturnsAllowed ()
138138 {
139139 $ ip = '192.168.1.1 ' ;
140140
141- // 10回の失敗を異なるメールアドレスで記録
142- for ($ i = 0 ; $ i < 10 ; $ i ++) {
141+ // 9回の失敗を異なるメールアドレスで記録(10回目の試行まで許可)
142+ for ($ i = 0 ; $ i < 9 ; $ i ++) {
143143 SC_Helper_LoginRateLimit_Ex::recordLoginAttempt ("test {$ i }@example.com " , $ ip , 'TestAgent ' , 0 );
144144 }
145145
146146 $ result = SC_Helper_LoginRateLimit_Ex::
checkRateLimit (
'[email protected] ' ,
$ ip);
147147
148148 $ this ->assertTrue ($ result ['allowed ' ]);
149- $ this ->assertEquals (10 , $ result ['ip_count ' ]);
149+ $ this ->assertEquals (9 , $ result ['ip_count ' ]);
150150 }
151151
152152 /**
153153 * Test checkRateLimit exceeds IP limit
154154 *
155- * IPアドレスのレート制限超過(11回以上 )の場合、blockedを返す
155+ * IPアドレスのレート制限超過(10回以上 )の場合、blockedを返す(11回目の試行でブロック)
156156 */
157157 public function testCheckRateLimitExceedsIPLimitReturnsBlocked ()
158158 {
159159 $ ip = '192.168.1.1 ' ;
160160
161- // 11回の失敗を異なるメールアドレスで記録
162- for ($ i = 0 ; $ i < 11 ; $ i ++) {
161+ // 10回の失敗を異なるメールアドレスで記録(11回目の試行でブロック)
162+ for ($ i = 0 ; $ i < 10 ; $ i ++) {
163163 SC_Helper_LoginRateLimit_Ex::recordLoginAttempt ("test {$ i }@example.com " , $ ip , 'TestAgent ' , 0 );
164164 }
165165
166166 $ result = SC_Helper_LoginRateLimit_Ex::
checkRateLimit (
'[email protected] ' ,
$ ip);
167167
168168 $ this ->assertFalse ($ result ['allowed ' ]);
169169 $ this ->assertEquals ('ip ' , $ result ['reason ' ]);
170- $ this ->assertEquals (11 , $ result ['ip_count ' ]);
170+ $ this ->assertEquals (10 , $ result ['ip_count ' ]);
171171 }
172172
173173 /**
0 commit comments