mirror of
https://github.com/elyby/accounts.git
synced 2024-12-29 16:40:25 +05:30
Fixes ACCOUNTS-5Y5. Also idna escape login part of the email.
This commit is contained in:
parent
3d89e5f94d
commit
3b00e36816
@ -102,17 +102,22 @@ class EmailValidatorTest extends TestCase {
|
||||
$this->assertNotSame(['error.email_is_tempmail'], $model->getErrors('field'));
|
||||
}
|
||||
|
||||
public function testValidateAttributeIdna() {
|
||||
/**
|
||||
* @dataProvider getValidateAttributeIdnaTestCases
|
||||
*/
|
||||
public function testValidateAttributeIdna(string $input, string $expectedOutput) {
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'checkdnsrr')->expects($this->any())->willReturn(true);
|
||||
$this->getFunctionMock(YiiEmailValidator::class, 'dns_get_record')->expects($this->any())->willReturn(['127.0.0.1']);
|
||||
|
||||
$model = $this->createModel('qdushyantasunassm@❕.gq');
|
||||
$model = $this->createModel($input);
|
||||
$this->validator->validateAttribute($model, 'field');
|
||||
$this->assertSame('qdushyantasunassm@xn--bei.gq', $model->field);
|
||||
$this->assertSame($expectedOutput, $model->field);
|
||||
}
|
||||
|
||||
$model = $this->createModel('valid-email@gmail.com');
|
||||
$this->validator->validateAttribute($model, 'field');
|
||||
$this->assertSame('valid-email@gmail.com', $model->field);
|
||||
public function getValidateAttributeIdnaTestCases() {
|
||||
yield ['qdushyantasunassm@❕.gq', 'qdushyantasunassm@xn--bei.gq'];
|
||||
yield ['Rafaelaabraão@gmail.com', 'xn--rafaelaabrao-dcb@gmail.com'];
|
||||
yield ['valid-email@gmail.com', 'valid-email@gmail.com'];
|
||||
}
|
||||
|
||||
public function testValidateAttributeUnique() {
|
||||
|
@ -40,7 +40,7 @@ class EmailValidator extends Validator {
|
||||
|
||||
$idnaDomain = new validators\FilterValidator(['filter' => function(string $value): string {
|
||||
[$name, $domain] = explode('@', $value);
|
||||
return $name . '@' . idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
|
||||
return idn_to_ascii($name, 0, INTL_IDNA_VARIANT_UTS46) . '@' . idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
|
||||
}]);
|
||||
|
||||
$unique = new validators\UniqueValidator();
|
||||
|
Loading…
Reference in New Issue
Block a user