diff --git a/api/modules/authserver/Module.php b/api/modules/authserver/Module.php index b2c1b22..09e0026 100644 --- a/api/modules/authserver/Module.php +++ b/api/modules/authserver/Module.php @@ -6,6 +6,7 @@ namespace api\modules\authserver; use Yii; use yii\base\BootstrapInterface; use yii\web\NotFoundHttpException; +use yii\web\Response; class Module extends \yii\base\Module implements BootstrapInterface { @@ -13,7 +14,7 @@ class Module extends \yii\base\Module implements BootstrapInterface { public $defaultRoute = 'index'; - public function beforeAction($action) { + public function beforeAction($action): bool { if (!parent::beforeAction($action)) { return false; } @@ -23,10 +24,18 @@ class Module extends \yii\base\Module implements BootstrapInterface { return true; } + public function afterAction($action, $result) { + if ($result === null) { + Yii::$app->response->format = Response::FORMAT_RAW; + } + + return parent::afterAction($action, $result); + } + /** * @param \yii\base\Application $app */ - public function bootstrap($app) { + public function bootstrap($app): void { $legacyHost = $app->params['authserverHost']; $app->getUrlManager()->addRules([ "//{$legacyHost}/authserver/auth/" => "{$this->id}/authentication/", diff --git a/api/tests/functional/authserver/InvalidateCest.php b/api/tests/functional/authserver/InvalidateCest.php index 46db699..ad1506a 100644 --- a/api/tests/functional/authserver/InvalidateCest.php +++ b/api/tests/functional/authserver/InvalidateCest.php @@ -1,4 +1,6 @@ andReturnTrue(); + Mock::func(EmailValidator::class, 'checkdnsrr')->andReturn(true); + Mock::func(EmailValidator::class, 'dns_get_record')->andReturn(['']); $model = new RegistrationForm([ 'username' => 'some_username', 'email' => 'some_email@example.com', @@ -72,7 +75,8 @@ class RegistrationFormTest extends TestCase { } public function testSignupWithDefaultLanguage() { - Mock::func(EmailValidator::class, 'checkdnsrr')->andReturnTrue(); + Mock::func(EmailValidator::class, 'checkdnsrr')->andReturn(true); + Mock::func(EmailValidator::class, 'dns_get_record')->andReturn(['']); $model = new RegistrationForm([ 'username' => 'some_username', 'email' => 'some_email@example.com', diff --git a/common/tests/helpers/Mock.php b/common/tests/helpers/Mock.php index 78fe5ab..75eb57e 100644 --- a/common/tests/helpers/Mock.php +++ b/common/tests/helpers/Mock.php @@ -1,5 +1,6 @@ getNamespaceName(); } diff --git a/common/tests/unit/validators/EmailValidatorTest.php b/common/tests/unit/validators/EmailValidatorTest.php index 711c2d8..778a37b 100644 --- a/common/tests/unit/validators/EmailValidatorTest.php +++ b/common/tests/unit/validators/EmailValidatorTest.php @@ -1,4 +1,6 @@ validator = new EmailValidator(); } @@ -41,7 +47,8 @@ class EmailValidatorTest extends TestCase { } public function testValidateAttributeLength() { - Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturnTrue(); + Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturn(false); + $model = $this->createModel( 'emailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemail' . 'emailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemailemail' . @@ -56,16 +63,27 @@ class EmailValidatorTest extends TestCase { $this->assertNotSame(['error.email_too_long'], $model->getErrors('field')); } - public function testValidateAttributeEmail() { - Mock::func(YiiEmailValidator::class, 'checkdnsrr')->times(3)->andReturnValues([false, false, true]); + public function testValidateAttributeEmailCaseNotExistsDomain() { + Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturn(false); + Mock::func(YiiEmailValidator::class, 'dns_get_record')->times(0); - $model = $this->createModel('non-email'); + $model = $this->createModel('non-email@this-domain-does-not-exists.de'); $this->validator->validateAttribute($model, 'field'); $this->assertSame(['error.email_invalid'], $model->getErrors('field')); + } - $model = $this->createModel('non-email@etot-domen-ne-suschestrvyet.de'); + public function testValidateAttributeEmailCaseExistsDomainButWithoutMXRecord() { + Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturnValues([false, true]); + Mock::func(YiiEmailValidator::class, 'dns_get_record')->andReturn(['127.0.0.1']); + + $model = $this->createModel('non-email@this-domain-has-no-mx-record.de'); $this->validator->validateAttribute($model, 'field'); - $this->assertSame(['error.email_invalid'], $model->getErrors('field')); + $this->assertNotSame(['error.email_invalid'], $model->getErrors('field')); + } + + public function testValidateAttributeEmailCaseExistsDomainWithMXRecord() { + Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturn(true); + Mock::func(YiiEmailValidator::class, 'dns_get_record')->andReturn(['mx.google.com']); $model = $this->createModel('valid-email@gmail.com'); $this->validator->validateAttribute($model, 'field'); @@ -73,7 +91,8 @@ class EmailValidatorTest extends TestCase { } public function testValidateAttributeTempmail() { - Mock::func(YiiEmailValidator::class, 'checkdnsrr')->times(2)->andReturnTrue(); + Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturn(true); + Mock::func(YiiEmailValidator::class, 'dns_get_record')->andReturn(['127.0.0.1']); $model = $this->createModel('ibrpycwyjdnt@dropmail.me'); $this->validator->validateAttribute($model, 'field'); @@ -85,7 +104,8 @@ class EmailValidatorTest extends TestCase { } public function testValidateAttributeIdna() { - Mock::func(YiiEmailValidator::class, 'checkdnsrr')->times(2)->andReturnTrue(); + Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturn(true); + Mock::func(YiiEmailValidator::class, 'dns_get_record')->andReturn(['127.0.0.1']); $model = $this->createModel('qdushyantasunassm@❕.gq'); $this->validator->validateAttribute($model, 'field'); @@ -97,7 +117,8 @@ class EmailValidatorTest extends TestCase { } public function testValidateAttributeUnique() { - Mock::func(YiiEmailValidator::class, 'checkdnsrr')->times(3)->andReturnTrue(); + Mock::func(YiiEmailValidator::class, 'checkdnsrr')->andReturn(true); + Mock::func(YiiEmailValidator::class, 'dns_get_record')->andReturn(['127.0.0.1']); $this->tester->haveFixtures([ 'accounts' => AccountFixture::class, diff --git a/composer.json b/composer.json index f39482e..864979b 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "minimum-stability": "stable", "require": { "php": "^7.2", + "ext-intl": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", @@ -24,7 +25,7 @@ "ramsey/uuid": "^3.5", "spomky-labs/otphp": "^9.0.2", "webmozart/assert": "^1.2.0", - "yiisoft/yii2": "2.0.15.1", + "yiisoft/yii2": "~2.0.20", "yiisoft/yii2-queue": "^2.2.0", "yiisoft/yii2-redis": "~2.0.0", "yiisoft/yii2-swiftmailer": "~2.1.0" diff --git a/composer.lock b/composer.lock index d6056bc..7a3d699 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "752322170e3433ba42cb90c1dd6122a2", + "content-hash": "80ccf8b828493911307a9daa95021dfc", "packages": [ { "name": "bacon/bacon-qr-code", @@ -1988,24 +1988,24 @@ }, { "name": "yiisoft/yii2", - "version": "2.0.15.1", + "version": "2.0.20", "source": { "type": "git", "url": "https://github.com/yiisoft/yii2-framework.git", - "reference": "ed3a9e1c4abe206e1c3ce48a6b3624119b79850d" + "reference": "bd05e0e0ac353cb239997da78f459d0960a1fe9f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/ed3a9e1c4abe206e1c3ce48a6b3624119b79850d", - "reference": "ed3a9e1c4abe206e1c3ce48a6b3624119b79850d", + "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/bd05e0e0ac353cb239997da78f459d0960a1fe9f", + "reference": "bd05e0e0ac353cb239997da78f459d0960a1fe9f", "shasum": "" }, "require": { "bower-asset/inputmask": "~3.2.2 | ~3.3.5", - "bower-asset/jquery": "3.2.*@stable | 3.1.*@stable | 2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable", + "bower-asset/jquery": "3.4.*@stable | 3.3.*@stable | 3.2.*@stable | 3.1.*@stable | 2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable", "bower-asset/punycode": "1.3.*", "bower-asset/yii2-pjax": "~2.0.1", - "cebe/markdown": "~1.0.0 | ~1.1.0", + "cebe/markdown": "~1.0.0 | ~1.1.0 | ~1.2.0", "ext-ctype": "*", "ext-mbstring": "*", "ezyang/htmlpurifier": "~4.6", @@ -2084,7 +2084,7 @@ "framework", "yii2" ], - "time": "2018-03-21T18:36:53+00:00" + "time": "2019-06-04T19:10:59+00:00" }, { "name": "yiisoft/yii2-composer", @@ -2142,16 +2142,16 @@ }, { "name": "yiisoft/yii2-queue", - "version": "2.2.0", + "version": "2.3.0", "source": { "type": "git", "url": "https://github.com/yiisoft/yii2-queue.git", - "reference": "d365e6f3222a0fdb150b1ea9f17bda2a4ddac61d" + "reference": "25c1142558768ec0e835171c972a4edc2fb59cf0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/yiisoft/yii2-queue/zipball/d365e6f3222a0fdb150b1ea9f17bda2a4ddac61d", - "reference": "d365e6f3222a0fdb150b1ea9f17bda2a4ddac61d", + "url": "https://api.github.com/repos/yiisoft/yii2-queue/zipball/25c1142558768ec0e835171c972a4edc2fb59cf0", + "reference": "25c1142558768ec0e835171c972a4edc2fb59cf0", "shasum": "" }, "require": { @@ -2161,7 +2161,8 @@ }, "require-dev": { "aws/aws-sdk-php": ">=2.4", - "enqueue/amqp-lib": "^0.8", + "enqueue/amqp-lib": "^0.8||^0.9.10", + "enqueue/stomp": "^0.8.39", "jeremeamia/superclosure": "*", "pda/pheanstalk": "v3.*", "php-amqplib/php-amqplib": "*", @@ -2173,6 +2174,7 @@ "suggest": { "aws/aws-sdk-php": "Need for aws SQS.", "enqueue/amqp-lib": "Need for AMQP interop queue.", + "enqueue/stomp": "Need for Stomp queue.", "ext-gearman": "Need for Gearman queue.", "ext-pcntl": "Need for process signals.", "pda/pheanstalk": "Need for Beanstalk queue.", @@ -2196,7 +2198,8 @@ "yii\\queue\\gearman\\": "src/drivers/gearman", "yii\\queue\\redis\\": "src/drivers/redis", "yii\\queue\\sync\\": "src/drivers/sync", - "yii\\queue\\sqs\\": "src/drivers/sqs" + "yii\\queue\\sqs\\": "src/drivers/sqs", + "yii\\queue\\stomp\\": "src/drivers/stomp" } }, "notification-url": "https://packagist.org/downloads/", @@ -2222,7 +2225,7 @@ "sqs", "yii" ], - "time": "2019-03-19T22:36:41+00:00" + "time": "2019-06-04T18:58:40+00:00" }, { "name": "yiisoft/yii2-redis", @@ -6146,6 +6149,7 @@ "prefer-lowest": false, "platform": { "php": "^7.2", + "ext-intl": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*",