From db1d41449c932c784ea5bda78d6ec69ef3b1592e Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Tue, 4 Apr 2017 14:59:23 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8,=20=D1=87=D1=82=D0=BE=D0=B1=D1=8B=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D1=82=D1=80=D0=B5=D0=B1=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BE?= =?UTF-8?q?=D1=82=D1=81=D1=83=D1=82=D1=81=D1=82=D0=B2=D0=B8=D1=8F=20Bearer?= =?UTF-8?q?=20=D1=82=D0=BE=D0=BA=D0=B5=D0=BD=D0=B0=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=81=D0=BB=D1=83=D1=87=D0=B0=D0=B5=D0=B2,=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=B3=D0=B4=D0=B0=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BD=D0=B5=20=D1=82=D1=80=D0=B5?= =?UTF-8?q?=D0=B1=D1=83=D0=B5=D1=82=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/components/User/Component.php | 21 +--------- api/controllers/FeedbackController.php | 2 +- .../unit/components/User/ComponentTest.php | 40 ------------------- 3 files changed, 2 insertions(+), 61 deletions(-) diff --git a/api/components/User/Component.php b/api/components/User/Component.php index ab64291..670839c 100644 --- a/api/components/User/Component.php +++ b/api/components/User/Component.php @@ -24,6 +24,7 @@ use yii\web\User as YiiUserComponent; * @property AccountIdentity|null $identity * * @method AccountIdentity|null loginByAccessToken($token, $type = null) + * @method AccountIdentity|null getIdentity($autoRenew = true) */ class Component extends YiiUserComponent { @@ -44,8 +45,6 @@ class Component extends YiiUserComponent { public $sessionTimeout = 'P7D'; - private $_identity; - public function init() { parent::init(); if (!$this->secret) { @@ -53,24 +52,6 @@ class Component extends YiiUserComponent { } } - /** - * @param bool $autoRenew - * @return null|AccountIdentity - */ - public function getIdentity($autoRenew = true) { - $result = parent::getIdentity($autoRenew); - if ($result === null && $this->_identity !== false) { - $bearer = $this->getBearerToken(); - if ($bearer !== null) { - $result = $this->loginByAccessToken($bearer); - } - - $this->_identity = $result ?: false; - } - - return $result; - } - /** * @param IdentityInterface $identity * @param bool $rememberMe diff --git a/api/controllers/FeedbackController.php b/api/controllers/FeedbackController.php index 5d4885a..7f50ded 100644 --- a/api/controllers/FeedbackController.php +++ b/api/controllers/FeedbackController.php @@ -10,7 +10,7 @@ class FeedbackController extends Controller { public function behaviors() { return ArrayHelper::merge(parent::behaviors(), [ 'authenticator' => [ - 'except' => ['index'], + 'optional' => ['index'], ], ]); } diff --git a/tests/codeception/api/unit/components/User/ComponentTest.php b/tests/codeception/api/unit/components/User/ComponentTest.php index 9f488f1..514fd1a 100644 --- a/tests/codeception/api/unit/components/User/ComponentTest.php +++ b/tests/codeception/api/unit/components/User/ComponentTest.php @@ -41,46 +41,6 @@ class ComponentTest extends TestCase { ]; } - public function testGetIdentity() { - $this->specify('getIdentity should return null, if not authorization header', function() { - $this->mockAuthorizationHeader(null); - $this->assertNull($this->component->getIdentity()); - }); - - $this->specify('getIdentity should return null, if passed bearer token don\'t return any account', function() { - $this->mockAuthorizationHeader('some-auth'); - /** @var Component|\PHPUnit_Framework_MockObject_MockObject $component */ - $component = $this->getMockBuilder(Component::class) - ->setMethods(['loginByAccessToken']) - ->setConstructorArgs([$this->getComponentArguments()]) - ->getMock(); - - $component - ->expects($this->once()) - ->method('loginByAccessToken') - ->willReturn(null); - - $this->assertNull($component->getIdentity()); - }); - - $this->specify('getIdentity should return identity from loginByAccessToken method', function() { - $identity = new AccountIdentity(); - $this->mockAuthorizationHeader('some-auth'); - /** @var Component|\PHPUnit_Framework_MockObject_MockObject $component */ - $component = $this->getMockBuilder(Component::class) - ->setMethods(['loginByAccessToken']) - ->setConstructorArgs([$this->getComponentArguments()]) - ->getMock(); - - $component - ->expects($this->once()) - ->method('loginByAccessToken') - ->willReturn($identity); - - $this->assertEquals($identity, $component->getIdentity()); - }); - } - public function testLogin() { $this->mockRequest(); $this->specify('success get LoginResult object without session value', function() {