Issue #2989985 by mcdruid, colorfulCoder, tatarbj, Fabianx, paulocs: User...
Issue #2989985 by mcdruid, colorfulCoder, tatarbj, Fabianx, paulocs: User module's flood controls should do better logging, plus add new hook_user_flood_control()
form_set_error('name',format_plural(variable_get('user_failed_login_user_limit',5),'Sorry, there has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.','Sorry, there have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.',array('@url'=>url('user/password'))));
// We did not find a uid, so the limit is IP-based.
form_set_error('name',t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or <a href="@url">request a new password</a>.',array('@url'=>url('user/password'))));
@@ -453,12 +453,19 @@ class UserLoginTestCase extends DrupalWebTestCase {
$this->drupalPost('user',$edit,t('Log in'));
$this->assertNoFieldByXPath("//input[@name='pass' and @value!='']",NULL,'Password value attribute is blank.');
if(isset($flood_trigger)){
$this->assertResponse(403);
$user_log=db_query_range('SELECT message FROM {watchdog} WHERE type = :type ORDER BY wid DESC',0,1,array(':type'=>'user'))->fetchField();
$user_flood_test_log=db_query_range('SELECT message FROM {watchdog} WHERE type = :type ORDER BY wid DESC',0,1,array(':type'=>'user_flood_test'))->fetchField();
if($flood_trigger=='user'){
$this->assertRaw(format_plural(variable_get('user_failed_login_user_limit',5),'Sorry, there has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.','Sorry, there have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.',array('@url'=>url('user/password'))));
$this->assertRaw(t('Sorry, there have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.',array('@url'=>url('user/password'),'@count'=>variable_get('user_failed_login_user_limit',5))));
$this->assertEqual('Flood control blocked login attempt for %user from %ip.',$user_log,'A watchdog message was logged for the login attempt blocked by flood control per user');
$this->assertEqual('hook_user_flood_control was passed username %username and IP %ip.',$user_flood_test_log,'hook_user_flood_control was invoked by flood control per user');
}
else{
// No uid, so the limit is IP-based.
$this->assertRaw(t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or <a href="@url">request a new password</a>.',array('@url'=>url('user/password'))));
$this->assertEqual('Flood control blocked login attempt from %ip.',$user_log,'A watchdog message was logged for the login attempt blocked by flood control per IP');
$this->assertEqual('hook_user_flood_control was passed IP %ip.',$user_flood_test_log,'hook_user_flood_control was invoked by flood control per IP');