diff --git a/src/ProjectHoneyPot.php b/src/ProjectHoneyPot.php index a546b1b..7d7098c 100644 --- a/src/ProjectHoneyPot.php +++ b/src/ProjectHoneyPot.php @@ -9,7 +9,7 @@ * Redistribution of these files must retain the above copyright notice. * * @author Josh Sherman - * @copyright Copyright 2012, 2013, 2014, 2015, 2016, 2017, 2018 Josh Sherman + * @copyright Copyright 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Josh Sherman * @license http://www.opensource.org/licenses/mit-license.html * @link https://github.com/joshtronic/php-projecthoneypot * @link http://www.projecthoneypot.org/httpbl_configure.php @@ -55,6 +55,8 @@ class ProjectHoneyPot */ public function query($ip_address) { + var_Dump('ip addy', $ip_address, filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE)); + // Validates the IP format if (filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE)) { // Flips the script, err, IP address diff --git a/tests/ProjectHoneyPotTest.php b/tests/ProjectHoneyPotTest.php index bc8011a..d0db202 100644 --- a/tests/ProjectHoneyPotTest.php +++ b/tests/ProjectHoneyPotTest.php @@ -1,6 +1,5 @@ assertTrue(true); + + if ( + method_exists('PHPUnit_Runner_Version','id') + && version_compare(PHPUnit_Runner_Version::id(), '5.4', '<=') + ) { + return 'getMock'; + } + + return 'createMock'; + } + + // Due to version juggling, did this a bit more manually as the + // declarations were being removed entirely and I wasn't sure which + // versions supported the suggested methods. public function testInvalidKey() { - new joshtronic\ProjectHoneyPot('foo'); + $threw = false; + + try { + new joshtronic\ProjectHoneyPot('foo'); + } catch (Exception $e) { + $threw = true; + + $this->assertEquals( + 'You must specify a valid API key.', + $e->getMessage(), + ); + } + + $this->assertTrue($threw); } public function testInvalidIP() @@ -36,23 +55,29 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase ); } - public function testMissingResults() + /** + * @depends testCreateMock + */ + public function testMissingResults($createMock) { - $mock = $this->$createMock( - 'joshtronic\ProjectHoneyPot', - array('dns_get_record'), - array('foobarfoobar') - ); + $mock = $this->$createMock('joshtronic\ProjectHoneyPot'); $mock ->expects($this->once()) ->method('dns_get_record') + ->with($this->equalTo('4.3.2.1')) ->will($this->returnValue('foo')); - $this->assertFalse($mock->query('1.2.3.4')); + var_dump($mock->query('1.2.3.4')); + + $this->assertNull($mock->query('1.2.3.4')); + // $this->assertFalse($mock->query('1.2.3.4')); } - public function testCategory0() + /** + * @depends testCreateMock + */ + public function testCategory0($createMock) { $mock = $this->$createMock( 'joshtronic\ProjectHoneyPot', @@ -70,7 +95,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase $this->assertEquals(array('Search Engine'), $results['categories']); } - public function testCategory1() + /** + * @depends testCreateMock + */ + public function testCategory1($createMock) { $mock = $this->$createMock( 'joshtronic\ProjectHoneyPot', @@ -88,7 +116,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase $this->assertEquals(array('Suspicious'), $results['categories']); } - public function testCategory2() + /** + * @depends testCreateMock + */ + public function testCategory2($createMock) { $mock = $this->$createMock( 'joshtronic\ProjectHoneyPot', @@ -106,7 +137,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase $this->assertEquals(array('Harvester'), $results['categories']); } - public function testCategory3() + /** + * @depends testCreateMock + */ + public function testCategory3($createMock) { $mock = $this->$createMock( 'joshtronic\ProjectHoneyPot', @@ -127,7 +161,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase ); } - public function testCategory4() + /** + * @depends testCreateMock + */ + public function testCategory4($createMock) { $mock = $this->$createMock( 'joshtronic\ProjectHoneyPot', @@ -148,7 +185,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase ); } - public function testCategory5() + /** + * @depends testCreateMock + */ + public function testCategory5($createMock) { $mock = $this->$createMock( 'joshtronic\ProjectHoneyPot', @@ -169,7 +209,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase ); } - public function testCategory6() + /** + * @depends testCreateMock + */ + public function testCategory6($createMock) { $mock = $this->$createMock( 'joshtronic\ProjectHoneyPot', @@ -190,7 +233,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase ); } - public function testCategory7() + /** + * @depends testCreateMock + */ + public function testCategory7($createMock) { $mock = $this->$createMock( 'joshtronic\ProjectHoneyPot', @@ -211,7 +257,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase ); } - public function testCategoryDefault() + /** + * @depends testCreateMock + */ + public function testCategoryDefault($createMock) { $mock = $this->$createMock( 'joshtronic\ProjectHoneyPot', @@ -232,7 +281,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase ); } - public function testWithout127() + /** + * @depends testCreateMock + */ + public function testWithout127($createMock) { $mock = $this->$createMock( 'joshtronic\ProjectHoneyPot',