Preparing for a formal release
Converted tabs to spaces, did some cleanup and updated the composer file.
This commit is contained in:
parent
c840d5a36f
commit
c76fdf936d
5 changed files with 351 additions and 337 deletions
23
LICENSE
23
LICENSE
|
@ -2,20 +2,19 @@ The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2012-2014 Josh Sherman
|
Copyright (c) 2012-2014 Josh Sherman
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
in the Software without restriction, including without limitation the rights
|
the Software without restriction, including without limitation the rights to
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
furnished to do so, subject to the following conditions:
|
subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
SOFTWARE.
|
|
||||||
|
|
36
README.md
36
README.md
|
@ -5,20 +5,16 @@
|
||||||
[][packagist]
|
[][packagist]
|
||||||
[][gittip]
|
[][gittip]
|
||||||
|
|
||||||
[travis]: http://travis-ci.org/joshtronic/php-projecthoneypot
|
|
||||||
[coveralls]: https://coveralls.io/r/joshtronic/php-projecthoneypot
|
|
||||||
[packagist]: https://packagist.org/packages/joshtronic/php-projecthoneypot
|
|
||||||
[gittip]: https://www.gittip.com/joshtronic/
|
|
||||||
|
|
||||||
PHP Wrapper for Project Honey Pot. Compatible with PHP 5.3+ and HHVM.
|
PHP Wrapper for Project Honey Pot. Compatible with PHP 5.3+ and HHVM.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
The preferred installation method is via `composer`. First add the following to your `composer.json`
|
The preferred installation method is via `composer`. First add the following
|
||||||
|
to your `composer.json`
|
||||||
|
|
||||||
```json
|
```json
|
||||||
"require": {
|
"require": {
|
||||||
"joshtronic/php-projecthoneypot": "dev-master"
|
"joshtronic/php-projecthoneypot": "dev-master"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -42,11 +38,14 @@ print_r($results);
|
||||||
|
|
||||||
### Results
|
### Results
|
||||||
|
|
||||||
Queries will return an array of information about the IP address. The array will contain `last_activity`, `threat_score` and an array of `categories`.
|
Queries will return an array of information about the IP address. The array
|
||||||
|
will contain `last_activity`, `threat_score` and an array of `categories`.
|
||||||
|
|
||||||
### Simulating Results
|
### Simulating Results
|
||||||
|
|
||||||
The folks at Project Honey Pot were kind enough to include a way to simulate results from their http:BL API. You can do so by performing queries against the following IP addresses.
|
The folks at Project Honey Pot were kind enough to include a way to simulate
|
||||||
|
results from their http:BL API. You can do so by performing queries against
|
||||||
|
the following IP addresses.
|
||||||
|
|
||||||
#### Visitor Types
|
#### Visitor Types
|
||||||
|
|
||||||
|
@ -75,10 +74,21 @@ The folks at Project Honey Pot were kind enough to include a way to simulate res
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Suggestions and bug reports are always welcome, but karma points are earned for pull requests.
|
Suggestions and bug reports are always welcome, but karma points are earned
|
||||||
|
for pull requests.
|
||||||
|
|
||||||
Unit tests are required for all contributions. You can run the test suite from the `tests` directory simply by running `phpunit .`
|
Unit tests are required for all contributions. You can run the test suite from
|
||||||
|
the `tests` directory simply by running `phpunit .`
|
||||||
|
|
||||||
I also urge you to install a honey pot and donate some MX records to Project Honey Pot. They are doing great work, they provide http:BL as a free service and your donations help make their service ever better!
|
I also urge you to install a honey pot and donate some MX records to Project
|
||||||
|
Honey Pot. They are doing great work, they provide http:BL as a free service
|
||||||
|
and your donations help make their service ever better!
|
||||||
|
|
||||||
If you’re not already a member, please sign up today with [my referral code](http://www.projecthoneypot.org?rf=123193).
|
If you’re not already a member, please sign up today with
|
||||||
|
[my referral code][referral].
|
||||||
|
|
||||||
|
[coveralls]: https://coveralls.io/r/joshtronic/php-projecthoneypot
|
||||||
|
[gittip]: https://www.gittip.com/joshtronic/
|
||||||
|
[packagist]: https://packagist.org/packages/joshtronic/php-projecthoneypot
|
||||||
|
[referral]: http://www.projecthoneypot.org?rf=123193
|
||||||
|
[travis]: http://travis-ci.org/joshtronic/php-projecthoneypot
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
{
|
{
|
||||||
"name": "joshtronic/php-projecthoneypot",
|
"name": "joshtronic/php-projecthoneypot",
|
||||||
"description": "PHP Wrapper for Project Honey Pot",
|
"description": "PHP Wrapper for Project Honey Pot",
|
||||||
"license": "MIT",
|
"version": "1.0.0",
|
||||||
"authors": [{
|
"type": "library",
|
||||||
"name": "Josh Sherman",
|
"keywords": ["project", "honey", "pot", "api", "spam", "spammer"],
|
||||||
"email": "josh@gravityblvd.com",
|
"homepage": "https://github.com/joshtronic/php-projecthoneypot",
|
||||||
"homepage": "https://github.com/joshtronic/php-projecthoneypot"
|
"license": "MIT",
|
||||||
}],
|
"authors": [{
|
||||||
"autoload": {
|
"name": "Josh Sherman",
|
||||||
"classmap": ["src/"]
|
"email": "josh@gravityblvd.com",
|
||||||
},
|
"homepage": "http://joshtronic.com"
|
||||||
"require-dev": {
|
}],
|
||||||
"satooshi/php-coveralls": "dev-master"
|
"require-dev": {
|
||||||
}
|
"php": ">=5.3.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"satooshi/php-coveralls": "dev-master"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {"joshtronic\\": "src/"}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,138 +19,137 @@ namespace joshtronic;
|
||||||
|
|
||||||
class ProjectHoneyPot
|
class ProjectHoneyPot
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* API Key
|
* API Key
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $api_key = '';
|
private $api_key = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* Adds the specified API key to the object.
|
* Adds the specified API key to the object.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $api_key PHP API Key (12 characters)
|
* @param string $api_key PHP API Key (12 characters)
|
||||||
*/
|
*/
|
||||||
public function __construct($api_key)
|
public function __construct($api_key)
|
||||||
{
|
{
|
||||||
if (preg_match('/^[a-z]{12}$/', $api_key))
|
if (preg_match('/^[a-z]{12}$/', $api_key))
|
||||||
{
|
{
|
||||||
$this->api_key = $api_key;
|
$this->api_key = $api_key;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new \Exception('You must specify a valid API key.');
|
throw new \Exception('You must specify a valid API key.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query
|
* Query
|
||||||
*
|
*
|
||||||
* Performs a DNS lookup to obtain information about the IP address.
|
* Performs a DNS lookup to obtain information about the IP address.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $ip_address IPv4 address to check
|
* @param string $ip_address IPv4 address to check
|
||||||
* @return array results from query
|
* @return array results from query
|
||||||
*/
|
*/
|
||||||
public function query($ip_address)
|
public function query($ip_address)
|
||||||
{
|
{
|
||||||
// Validates the IP format
|
// Validates the IP format
|
||||||
if (filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE))
|
if (filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE))
|
||||||
{
|
{
|
||||||
// Flips the script, err, IP address
|
// Flips the script, err, IP address
|
||||||
$octets = explode('.', $ip_address);
|
$octets = explode('.', $ip_address);
|
||||||
krsort($octets);
|
krsort($octets);
|
||||||
$reversed_ip = implode('.', $octets);
|
$reversed_ip = implode('.', $octets);
|
||||||
|
|
||||||
// Performs the query
|
// Performs the query
|
||||||
$results = $this->dns_get_record($reversed_ip);
|
$results = $this->dns_get_record($reversed_ip);
|
||||||
|
|
||||||
// Processes the results
|
// Processes the results
|
||||||
if (isset($results[0]['ip']))
|
if (isset($results[0]['ip']))
|
||||||
{
|
{
|
||||||
$results = explode('.', $results[0]['ip']);
|
$results = explode('.', $results[0]['ip']);
|
||||||
|
|
||||||
if ($results[0] == 127)
|
if ($results[0] == 127)
|
||||||
{
|
{
|
||||||
$results = array(
|
$results = array(
|
||||||
'last_activity' => $results[1],
|
'last_activity' => $results[1],
|
||||||
'threat_score' => $results[2],
|
'threat_score' => $results[2],
|
||||||
'categories' => $results[3],
|
'categories' => $results[3],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Creates an array of categories
|
// Creates an array of categories
|
||||||
switch ($results['categories'])
|
switch ($results['categories'])
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
$categories = array('Search Engine');
|
$categories = array('Search Engine');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
$categories = array('Suspicious');
|
$categories = array('Suspicious');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
$categories = array('Harvester');
|
$categories = array('Harvester');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
$categories = array('Suspicious', 'Harvester');
|
$categories = array('Suspicious', 'Harvester');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
$categories = array('Comment Spammer');
|
$categories = array('Comment Spammer');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
$categories = array('Suspicious', 'Comment Spammer');
|
$categories = array('Suspicious', 'Comment Spammer');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
$categories = array('Harvester', 'Comment Spammer');
|
$categories = array('Harvester', 'Comment Spammer');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 7:
|
case 7:
|
||||||
$categories = array('Suspicious', 'Harvester', 'Comment Spammer');
|
$categories = array('Suspicious', 'Harvester', 'Comment Spammer');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$categories = array('Reserved for Future Use');
|
$categories = array('Reserved for Future Use');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$results['categories'] = $categories;
|
|
||||||
|
|
||||||
return $results;
|
$results['categories'] = $categories;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return array('error' => 'Invalid IP address.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return $results;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return array('error' => 'Invalid IP address.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
return false;
|
||||||
* DNS Get Record
|
}
|
||||||
*
|
|
||||||
* Wrapper method for dns_get_record() to allow fo easy mocking of the
|
/**
|
||||||
* results in our tests. Takes an already reversed IP address and does a
|
* DNS Get Record
|
||||||
* DNS lookup for A records against the http:BL API.
|
*
|
||||||
*
|
* Wrapper method for dns_get_record() to allow fo easy mocking of the
|
||||||
* @access public
|
* results in our tests. Takes an already reversed IP address and does a
|
||||||
* @param string $reversed_ip reversed IPv4 address to check
|
* DNS lookup for A records against the http:BL API.
|
||||||
* @return array results from the DNS lookup
|
*
|
||||||
*/
|
* @access public
|
||||||
public function dns_get_record($reversed_ip)
|
* @param string $reversed_ip reversed IPv4 address to check
|
||||||
{
|
* @return array results from the DNS lookup
|
||||||
return dns_get_record($this->api_key . '.' . $reversed_ip . '.dnsbl.httpbl.org', DNS_A);
|
*/
|
||||||
}
|
public function dns_get_record($reversed_ip)
|
||||||
|
{
|
||||||
|
return dns_get_record($this->api_key . '.' . $reversed_ip . '.dnsbl.httpbl.org', DNS_A);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
@ -4,233 +4,232 @@ require_once '../src/ProjectHoneyPot.php';
|
||||||
|
|
||||||
class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
|
class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @expectedException Exception
|
* @expectedException Exception
|
||||||
* @expectedExceptionMessage You must specify a valid API key.
|
* @expectedExceptionMessage You must specify a valid API key.
|
||||||
*/
|
*/
|
||||||
public function testInvalidKey()
|
public function testInvalidKey()
|
||||||
{
|
{
|
||||||
new joshtronic\ProjectHoneyPot('foo');
|
new joshtronic\ProjectHoneyPot('foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidIP()
|
public function testInvalidIP()
|
||||||
{
|
{
|
||||||
$object = new joshtronic\ProjectHoneyPot('foobarfoobar');
|
$object = new joshtronic\ProjectHoneyPot('foobarfoobar');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array('error' => 'Invalid IP address.'),
|
array('error' => 'Invalid IP address.'),
|
||||||
$object->query('foo')
|
$object->query('foo')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMissingResults()
|
public function testMissingResults()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock(
|
$mock = $this->getMock(
|
||||||
'joshtronic\ProjectHoneyPot',
|
'joshtronic\ProjectHoneyPot',
|
||||||
array('dns_get_record'),
|
array('dns_get_record'),
|
||||||
array('foobarfoobar')
|
array('foobarfoobar')
|
||||||
);
|
);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('dns_get_record')
|
->method('dns_get_record')
|
||||||
->will($this->returnValue('foo'));
|
->will($this->returnValue('foo'));
|
||||||
|
|
||||||
$this->assertFalse($mock->query('1.2.3.4'));
|
$this->assertFalse($mock->query('1.2.3.4'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCategory0()
|
public function testCategory0()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock(
|
$mock = $this->getMock(
|
||||||
'joshtronic\ProjectHoneyPot',
|
'joshtronic\ProjectHoneyPot',
|
||||||
array('dns_get_record'),
|
array('dns_get_record'),
|
||||||
array('foobarfoobar')
|
array('foobarfoobar')
|
||||||
);
|
);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('dns_get_record')
|
->method('dns_get_record')
|
||||||
->will($this->returnValue(array(array('ip' => '127.0.0.0'))));
|
->will($this->returnValue(array(array('ip' => '127.0.0.0'))));
|
||||||
|
|
||||||
$results = $mock->query('1.2.3.4');
|
$results = $mock->query('1.2.3.4');
|
||||||
|
|
||||||
$this->assertEquals(array('Search Engine'), $results['categories']);
|
$this->assertEquals(array('Search Engine'), $results['categories']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCategory1()
|
public function testCategory1()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock(
|
$mock = $this->getMock(
|
||||||
'joshtronic\ProjectHoneyPot',
|
'joshtronic\ProjectHoneyPot',
|
||||||
array('dns_get_record'),
|
array('dns_get_record'),
|
||||||
array('foobarfoobar')
|
array('foobarfoobar')
|
||||||
);
|
);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('dns_get_record')
|
->method('dns_get_record')
|
||||||
->will($this->returnValue(array(array('ip' => '127.0.0.1'))));
|
->will($this->returnValue(array(array('ip' => '127.0.0.1'))));
|
||||||
|
|
||||||
$results = $mock->query('1.2.3.4');
|
$results = $mock->query('1.2.3.4');
|
||||||
|
|
||||||
$this->assertEquals(array('Suspicious'), $results['categories']);
|
$this->assertEquals(array('Suspicious'), $results['categories']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCategory2()
|
public function testCategory2()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock(
|
$mock = $this->getMock(
|
||||||
'joshtronic\ProjectHoneyPot',
|
'joshtronic\ProjectHoneyPot',
|
||||||
array('dns_get_record'),
|
array('dns_get_record'),
|
||||||
array('foobarfoobar')
|
array('foobarfoobar')
|
||||||
);
|
);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('dns_get_record')
|
->method('dns_get_record')
|
||||||
->will($this->returnValue(array(array('ip' => '127.0.0.2'))));
|
->will($this->returnValue(array(array('ip' => '127.0.0.2'))));
|
||||||
|
|
||||||
$results = $mock->query('1.2.3.4');
|
$results = $mock->query('1.2.3.4');
|
||||||
|
|
||||||
$this->assertEquals(array('Harvester'), $results['categories']);
|
$this->assertEquals(array('Harvester'), $results['categories']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCategory3()
|
public function testCategory3()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock(
|
$mock = $this->getMock(
|
||||||
'joshtronic\ProjectHoneyPot',
|
'joshtronic\ProjectHoneyPot',
|
||||||
array('dns_get_record'),
|
array('dns_get_record'),
|
||||||
array('foobarfoobar')
|
array('foobarfoobar')
|
||||||
);
|
);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('dns_get_record')
|
->method('dns_get_record')
|
||||||
->will($this->returnValue(array(array('ip' => '127.0.0.3'))));
|
->will($this->returnValue(array(array('ip' => '127.0.0.3'))));
|
||||||
|
|
||||||
$results = $mock->query('1.2.3.4');
|
$results = $mock->query('1.2.3.4');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array('Suspicious', 'Harvester'),
|
array('Suspicious', 'Harvester'),
|
||||||
$results['categories']
|
$results['categories']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCategory4()
|
public function testCategory4()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock(
|
$mock = $this->getMock(
|
||||||
'joshtronic\ProjectHoneyPot',
|
'joshtronic\ProjectHoneyPot',
|
||||||
array('dns_get_record'),
|
array('dns_get_record'),
|
||||||
array('foobarfoobar')
|
array('foobarfoobar')
|
||||||
);
|
);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('dns_get_record')
|
->method('dns_get_record')
|
||||||
->will($this->returnValue(array(array('ip' => '127.0.0.4'))));
|
->will($this->returnValue(array(array('ip' => '127.0.0.4'))));
|
||||||
|
|
||||||
$results = $mock->query('1.2.3.4');
|
$results = $mock->query('1.2.3.4');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array('Comment Spammer'),
|
array('Comment Spammer'),
|
||||||
$results['categories']
|
$results['categories']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCategory5()
|
public function testCategory5()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock(
|
$mock = $this->getMock(
|
||||||
'joshtronic\ProjectHoneyPot',
|
'joshtronic\ProjectHoneyPot',
|
||||||
array('dns_get_record'),
|
array('dns_get_record'),
|
||||||
array('foobarfoobar')
|
array('foobarfoobar')
|
||||||
);
|
);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('dns_get_record')
|
->method('dns_get_record')
|
||||||
->will($this->returnValue(array(array('ip' => '127.0.0.5'))));
|
->will($this->returnValue(array(array('ip' => '127.0.0.5'))));
|
||||||
|
|
||||||
$results = $mock->query('1.2.3.4');
|
$results = $mock->query('1.2.3.4');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array('Suspicious', 'Comment Spammer'),
|
array('Suspicious', 'Comment Spammer'),
|
||||||
$results['categories']
|
$results['categories']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCategory6()
|
public function testCategory6()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock(
|
$mock = $this->getMock(
|
||||||
'joshtronic\ProjectHoneyPot',
|
'joshtronic\ProjectHoneyPot',
|
||||||
array('dns_get_record'),
|
array('dns_get_record'),
|
||||||
array('foobarfoobar')
|
array('foobarfoobar')
|
||||||
);
|
);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('dns_get_record')
|
->method('dns_get_record')
|
||||||
->will($this->returnValue(array(array('ip' => '127.0.0.6'))));
|
->will($this->returnValue(array(array('ip' => '127.0.0.6'))));
|
||||||
|
|
||||||
$results = $mock->query('1.2.3.4');
|
$results = $mock->query('1.2.3.4');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array('Harvester', 'Comment Spammer'),
|
array('Harvester', 'Comment Spammer'),
|
||||||
$results['categories']
|
$results['categories']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCategory7()
|
public function testCategory7()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock(
|
$mock = $this->getMock(
|
||||||
'joshtronic\ProjectHoneyPot',
|
'joshtronic\ProjectHoneyPot',
|
||||||
array('dns_get_record'),
|
array('dns_get_record'),
|
||||||
array('foobarfoobar')
|
array('foobarfoobar')
|
||||||
);
|
);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('dns_get_record')
|
->method('dns_get_record')
|
||||||
->will($this->returnValue(array(array('ip' => '127.0.0.7'))));
|
->will($this->returnValue(array(array('ip' => '127.0.0.7'))));
|
||||||
|
|
||||||
$results = $mock->query('1.2.3.4');
|
$results = $mock->query('1.2.3.4');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array('Suspicious', 'Harvester', 'Comment Spammer'),
|
array('Suspicious', 'Harvester', 'Comment Spammer'),
|
||||||
$results['categories']
|
$results['categories']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCategoryDefault()
|
public function testCategoryDefault()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock(
|
$mock = $this->getMock(
|
||||||
'joshtronic\ProjectHoneyPot',
|
'joshtronic\ProjectHoneyPot',
|
||||||
array('dns_get_record'),
|
array('dns_get_record'),
|
||||||
array('foobarfoobar')
|
array('foobarfoobar')
|
||||||
);
|
);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('dns_get_record')
|
->method('dns_get_record')
|
||||||
->will($this->returnValue(array(array('ip' => '127.0.0.255'))));
|
->will($this->returnValue(array(array('ip' => '127.0.0.255'))));
|
||||||
|
|
||||||
$results = $mock->query('1.2.3.4');
|
$results = $mock->query('1.2.3.4');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
array('Reserved for Future Use'),
|
array('Reserved for Future Use'),
|
||||||
$results['categories']
|
$results['categories']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWithout127()
|
public function testWithout127()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock(
|
$mock = $this->getMock(
|
||||||
'joshtronic\ProjectHoneyPot',
|
'joshtronic\ProjectHoneyPot',
|
||||||
array('dns_get_record'),
|
array('dns_get_record'),
|
||||||
array('foobarfoobar')
|
array('foobarfoobar')
|
||||||
);
|
);
|
||||||
|
|
||||||
$mock->expects($this->once())
|
$mock->expects($this->once())
|
||||||
->method('dns_get_record')
|
->method('dns_get_record')
|
||||||
->will($this->returnValue(array(array('ip' => '1.0.0.0'))));
|
->will($this->returnValue(array(array('ip' => '1.0.0.0'))));
|
||||||
|
|
||||||
$this->assertFalse($mock->query('1.2.3.4'));
|
$this->assertFalse($mock->query('1.2.3.4'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Doesn't serve much purpose aside from helping achieve 100% coverage
|
// Doesn't serve much purpose aside from helping achieve 100% coverage
|
||||||
public function testDnsGetRecord()
|
public function testDnsGetRecord()
|
||||||
{
|
{
|
||||||
$object = new joshtronic\ProjectHoneyPot('foobarfoobar');
|
$object = new joshtronic\ProjectHoneyPot('foobarfoobar');
|
||||||
|
|
||||||
$object->dns_get_record('1.2.3.4');
|
$object->dns_get_record('1.2.3.4');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue