diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a2144a3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+composer.lock
+composer.phar
+.phpunit.result.cache
+/vendor/
diff --git a/.travis.yml b/.travis.yml
index 8bfb40e..36d3649 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,26 +1,40 @@
language: php
-
-php:
- - 5.3
- - 5.4
- - 5.5
- - 5.6
- - hhvm
- - hhvm-nightly
+dist: bionic
+sudo: required
matrix:
+ include:
+ - php: 5.3
+ dist: precise
+ - php: 5.4
+ dist: trusty
+ - php: 5.5
+ dist: trusty
+ - php: 5.6
+ dist: trusty
+ - php: 7.0
+ dist: xenial
+ - php: 7.1
+ - php: 7.2
+ - php: 7.3
+ - php: 7.4
+ env: COVERAGE=true
+ - php: nightly
allow_failures:
- - php: hhvm-nightly
+ - php: nightly
install:
+ - php --version
- composer install
before_script:
- mkdir -p build/logs
- - cd tests
script:
- - phpunit --colors --coverage-clover /home/travis/build/joshtronic/php-projecthoneypot/build/logs/clover.xml .
+ - vendor/bin/phpunit --coverage-clover build/logs/clover.xml
after_success:
- - php ../vendor/bin/coveralls --config ../.coveralls.yml -v
+ - |
+ if [[ $COVERAGE ]]; then
+ travis_retry php vendor/bin/php-coveralls --config .coveralls.yml -v
+ fi
diff --git a/LICENSE b/LICENSE
index be2bff2..22de71d 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2012-2014 Josh Sherman
+Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Josh Sherman
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
diff --git a/composer.json b/composer.json
index 8bef239..87ebba0 100644
--- a/composer.json
+++ b/composer.json
@@ -1,23 +1,33 @@
{
- "name": "joshtronic/php-projecthoneypot",
- "description": "PHP Wrapper for Project Honey Pot",
- "version": "1.0.0",
- "type": "library",
- "keywords": ["project", "honey", "pot", "api", "spam", "spammer"],
- "homepage": "https://github.com/joshtronic/php-projecthoneypot",
- "license": "MIT",
- "authors": [{
- "name": "Josh Sherman",
- "email": "hello@joshtronic.com",
- "homepage": "http://joshtronic.com"
- }],
- "require-dev": {
- "php": ">=5.3.0"
- },
- "require-dev": {
- "satooshi/php-coveralls": "dev-master"
- },
- "autoload": {
- "psr-4": {"joshtronic\\": "src/"}
+ "name": "joshtronic/php-projecthoneypot",
+ "description": "PHP Wrapper for Project Honey Pot",
+ "version": "1.0.1",
+ "type": "library",
+ "keywords": [
+ "project",
+ "honey",
+ "pot",
+ "api",
+ "spam",
+ "spammer"
+ ],
+ "homepage": "https://github.com/joshtronic/php-projecthoneypot",
+ "license": "MIT",
+ "authors": [{
+ "name": "Josh Sherman",
+ "email": "hello@joshtronic.com",
+ "homepage": "https://joshtronic.com"
+ }],
+ "require": {
+ "php": ">=5.3"
+ },
+ "require-dev": {
+ "php-coveralls/php-coveralls": ">=1",
+ "phpunit/phpunit": ">=4"
+ },
+ "autoload": {
+ "psr-4": {
+ "joshtronic\\": "src/"
}
+ }
}
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 0000000..6eaac53
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,23 @@
+
+
+
+
+ tests
+
+
+
+
+ ./src
+
+
+
diff --git a/src/ProjectHoneyPot.php b/src/ProjectHoneyPot.php
index 613b5f1..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-2015, 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 38128db..d0db202 100644
--- a/tests/ProjectHoneyPotTest.php
+++ b/tests/ProjectHoneyPotTest.php
@@ -1,16 +1,48 @@
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()
@@ -23,83 +55,103 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
);
}
- public function testMissingResults()
+ /**
+ * @depends testCreateMock
+ */
+ public function testMissingResults($createMock)
{
- $mock = $this->getMock(
- 'joshtronic\ProjectHoneyPot',
- array('dns_get_record'),
- array('foobarfoobar')
- );
+ $mock = $this->$createMock('joshtronic\ProjectHoneyPot');
- $mock->expects($this->once())
- ->method('dns_get_record')
- ->will($this->returnValue('foo'));
+ $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->getMock(
+ $mock = $this->$createMock(
'joshtronic\ProjectHoneyPot',
array('dns_get_record'),
array('foobarfoobar')
);
- $mock->expects($this->once())
- ->method('dns_get_record')
- ->will($this->returnValue(array(array('ip' => '127.0.0.0'))));
+ $mock
+ ->expects($this->once())
+ ->method('dns_get_record')
+ ->will($this->returnValue(array(array('ip' => '127.0.0.0'))));
$results = $mock->query('1.2.3.4');
$this->assertEquals(array('Search Engine'), $results['categories']);
}
- public function testCategory1()
+ /**
+ * @depends testCreateMock
+ */
+ public function testCategory1($createMock)
{
- $mock = $this->getMock(
+ $mock = $this->$createMock(
'joshtronic\ProjectHoneyPot',
array('dns_get_record'),
array('foobarfoobar')
);
- $mock->expects($this->once())
- ->method('dns_get_record')
- ->will($this->returnValue(array(array('ip' => '127.0.0.1'))));
+ $mock
+ ->expects($this->once())
+ ->method('dns_get_record')
+ ->will($this->returnValue(array(array('ip' => '127.0.0.1'))));
$results = $mock->query('1.2.3.4');
$this->assertEquals(array('Suspicious'), $results['categories']);
}
- public function testCategory2()
+ /**
+ * @depends testCreateMock
+ */
+ public function testCategory2($createMock)
{
- $mock = $this->getMock(
+ $mock = $this->$createMock(
'joshtronic\ProjectHoneyPot',
array('dns_get_record'),
array('foobarfoobar')
);
- $mock->expects($this->once())
- ->method('dns_get_record')
- ->will($this->returnValue(array(array('ip' => '127.0.0.2'))));
+ $mock
+ ->expects($this->once())
+ ->method('dns_get_record')
+ ->will($this->returnValue(array(array('ip' => '127.0.0.2'))));
$results = $mock->query('1.2.3.4');
$this->assertEquals(array('Harvester'), $results['categories']);
}
- public function testCategory3()
+ /**
+ * @depends testCreateMock
+ */
+ public function testCategory3($createMock)
{
- $mock = $this->getMock(
+ $mock = $this->$createMock(
'joshtronic\ProjectHoneyPot',
array('dns_get_record'),
array('foobarfoobar')
);
- $mock->expects($this->once())
- ->method('dns_get_record')
- ->will($this->returnValue(array(array('ip' => '127.0.0.3'))));
+ $mock
+ ->expects($this->once())
+ ->method('dns_get_record')
+ ->will($this->returnValue(array(array('ip' => '127.0.0.3'))));
$results = $mock->query('1.2.3.4');
@@ -109,17 +161,21 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
);
}
- public function testCategory4()
+ /**
+ * @depends testCreateMock
+ */
+ public function testCategory4($createMock)
{
- $mock = $this->getMock(
+ $mock = $this->$createMock(
'joshtronic\ProjectHoneyPot',
array('dns_get_record'),
array('foobarfoobar')
);
- $mock->expects($this->once())
- ->method('dns_get_record')
- ->will($this->returnValue(array(array('ip' => '127.0.0.4'))));
+ $mock
+ ->expects($this->once())
+ ->method('dns_get_record')
+ ->will($this->returnValue(array(array('ip' => '127.0.0.4'))));
$results = $mock->query('1.2.3.4');
@@ -129,17 +185,21 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
);
}
- public function testCategory5()
+ /**
+ * @depends testCreateMock
+ */
+ public function testCategory5($createMock)
{
- $mock = $this->getMock(
+ $mock = $this->$createMock(
'joshtronic\ProjectHoneyPot',
array('dns_get_record'),
array('foobarfoobar')
);
- $mock->expects($this->once())
- ->method('dns_get_record')
- ->will($this->returnValue(array(array('ip' => '127.0.0.5'))));
+ $mock
+ ->expects($this->once())
+ ->method('dns_get_record')
+ ->will($this->returnValue(array(array('ip' => '127.0.0.5'))));
$results = $mock->query('1.2.3.4');
@@ -149,17 +209,21 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
);
}
- public function testCategory6()
+ /**
+ * @depends testCreateMock
+ */
+ public function testCategory6($createMock)
{
- $mock = $this->getMock(
+ $mock = $this->$createMock(
'joshtronic\ProjectHoneyPot',
array('dns_get_record'),
array('foobarfoobar')
);
- $mock->expects($this->once())
- ->method('dns_get_record')
- ->will($this->returnValue(array(array('ip' => '127.0.0.6'))));
+ $mock
+ ->expects($this->once())
+ ->method('dns_get_record')
+ ->will($this->returnValue(array(array('ip' => '127.0.0.6'))));
$results = $mock->query('1.2.3.4');
@@ -169,17 +233,21 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
);
}
- public function testCategory7()
+ /**
+ * @depends testCreateMock
+ */
+ public function testCategory7($createMock)
{
- $mock = $this->getMock(
+ $mock = $this->$createMock(
'joshtronic\ProjectHoneyPot',
array('dns_get_record'),
array('foobarfoobar')
);
- $mock->expects($this->once())
- ->method('dns_get_record')
- ->will($this->returnValue(array(array('ip' => '127.0.0.7'))));
+ $mock
+ ->expects($this->once())
+ ->method('dns_get_record')
+ ->will($this->returnValue(array(array('ip' => '127.0.0.7'))));
$results = $mock->query('1.2.3.4');
@@ -189,17 +257,21 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
);
}
- public function testCategoryDefault()
+ /**
+ * @depends testCreateMock
+ */
+ public function testCategoryDefault($createMock)
{
- $mock = $this->getMock(
+ $mock = $this->$createMock(
'joshtronic\ProjectHoneyPot',
array('dns_get_record'),
array('foobarfoobar')
);
- $mock->expects($this->once())
- ->method('dns_get_record')
- ->will($this->returnValue(array(array('ip' => '127.0.0.255'))));
+ $mock
+ ->expects($this->once())
+ ->method('dns_get_record')
+ ->will($this->returnValue(array(array('ip' => '127.0.0.255'))));
$results = $mock->query('1.2.3.4');
@@ -209,17 +281,21 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
);
}
- public function testWithout127()
+ /**
+ * @depends testCreateMock
+ */
+ public function testWithout127($createMock)
{
- $mock = $this->getMock(
+ $mock = $this->$createMock(
'joshtronic\ProjectHoneyPot',
array('dns_get_record'),
array('foobarfoobar')
);
- $mock->expects($this->once())
- ->method('dns_get_record')
- ->will($this->returnValue(array(array('ip' => '1.0.0.0'))));
+ $mock
+ ->expects($this->once())
+ ->method('dns_get_record')
+ ->will($this->returnValue(array(array('ip' => '1.0.0.0'))));
$this->assertFalse($mock->query('1.2.3.4'));
}