mirror of
https://github.com/elyby/accounts.git
synced 2024-11-16 18:23:29 +05:30
Fix some tests
This commit is contained in:
parent
45c2ed601d
commit
6bd054e743
@ -112,22 +112,20 @@ class LoginForm extends ApiForm {
|
|||||||
Assert::true($account->save(), 'Unable to upgrade user\'s password');
|
Assert::true($account->save(), 'Unable to upgrade user\'s password');
|
||||||
}
|
}
|
||||||
|
|
||||||
$refreshToken = null;
|
$session = null;
|
||||||
if ($this->rememberMe) {
|
if ($this->rememberMe) {
|
||||||
$session = new AccountSession();
|
$session = new AccountSession();
|
||||||
$session->account_id = $account->id;
|
$session->account_id = $account->id;
|
||||||
$session->setIp(Yii::$app->request->userIP);
|
$session->setIp(Yii::$app->request->userIP);
|
||||||
$session->generateRefreshToken();
|
$session->generateRefreshToken();
|
||||||
Assert::true($session->save(), 'Cannot save account session model');
|
Assert::true($session->save(), 'Cannot save account session model');
|
||||||
|
|
||||||
$refreshToken = $session->refresh_token;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$token = TokensFactory::createForAccount($account, $session);
|
$token = TokensFactory::createForAccount($account, $session);
|
||||||
|
|
||||||
$transaction->commit();
|
$transaction->commit();
|
||||||
|
|
||||||
return new AuthenticationResult($token, $refreshToken);
|
return new AuthenticationResult($token, $session ? $session->refresh_token : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ use Yii;
|
|||||||
class FunctionalTester extends Actor {
|
class FunctionalTester extends Actor {
|
||||||
use FunctionalTesterActions;
|
use FunctionalTesterActions;
|
||||||
|
|
||||||
public function amAuthenticated(string $asUsername = 'admin'): int {
|
public function amAuthenticated(string $asUsername = 'admin') { // Do not declare type
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
$account = Account::findOne(['username' => $asUsername]);
|
$account = Account::findOne(['username' => $asUsername]);
|
||||||
if ($account === null) {
|
if ($account === null) {
|
||||||
|
@ -9,7 +9,7 @@ use Ramsey\Uuid\Uuid;
|
|||||||
|
|
||||||
class AuthserverSteps extends FunctionalTester {
|
class AuthserverSteps extends FunctionalTester {
|
||||||
|
|
||||||
public function amAuthenticated(string $asUsername = 'admin', string $password = 'password_0'): array {
|
public function amAuthenticated(string $asUsername = 'admin', string $password = 'password_0') {
|
||||||
$route = new AuthserverRoute($this);
|
$route = new AuthserverRoute($this);
|
||||||
$clientToken = Uuid::uuid4()->toString();
|
$clientToken = Uuid::uuid4()->toString();
|
||||||
$route->authenticate([
|
$route->authenticate([
|
||||||
|
@ -25,7 +25,7 @@ class ComponentTest extends TestCase {
|
|||||||
|
|
||||||
public function _before() {
|
public function _before() {
|
||||||
parent::_before();
|
parent::_before();
|
||||||
$this->component = new Component($this->getComponentConfig());
|
$this->component = new Component();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function _fixtures(): array {
|
public function _fixtures(): array {
|
||||||
@ -72,7 +72,6 @@ class ComponentTest extends TestCase {
|
|||||||
/** @var Component|\PHPUnit\Framework\MockObject\MockObject $component */
|
/** @var Component|\PHPUnit\Framework\MockObject\MockObject $component */
|
||||||
$component = $this->getMockBuilder(Component::class)
|
$component = $this->getMockBuilder(Component::class)
|
||||||
->setMethods(['getIsGuest'])
|
->setMethods(['getIsGuest'])
|
||||||
->setConstructorArgs([$this->getComponentConfig()])
|
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$component
|
$component
|
||||||
@ -91,7 +90,7 @@ class ComponentTest extends TestCase {
|
|||||||
$session = $this->tester->grabFixture('sessions', 'admin2');
|
$session = $this->tester->grabFixture('sessions', 'admin2');
|
||||||
|
|
||||||
/** @var Component|\Mockery\MockInterface $component */
|
/** @var Component|\Mockery\MockInterface $component */
|
||||||
$component = mock(Component::class . '[getActiveSession]', [$this->getComponentConfig()])->makePartial();
|
$component = mock(Component::class . '[getActiveSession]')->makePartial();
|
||||||
$component->shouldReceive('getActiveSession')->times(1)->andReturn($session);
|
$component->shouldReceive('getActiveSession')->times(1)->andReturn($session);
|
||||||
|
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
@ -140,15 +139,4 @@ class ComponentTest extends TestCase {
|
|||||||
Yii::$app->request->headers->set('Authorization', $bearerToken);
|
Yii::$app->request->headers->set('Authorization', $bearerToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getComponentConfig() {
|
|
||||||
return [
|
|
||||||
'identityClass' => IdentityFactory::class,
|
|
||||||
'enableSession' => false,
|
|
||||||
'loginUrl' => null,
|
|
||||||
'secret' => 'secret',
|
|
||||||
'publicKeyPath' => 'data/certs/public.crt',
|
|
||||||
'privateKeyPath' => 'data/certs/private.key',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace codeception\api\unit\models;
|
namespace codeception\api\unit\components\User;
|
||||||
|
|
||||||
use api\components\User\JwtIdentity;
|
use api\components\User\JwtIdentity;
|
||||||
use api\tests\unit\TestCase;
|
use api\tests\unit\TestCase;
|
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace common\tests\unit\rbac\rules;
|
namespace common\tests\unit\rbac\rules;
|
||||||
|
|
||||||
use api\components\User\Component;
|
use api\components\User\Component;
|
||||||
@ -13,12 +15,8 @@ use const common\LATEST_RULES_VERSION;
|
|||||||
class AccountOwnerTest extends TestCase {
|
class AccountOwnerTest extends TestCase {
|
||||||
|
|
||||||
public function testIdentityIsNull() {
|
public function testIdentityIsNull() {
|
||||||
$component = mock(Component::class . '[findIdentityByAccessToken]', [[
|
$component = mock(Component::class . '[findIdentityByAccessToken]');
|
||||||
'secret' => 'secret',
|
$component->makePartial();
|
||||||
'publicKeyPath' => 'data/certs/public.crt',
|
|
||||||
'privateKeyPath' => 'data/certs/private.key',
|
|
||||||
]]);
|
|
||||||
$component->shouldDeferMissing();
|
|
||||||
$component->shouldReceive('findIdentityByAccessToken')->andReturn(null);
|
$component->shouldReceive('findIdentityByAccessToken')->andReturn(null);
|
||||||
|
|
||||||
Yii::$app->set('user', $component);
|
Yii::$app->set('user', $component);
|
||||||
@ -38,12 +36,8 @@ class AccountOwnerTest extends TestCase {
|
|||||||
$identity = mock(IdentityInterface::class);
|
$identity = mock(IdentityInterface::class);
|
||||||
$identity->shouldReceive('getAccount')->andReturn($account);
|
$identity->shouldReceive('getAccount')->andReturn($account);
|
||||||
|
|
||||||
$component = mock(Component::class . '[findIdentityByAccessToken]', [[
|
$component = mock(Component::class . '[findIdentityByAccessToken]');
|
||||||
'secret' => 'secret',
|
$component->makePartial();
|
||||||
'publicKeyPath' => 'data/certs/public.crt',
|
|
||||||
'privateKeyPath' => 'data/certs/private.key',
|
|
||||||
]]);
|
|
||||||
$component->shouldDeferMissing();
|
|
||||||
$component->shouldReceive('findIdentityByAccessToken')->withArgs(['token'])->andReturn($identity);
|
$component->shouldReceive('findIdentityByAccessToken')->withArgs(['token'])->andReturn($identity);
|
||||||
|
|
||||||
Yii::$app->set('user', $component);
|
Yii::$app->set('user', $component);
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace common\tests\unit\rbac\rules;
|
namespace common\tests\unit\rbac\rules;
|
||||||
|
|
||||||
use api\components\User\Component;
|
use api\components\User\Component;
|
||||||
@ -34,12 +36,8 @@ class OauthClientOwnerTest extends TestCase {
|
|||||||
$identity->shouldReceive('getAccount')->andReturn($account);
|
$identity->shouldReceive('getAccount')->andReturn($account);
|
||||||
|
|
||||||
/** @var Component|\Mockery\MockInterface $component */
|
/** @var Component|\Mockery\MockInterface $component */
|
||||||
$component = mock(Component::class . '[findIdentityByAccessToken]', [[
|
$component = mock(Component::class . '[findIdentityByAccessToken]');
|
||||||
'secret' => 'secret',
|
$component->makePartial();
|
||||||
'publicKeyPath' => 'data/certs/public.crt',
|
|
||||||
'privateKeyPath' => 'data/certs/private.key',
|
|
||||||
]]);
|
|
||||||
$component->shouldDeferMissing();
|
|
||||||
$component->shouldReceive('findIdentityByAccessToken')->withArgs(['token'])->andReturn($identity);
|
$component->shouldReceive('findIdentityByAccessToken')->withArgs(['token'])->andReturn($identity);
|
||||||
|
|
||||||
Yii::$app->set('user', $component);
|
Yii::$app->set('user', $component);
|
||||||
|
Loading…
Reference in New Issue
Block a user