* @license BSD */ namespace Domframework\Tests; use Domframework\Spfcheck; /** Test the Spfcheck tools */ class SpfcheckTest extends \PHPUnit_Framework_TestCase { public function test_getRecords_NoSPF() { $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 test_getRecords_SPFReject() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("reject.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("reject.spf.tester.fournier38.fr" => array ("-all" => array ())) ); } public function test_getRecords_Loop() { $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, array ()); } public function test_getRecords_Include_emptyInclude() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("includeempty.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("includeempty.spf.tester.fournier38.fr" => array ("include:" => array (), "-all" => array ())) ); } public function test_getRecords_Redirect_emptyRedirect() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("redirectempty.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("redirectempty.spf.tester.fournier38.fr" => array ("redirect=" => array (), "-all" => array ())) ); } public function test_getRecords_MX_emptyMX() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("mx.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("mx.spf.tester.fournier38.fr" => array ("mx" => array (), "-all" => array ())) ); } public function test_getRecords_MX_validMX() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("mxvalid.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("mxvalid.spf.tester.fournier38.fr" => array ( "mx:tester.fournier38.fr" => array ( "2a01:e0a:2a7:9cd1::103", "2a01:e0a:392:ab60::206", "82.64.75.195", "82.66.67.64"), "-all" => array ())) ); } public function test_getRecords_A_emptyA() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("a.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("a.spf.tester.fournier38.fr" => array ("a" => array (), "-all" => array ())) ); } public function test_getRecords_A_validA() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("avalid.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("avalid.spf.tester.fournier38.fr" => array ( "a:tester.fournier38.fr" => array ( "2a01:e0a:2a7:9cd1::100", "82.64.75.195",), "-all" => array ())) ); } public function test_getRecords_IP4_emptyIP4() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("ip4empty.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("ip4empty.spf.tester.fournier38.fr" => array ( "ip4:" => array (), "-all" => array ())) ); } public function test_getRecords_IP4_invalidIP4() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("ip4invalid.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("ip4invalid.spf.tester.fournier38.fr" => array ( "ip4:0::1" => array (), "-all" => array ())) ); } public function test_getRecords_IP4_validIP4() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("ip4valid.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("ip4valid.spf.tester.fournier38.fr" => array ( "ip4:192.168.1.1" => array ("192.168.1.1"), "-all" => array ())) ); } public function test_getRecords_IP6_emptyIP6() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("ip6empty.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("ip6empty.spf.tester.fournier38.fr" => array ( "ip6:" => array (), "-all" => array ())) ); } public function test_getRecords_IP6_invalidIP6() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("ip6invalid.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("ip6invalid.spf.tester.fournier38.fr" => array ( "ip6:192.168.1.1" => array (), "-all" => array ())) ); } public function test_getRecords_IP6_validIP6() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("ip6valid.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("ip6valid.spf.tester.fournier38.fr" => array ( "ip6:0::1" => array ("0::1"), "-all" => array ())) ); } public function test_getRecords_PTR() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("ptrvalid.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("ptrvalid.spf.tester.fournier38.fr" => array ( "ptr" => array (), "-all" => array ())) ); } public function test_getRecords_All_Multiple() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("allmultiple.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("allmultiple.spf.tester.fournier38.fr" => array ( "+all" => array (), "-all" => array ())) ); } public function test_getRecords_All_NotEnd() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("allnotend.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("allnotend.spf.tester.fournier38.fr" => array ( "+all" => array (), "mx" => array ())) ); } public function test_getRecords_All_NotSet() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("allnotset.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("allnotset.spf.tester.fournier38.fr" => array ( "mx" => array ())) ); } public function test_wideIPRange() { $spfcheck = new Spfcheck(); $spfcheck->getRecords("wide.spf.tester.fournier38.fr"); $res = $spfcheck->getErrors(); $this->assertSame( $res, array ("wide.spf.tester.fournier38.fr" => array ( "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 test_recordsWithPlus() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("plus.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("plus.spf.tester.fournier38.fr" => array ( "+a" => array (), "+mx" => array (), "+ip4:178.33.236.5" => array ("178.33.236.5"), "-ip4:137.74.69.64" => array ("137.74.69.64"), "+ip4:51.254.45.81" => array ("51.254.45.81"), "-all" => array (), )) ); } public function test_getRecords_Unknown() { $spfcheck = new Spfcheck(); $res = $spfcheck->getRecords("unknown.spf.tester.fournier38.fr"); $this->assertSame( $res, array ("unknown.spf.tester.fournier38.fr" => array ( "unknown" => array (), "-all" => array ())) ); } public function test_ipCheckToSPF_OK_inA() { $spfcheck = new Spfcheck(); $res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "178.33.236.5"); $this->assertSame($res, "PASS"); } public function test_ipCheckToSPF_FAIL_inALL() { $spfcheck = new Spfcheck(); $res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "1.3.6.5"); $this->assertSame($res, "FAIL"); } public function test_ipCheckToSPF_OK_inALL() { $spfcheck = new Spfcheck(); $res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "1.3.6.5"); $this->assertSame($res, "FAIL"); } public function test_ipCheckToSPF_FAIL_inIP4() { $spfcheck = new Spfcheck(); $res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "137.74.69.64"); $this->assertSame($res, "FAIL"); } }