<?php
-// $Id: SpamTest.php,v 1.16 2007/06/23 14:11:10 henoheno Exp $
+// $Id: SpamTest.php,v 1.17 2007/06/23 15:21:32 henoheno Exp $
// Copyright (C) 2007 heno
//
// Design test case for spam.php (called from runner.php)
$test_string = ' http://192.168.0.1/fobar.html ';
$results = uri_pickup_normalize(uri_pickup($test_string));
$this->assertEquals('192.168.0.1', $results[0]['host']);
+
+ // Host: Starts
+ $test_string = ' http://_sss/foo.html ';
+ $results = uri_pickup_normalize(uri_pickup($test_string));
+ $this->assertEquals('_sss', $results[0]['host']);
+ $this->assertEquals('foo.html', $results[0]['file']);
+
+ // Host: Ends
+ $test_string = ' http://sss_/foo.html ';
+ $results = uri_pickup_normalize(uri_pickup($test_string));
+ $this->assertEquals('sss_', $results[0]['host']);
+ $this->assertEquals('foo.html', $results[0]['file']);
+
+
+ // Specific tests ---- Fails
+
+ // Divider: Colon only (Too sensitive to capture)
+ $test_string = ' http:colon.org ';
+ $results = uri_pickup_normalize(uri_pickup($test_string));
+ $this->assertEquals(0, count($results));
+
+ // Host: Too short
+ $test_string = ' http://s/foo.html http://ss/foo.html ';
+ $results = uri_pickup_normalize(uri_pickup($test_string));
+ $this->assertEquals(0, count($results));
+
+ $test_string = ' http://sss/foo.html ';
+ $results = uri_pickup_normalize(uri_pickup($test_string));
+ $this->assertEquals('sss', $results[0]['host']);
+ $this->assertEquals('foo.html', $results[0]['file']);
}
function testFunc_scheme_normalize()
$array = get_blocklist('goodhost');
$this->assertTrue(isset($array['IANA-examples']));
}
+
+
+ function testFunc_whois_responsibility()
+ {
+ // 1st argument: Null
+ foreach($this->setup_string_null() as $key => $value){
+ $this->assertEquals('', whois_responsibility($value), $key);
+ }
+
+ // 'act.edu.au' is known as 3rd level domain
+ $this->AssertEquals('bar.act.edu.au', whois_responsibility('foo.bar.act.edu.au'));
+ $this->AssertEquals('bar.act.edu.au', whois_responsibility('bar.act.edu.au'));
+ $this->AssertEquals('act.edu.au', whois_responsibility('act.edu.au'));
+ $this->AssertEquals('edu.au', whois_responsibility('edu.au'));
+ $this->AssertEquals('au', whois_responsibility('au'));
+
+ // 'co.uk' is known as 2nd level domain
+ $this->AssertEquals('bar.co.uk', whois_responsibility('foo.bar.co.uk'));
+ $this->AssertEquals('bar.co.uk', whois_responsibility('bar.co.uk'));
+ $this->AssertEquals('co.uk', whois_responsibility('co.uk'));
+ $this->AssertEquals('uk', whois_responsibility('uk'));
+
+ // 'bar.uk' is not 2nd level (implicit responsibility)
+ $this->AssertEquals('bar.uk', whois_responsibility('foo.bar.uk'));
+ $this->AssertEquals('bar.uk', whois_responsibility('bar.uk'));
+
+ // IPv4
+ $this->AssertEquals('192.168.0.1', whois_responsibility('192.168.0.1'));
+
+ // Invalid Top-Level Domain (With implicit)
+ $this->AssertEquals('bar.local', whois_responsibility('foo.bar.local')); // Implicit responsibility
+ $this->AssertEquals('bar.local', whois_responsibility('bar.local'));
+ $this->AssertEquals('local', whois_responsibility('local'));
+ $this->AssertEquals('localhost', whois_responsibility('localhost'));
+ $this->AssertEquals('s', whois_responsibility('s'));
+ }
}
?>
<?php
-// $Id: spam.php,v 1.189 2007/06/23 14:11:10 henoheno Exp $
+// $Id: spam.php,v 1.190 2007/06/23 15:21:10 henoheno Exp $
// Copyright (C) 2006-2007 PukiWiki Developers Team
// License: GPL v2 or (at your option) any later version
//
// 3: Host
'\[[0-9a-f:.]+\]' . '|' . // IPv6([colon-hex and dot]): RFC2732
'(?:[0-9]{1,3}\.){3}[0-9]{1,3}' . '|' . // IPv4(dot-decimal): 001.22.3.44
- '[a-z0-9][a-z0-9_.-]+[a-z0-9]' . // hostname(FQDN) : foo.example.org
+ '[a-z0-9_-][a-z0-9_.-]+[a-z0-9_-]' . // hostname(FQDN) : foo.example.org
')' .
'(?::([0-9]*))?' . // 4: Port
'((?:/+[^\s<>"\'\[\]/\#]+)*/+)?' . // 5: Directory path or path-info
foreach($progress['hosts'] as $value) {
// 'A.foo.bar.example.com'
$resp = whois_responsibility($value); // 'example.com'
- $rest = rtrim(substr($value, 0, - strlen($resp)), '.'); // 'A.foo.bar'
+ if (empty($resp)) {
+ // One or more test, or do nothing here
+ $resp = strval($value);
+ $rest = '';
+ } else {
+ $rest = rtrim(substr($value, 0, - strlen($resp)), '.'); // 'A.foo.bar'
+ }
$trie = array_merge_recursive($trie, array($resp => array($rest => NULL)));
}
),
);
- if (is_ip($fqdn) || ! is_string($fqdn)) return $fqdn;
+ if (! is_string($fqdn)) return '';
+ if (is_ip($fqdn)) return $fqdn;
$result = array();
$dcursor = & $domain;
$array = array_reverse(explode('.', $fqdn));
$i = 0;
while(TRUE) {
+ if (! isset($array[$i])) break;
$acursor = $array[$i];
if (is_array($dcursor) && isset($dcursor[$acursor])) {
$result[] = & $array[$i];