diff options
author | sebastianpiskorski <s.piskorski@piwik.pro> | 2016-02-01 23:18:04 +0300 |
---|---|---|
committer | sebastianpiskorski <s.piskorski@piwik.pro> | 2016-03-24 14:07:17 +0300 |
commit | 88ad8c95aaac3bf6ebc17c4ebc6db40b534c9267 (patch) | |
tree | 3f850ebb979f8981898b3b30710cb284228e90a4 /tests | |
parent | f8d3e6fad11413cbeef5eb71080773dadf944012 (diff) |
Test for PR #9486, Validate allowed TLDs with current IANA list
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/Integration/EmailValidatorTest.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/PHPUnit/Integration/EmailValidatorTest.php b/tests/PHPUnit/Integration/EmailValidatorTest.php index 4b2e215506..262baab9e0 100644 --- a/tests/PHPUnit/Integration/EmailValidatorTest.php +++ b/tests/PHPUnit/Integration/EmailValidatorTest.php @@ -8,6 +8,7 @@ namespace Piwik\Tests\Integration; +use Piwik\Http; use Piwik\Piwik; /** @@ -20,6 +21,62 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase return Piwik::isValidEmailString($email); } + private function getAllTlds() + { + /** @var array $response */ + $response = \Piwik\Http::sendHttpRequest("http://data.iana.org/TLD/tlds-alpha-by-domain.txt", 30, null, null, null, null, null, true); + + $this->assertEquals("200", $response['status']); + + $tlds = explode("\n", $response['data']); + foreach ($tlds as $key => $tld) { + if (strpos($tld, '#') !== false || $tld == "") { + unset($tlds[$key]); + } + } + return $tlds; + } + + public function test_allCurrentTlds(){ + $tlds = $this->getAllTlds(); + if (count($tlds) === 0) { + $this->markTestSkipped("Couldn't get TLD list"); + } + + foreach ($tlds as $key => $tld) { + if (strpos(mb_strtolower($tld), 'xn--') !== 0) { + $tld = mb_strtolower($tld); + } + $this->assertTrue( + $this->isValid('test@example.' . idn_to_utf8($tld)) + ); + } + } + + public function test_invalidTld(){ + $tlds = [ + strval(bin2hex(openssl_random_pseudo_bytes(64))), //generates 128 bit length string + '-tld-cannot-start-from-hypen', + 'ąęśćżźł-there-is-no-such-idn', + 'xn--fd67as67fdsa', //no such idn punycode + '!@#-inavlid-chars-in-tld', + 'no spaces in tld allowed', + 'no--double--hypens--allowed' + ]; + if (count($tlds) === 0) { + $this->markTestSkipped("Couldn't get TLD list"); + } + + foreach ($tlds as $key => $tld) { + if (strpos(mb_strtolower($tld), 'xn--') !== 0) { + $tld = mb_strtolower($tld); + } + $this->assertFalse( + $this->isValid('test@example.' . idn_to_utf8($tld)) + ); + } + } + public function test_isValid_validStandard() { $this->assertTrue($this->isValid('test@example.com')); |