diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2016-03-28 22:11:08 +0300 |
---|---|---|
committer | Thomas Steur <tsteur@users.noreply.github.com> | 2016-03-28 22:11:08 +0300 |
commit | 9c0f876ef7e75b39c55a162cafde1125825b7d9d (patch) | |
tree | 03e9ed82e560ea9b8276caa207dc76aecf7f5a01 /tests | |
parent | af7997f920759677c8cf7c9ffe20ead30ae44471 (diff) | |
parent | 88ad8c95aaac3bf6ebc17c4ebc6db40b534c9267 (diff) |
Merge pull request #9674 from sebastianpiskorski/9486_test_case
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')); |