2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2020-01-28 21:19:59 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class IPBanTest extends ShimmiePHPUnitTestCase
|
|
|
|
{
|
2020-01-28 21:19:59 +00:00
|
|
|
# FIXME: test that the IP is actually banned
|
|
|
|
|
2020-01-29 00:49:21 +00:00
|
|
|
public function testAccess()
|
|
|
|
{
|
2020-01-28 21:19:59 +00:00
|
|
|
$page = $this->get_page('ip_ban/list');
|
|
|
|
$this->assertEquals(403, $page->code);
|
|
|
|
$this->assertEquals("Permission Denied", $page->title);
|
|
|
|
}
|
|
|
|
|
2020-01-29 00:49:21 +00:00
|
|
|
public function testIPBan()
|
|
|
|
{
|
2020-01-28 21:19:59 +00:00
|
|
|
global $database;
|
2008-10-11 07:09:42 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->log_in_as_admin();
|
2008-10-11 07:09:42 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
// Check initial state
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->get_page('ip_ban/list');
|
|
|
|
$this->assert_no_text("42.42.42.42");
|
2015-09-24 22:16:38 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
// Add ban
|
|
|
|
send_event(new AddIPBanEvent(
|
|
|
|
'42.42.42.42',
|
|
|
|
'block',
|
|
|
|
'unit testing',
|
2020-01-30 09:01:19 +00:00
|
|
|
'2030-01-01'
|
2020-01-28 21:19:59 +00:00
|
|
|
));
|
2015-09-24 22:16:38 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
// Check added
|
|
|
|
$page = $this->get_page('ip_ban/list');
|
|
|
|
$this->assertStringContainsString(
|
|
|
|
"42.42.42.42",
|
|
|
|
$page->find_block("Edit IP Bans")->body
|
|
|
|
);
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
// Delete ban
|
|
|
|
$ban_id = (int)$database->get_one("SELECT id FROM bans");
|
|
|
|
send_event(new RemoveIPBanEvent($ban_id));
|
2008-10-11 07:09:42 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
// Check delete
|
|
|
|
$page = $this->get_page('ip_ban/list');
|
|
|
|
$this->assertStringNotContainsString(
|
|
|
|
"42.42.42.42",
|
|
|
|
$page->find_block("Edit IP Bans")->body
|
|
|
|
);
|
|
|
|
}
|
2009-09-27 14:48:38 +00:00
|
|
|
|
2020-01-29 00:49:21 +00:00
|
|
|
public function test_all()
|
|
|
|
{
|
2020-01-29 20:22:50 +00:00
|
|
|
// just test it doesn't crash for now
|
2020-01-28 21:19:59 +00:00
|
|
|
$this->log_in_as_admin();
|
2020-01-29 20:22:50 +00:00
|
|
|
$page = $this->get_page('ip_ban/list', ['r_all'=>'on']);
|
|
|
|
$this->assertEquals(200, $page->code);
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2008-10-11 07:09:42 +00:00
|
|
|
}
|