Issue #2697993 by aerozeppelin, Novitsh, makbul_khan8: system_block_ip_action() adding empty IP record in blocked_ips table
parent
e94c581e09
commit
c31a50baa5
|
@ -44,7 +44,8 @@ class BanIpManager implements BanIpManagerInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function banIp($ip) {
|
||||
$this->connection->insert('ban_ip')
|
||||
$this->connection->merge('ban_ip')
|
||||
->key(array('ip' => $ip))
|
||||
->fields(array('ip' => $ip))
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace Drupal\Tests\ban\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\ban\BanIpManager;
|
||||
|
||||
/**
|
||||
* Tests IP address banning.
|
||||
|
@ -73,6 +75,28 @@ class IpAddressBlockingTest extends BrowserTestBase {
|
|||
// $edit['ip'] = \Drupal::request()->getClientIP();
|
||||
// $this->drupalPostForm('admin/config/people/ban', $edit, t('Save'));
|
||||
// $this->assertText(t('You may not ban your own IP address.'));
|
||||
|
||||
// Test duplicate ip address are not present in the 'blocked_ips' table.
|
||||
// when they are entered programmatically.
|
||||
$connection = Database::getConnection();
|
||||
$banIp = new BanIpManager($connection);
|
||||
$ip = '1.0.0.0';
|
||||
$banIp->banIp($ip);
|
||||
$banIp->banIp($ip);
|
||||
$banIp->banIp($ip);
|
||||
$query = db_select('ban_ip', 'bip');
|
||||
$query->fields('bip', array('iid'));
|
||||
$query->condition('bip.ip', $ip);
|
||||
$ip_count = $query->execute()->fetchAll();
|
||||
$this->assertEqual(1, count($ip_count));
|
||||
$ip = '';
|
||||
$banIp->banIp($ip);
|
||||
$banIp->banIp($ip);
|
||||
$query = db_select('ban_ip', 'bip');
|
||||
$query->fields('bip', array('iid'));
|
||||
$query->condition('bip.ip', $ip);
|
||||
$ip_count = $query->execute()->fetchAll();
|
||||
$this->assertEqual(1, count($ip_count));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue