Skip to content
Snippets Groups Projects
Commit c31a50ba authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2697993 by aerozeppelin, Novitsh, makbul_khan8:...

Issue #2697993 by aerozeppelin, Novitsh, makbul_khan8: system_block_ip_action() adding empty IP record in blocked_ips table
parent e94c581e
No related branches found
No related tags found
No related merge requests found
......@@ -44,7 +44,8 @@ public function findAll() {
* {@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 @@ function testIPAddressValidation() {
// $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));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment