OSDN Git Service

host_normalize(): Don't cut 'www' with Non-ASCII-based string such as IDN
[pukiwiki/pukiwiki_sandbox.git] / spam / SpamPickupTest.php
index 77890c4..8f0d5ec 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-// $Id: SpamPickupTest.php,v 1.3 2007/08/20 14:37:23 henoheno Exp $
+// $Id: SpamPickupTest.php,v 1.5 2008/12/27 11:50:55 henoheno Exp $
 // Copyright (C) 2007 heno
 //
 // Design test case for spam.php (called from runner.php)
@@ -54,7 +54,7 @@ class SpamPickupTest extends PHPUnit_TestCase
 
        function testFunc_host_normalize()
        {
-               // Null
+               // Invalid: Null
                foreach($this->setup_string_null() as $key => $value){
                        $this->assertEquals('', host_normalize($value), $key);
                }
@@ -62,8 +62,12 @@ class SpamPickupTest extends PHPUnit_TestCase
                // Hostname is case-insensitive
                $this->assertEquals('example.org', host_normalize('ExAMPle.ORG'));
 
-               // Cut 'www' (destructive)
+               // Cut 'www' with traditional ASCII-based FQDN (destructive)
                $this->assertEquals('example.org', host_normalize('WWW.example.org'));
+
+               // Don't cut 'www' with Non-ASCII-based string such as IDN
+               $this->assertEquals("www.example.org\0foobar",
+                        host_normalize("WWW.example.org\0foobar"));
        }
 
        function testFunc_port_normalize()
@@ -360,6 +364,18 @@ EOF;
                $results = spam_uri_pickup($test_string);
                $this->assertEquals('victim.example.org', $results[0]['host']);
                $this->assertEquals('nasty.example.org',  $results[1]['host']);
+
+               // Domain exposure (site:)
+               $test_string = ' http://search.example.org/?q=%20site:nasty.example.org ';
+               $results = spam_uri_pickup($test_string);
+               $this->assertEquals('nasty.example.org', $results[0]['host']);
+               $this->assertEquals('search.example.org',  $results[1]['host']);
+               
+               // Domain exposure (%20site:)
+               $test_string = ' http://search2.example.org/?q=%20site:nasty2.example.org ';
+               $results = spam_uri_pickup($test_string);
+               $this->assertEquals('nasty2.example.org', $results[0]['host']);
+               $this->assertEquals('search2.example.org',  $results[1]['host']);
        }
 }