318 lines
8.9 KiB
PHP
318 lines
8.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* DomFramework - Tests
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework\Tests;
|
|
|
|
use Domframework\Spfcheck;
|
|
|
|
/**
|
|
* Test the Spfcheck tools
|
|
*/
|
|
class SpfcheckTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function testGetRecordsNoSPF()
|
|
{
|
|
$this->expectException(
|
|
"Exception",
|
|
"Can not find a valid SPF TXT entry in DNS for domain " .
|
|
"'notfound.tester.fournier38.fr'",
|
|
403
|
|
);
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("notfound.tester.fournier38.fr");
|
|
}
|
|
|
|
public function testGetRecordsSPFReject()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("reject.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["reject.spf.tester.fournier38.fr" =>
|
|
["-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsLoop()
|
|
{
|
|
$this->expectException(
|
|
"Exception",
|
|
"SPFCheck : Too much DNS requests (30 >= 30)",
|
|
500
|
|
);
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("loop.spf.tester.fournier38.fr");
|
|
$this->assertSame($res, []);
|
|
}
|
|
|
|
public function testGetRecordsIncludeEmptyInclude()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("includeempty.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["includeempty.spf.tester.fournier38.fr" =>
|
|
["include:" => [], "-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsRedirectEmptyRedirect()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("redirectempty.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["redirectempty.spf.tester.fournier38.fr" =>
|
|
["redirect=" => [], "-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsMXEmptyMX()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("mx.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["mx.spf.tester.fournier38.fr" =>
|
|
["mx" => [], "-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsMXValidMX()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("mxvalid.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["mxvalid.spf.tester.fournier38.fr" => [
|
|
"mx:tester.fournier38.fr" => [
|
|
"2a01:e0a:2a7:9cd1::103",
|
|
"2a01:e0a:392:ab60::206",
|
|
"82.64.75.195",
|
|
"82.66.67.64"],
|
|
"-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsAEmptyA()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("a.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["a.spf.tester.fournier38.fr" =>
|
|
["a" => [], "-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsAValidA()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("avalid.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["avalid.spf.tester.fournier38.fr" => [
|
|
"a:tester.fournier38.fr" => [
|
|
"2a01:e0a:2a7:9cd1::100",
|
|
"82.64.75.195",],
|
|
"-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsIP4EmptyIP4()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("ip4empty.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["ip4empty.spf.tester.fournier38.fr" => [
|
|
"ip4:" => [],
|
|
"-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsIP4InvalidIP4()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("ip4invalid.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["ip4invalid.spf.tester.fournier38.fr" => [
|
|
"ip4:0::1" => [],
|
|
"-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsIP4ValidIP4()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("ip4valid.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["ip4valid.spf.tester.fournier38.fr" => [
|
|
"ip4:192.168.1.1" => ["192.168.1.1"],
|
|
"-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsIP6EmptyIP6()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("ip6empty.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["ip6empty.spf.tester.fournier38.fr" => [
|
|
"ip6:" => [],
|
|
"-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsIP6InvalidIP6()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("ip6invalid.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["ip6invalid.spf.tester.fournier38.fr" => [
|
|
"ip6:192.168.1.1" => [],
|
|
"-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsIP6ValidIP6()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("ip6valid.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["ip6valid.spf.tester.fournier38.fr" => [
|
|
"ip6:0::1" => ["0::1"],
|
|
"-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsPTR()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("ptrvalid.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["ptrvalid.spf.tester.fournier38.fr" => [
|
|
"ptr" => [],
|
|
"-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsAllMultiple()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("allmultiple.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["allmultiple.spf.tester.fournier38.fr" => [
|
|
"+all" => [],
|
|
"-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsAllNotEnd()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("allnotend.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["allnotend.spf.tester.fournier38.fr" => [
|
|
"+all" => [],
|
|
"mx" => []]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsAllNotSet()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("allnotset.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["allnotset.spf.tester.fournier38.fr" => [
|
|
"mx" => []]]
|
|
);
|
|
}
|
|
|
|
public function testWideIPRange()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$spfcheck->getRecords("wide.spf.tester.fournier38.fr");
|
|
$res = $spfcheck->getErrors();
|
|
$this->assertSame(
|
|
$res,
|
|
["wide.spf.tester.fournier38.fr" => [
|
|
"ip4:213.131.32.0/2" => "Invalid ip4 set for domain 'wide.spf.tester.fournier38.fr' : Mask '/2' too wide",
|
|
"ip6:2001::/20" => "Invalid ip6 set for domain 'wide.spf.tester.fournier38.fr' : Mask '/20' too wide"
|
|
]]
|
|
);
|
|
}
|
|
|
|
public function testRecordsWithPlus()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("plus.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["plus.spf.tester.fournier38.fr" => [
|
|
"+a" => [],
|
|
"+mx" => [],
|
|
"+ip4:178.33.236.5" => ["178.33.236.5"],
|
|
"-ip4:137.74.69.64" => ["137.74.69.64"],
|
|
"+ip4:51.254.45.81" => ["51.254.45.81"],
|
|
"-all" => [],
|
|
]]
|
|
);
|
|
}
|
|
|
|
public function testGetRecordsUnknown()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->getRecords("unknown.spf.tester.fournier38.fr");
|
|
$this->assertSame(
|
|
$res,
|
|
["unknown.spf.tester.fournier38.fr" => [
|
|
"unknown" => [],
|
|
"-all" => []]]
|
|
);
|
|
}
|
|
|
|
public function testIpCheckToSPFOKInA()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "178.33.236.5");
|
|
$this->assertSame($res, "PASS");
|
|
}
|
|
|
|
public function testIpCheckToSPFFAILInALL()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "1.3.6.5");
|
|
$this->assertSame($res, "FAIL");
|
|
}
|
|
|
|
public function testIpCheckToSPFOKInALL()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "1.3.6.5");
|
|
$this->assertSame($res, "FAIL");
|
|
}
|
|
|
|
public function testIpCheckToSPFFAILInIP4()
|
|
{
|
|
$spfcheck = new Spfcheck();
|
|
$res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "137.74.69.64");
|
|
$this->assertSame($res, "FAIL");
|
|
}
|
|
}
|