chore: stashing old stuff

This commit is contained in:
Josh Sherman 2024-11-20 16:16:04 -06:00
parent 6a70fd2f26
commit 932e2ca800
No known key found for this signature in database
GPG key ID: 55B058A80530EF22
2 changed files with 85 additions and 31 deletions

View file

@ -9,7 +9,7 @@
* Redistribution of these files must retain the above copyright notice.
*
* @author Josh Sherman <hello@joshtronic.com>
* @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

View file

@ -1,6 +1,5 @@
<?php
require_once '../src/ProjectHoneyPot.php';
require_once './src/ProjectHoneyPot.php';
if (
!class_exists('\PHPUnit_Framework_TestCase')
@ -9,21 +8,41 @@ if (
class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
}
$createMock = 'createMock';
if (version_compare(PHPUnit_Runner_Version::id(), '5.4', '<=')) {
$createMock = 'getMock';
}
class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
{
/**
* @expectedException Exception
* @expectedExceptionMessage You must specify a valid API key.
*/
public function testCreateMock()
{
$this->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()
{
$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',