Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.86% |
22 / 29 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_functions_user_whois_test | |
75.86% |
22 / 29 |
|
33.33% |
1 / 3 |
6.51 | |
0.00% |
0 / 1 |
| setUp | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| ips_data | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| test_ip_whois | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
4.02 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * @package testing |
| 5 | * @copyright (c) 2020 phpBB Group |
| 6 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | require_once __DIR__ . '/../../phpBB/includes/functions_user.php'; |
| 11 | |
| 12 | class phpbb_functions_user_whois_test extends phpbb_test_case |
| 13 | { |
| 14 | public function setUp(): void |
| 15 | { |
| 16 | global $config, $phpbb_dispatcher, $user, $request, $symfony_request, $phpbb_root_path, $phpEx; |
| 17 | |
| 18 | $user = $this->getMockBuilder('\phpbb\user') |
| 19 | ->setConstructorArgs([ |
| 20 | new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), |
| 21 | '\phpbb\datetime', |
| 22 | ]) |
| 23 | ->getMock(); |
| 24 | $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); |
| 25 | $config = new \phpbb\config\config([]); |
| 26 | $request = $this->getMockBuilder('\phpbb\request\request') |
| 27 | ->getMock(); |
| 28 | $symfony_request = $this->getMockBuilder('\phpbb\symfony_request') |
| 29 | ->disableOriginalConstructor() |
| 30 | ->getMock(); |
| 31 | } |
| 32 | |
| 33 | public static function ips_data() |
| 34 | { |
| 35 | return [ |
| 36 | ['2001:4860:4860::8888'], // Google public DNS (ARIN) |
| 37 | ['64.233.161.139'], // google.com (ARIN) |
| 38 | ['1.1.1.1'], // Cloudflare (APNIC via whois:// referral) |
| 39 | ['213.133.116.44'], // Hetzner (RIPE via non-whois:// referral) |
| 40 | ]; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @dataProvider ips_data |
| 45 | */ |
| 46 | public function test_ip_whois($ip) |
| 47 | { |
| 48 | $ip_whois = user_ipwhois($ip); |
| 49 | |
| 50 | if (preg_match('/%ERROR:201:\s*access denied/i', $ip_whois) |
| 51 | || stripos($ip_whois, 'daily limit of controlled objects') !== false |
| 52 | || stripos($ip_whois, 'Access from your host has been temporarily denied') !== false |
| 53 | ) |
| 54 | { |
| 55 | $this->markTestSkipped('WHOIS provider temporarily denied access due to rate limiting (RIPE ERROR:201).'); |
| 56 | } |
| 57 | |
| 58 | $this->assertStringNotContainsString('Query terms are ambiguous', $ip_whois); |
| 59 | $this->assertStringNotContainsString('no entries found', $ip_whois); |
| 60 | $this->assertStringNotContainsString('ERROR', $ip_whois); |
| 61 | $this->assertStringNotContainsString('Allocated to RIPE NCC', $ip_whois); // This only shows if the referral isn't found |
| 62 | } |
| 63 | } |