-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GLUE-11936 : Authorization Enabler (#8404)
GLUE-11936: Authorization Enabler
- Loading branch information
Showing
7 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...mer/Plugin/Authorization/CustomerReferenceMatchingEntityIdAuthorizationStrategyPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace Spryker\Client\Customer\Plugin\Authorization; | ||
|
||
use Generated\Shared\Transfer\AuthorizationRequestTransfer; | ||
use Spryker\Client\AuthorizationExtension\Dependency\Plugin\AuthorizationStrategyPluginInterface; | ||
|
||
class CustomerReferenceMatchingEntityIdAuthorizationStrategyPlugin implements AuthorizationStrategyPluginInterface | ||
{ | ||
protected const STRATEGY_NAME = 'CustomerReferenceMatchingEntityId'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @api | ||
* | ||
* @param \Generated\Shared\Transfer\AuthorizationRequestTransfer $authorizationRequestTransfer | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize(AuthorizationRequestTransfer $authorizationRequestTransfer): bool | ||
{ | ||
return $authorizationRequestTransfer->getEntity()->getIdentifier() === $authorizationRequestTransfer->getIdentity()->getIdentifier(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @api | ||
* | ||
* @return string | ||
*/ | ||
public function getStrategyName(): string | ||
{ | ||
return static::STRATEGY_NAME; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
tests/SprykerTest/Client/Customer/CustomerAuthorizationClientTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerTest\Client\Customer; | ||
|
||
use Codeception\Test\Unit; | ||
use Generated\Shared\Transfer\AuthorizationEntityTransfer; | ||
use Generated\Shared\Transfer\AuthorizationIdentityTransfer; | ||
use Generated\Shared\Transfer\AuthorizationRequestTransfer; | ||
use Spryker\Client\Customer\Plugin\Authorization\CustomerReferenceMatchingEntityIdAuthorizationStrategyPlugin; | ||
|
||
/** | ||
* Auto-generated group annotations | ||
* | ||
* @group SprykerTest | ||
* @group Client | ||
* @group Customer | ||
* @group CustomerAuthorizationClientTest | ||
* Add your own group annotations below this line | ||
*/ | ||
class CustomerAuthorizationClientTest extends Unit | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
public function testCustomerAuthorizationStrategyPlugin(): void | ||
{ | ||
// Arrange | ||
$customerAuthorizationStrategyPlugin = new CustomerReferenceMatchingEntityIdAuthorizationStrategyPlugin(); | ||
$authorizationRequestTransfer = (new AuthorizationRequestTransfer()) | ||
->setIdentity( | ||
(new AuthorizationIdentityTransfer()) | ||
->setIdentifier('test') | ||
) | ||
->setEntity( | ||
(new AuthorizationEntityTransfer()) | ||
->setIdentifier('test') | ||
); | ||
|
||
// Act | ||
$result = $customerAuthorizationStrategyPlugin->authorize($authorizationRequestTransfer); | ||
|
||
// Assert | ||
$this->isTrue($result); | ||
$this->assertSame($customerAuthorizationStrategyPlugin->getStrategyName(), 'CustomerReferenceMatchingEntityId'); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testCustomerAuthorizationStrategyPluginReturnsFalse(): void | ||
{ | ||
// Arrange | ||
$customerAuthorizationStrategyPlugin = new CustomerReferenceMatchingEntityIdAuthorizationStrategyPlugin(); | ||
$authorizationRequestTransfer = (new AuthorizationRequestTransfer()) | ||
->setIdentity( | ||
(new AuthorizationIdentityTransfer()) | ||
->setIdentifier('test') | ||
) | ||
->setEntity( | ||
(new AuthorizationEntityTransfer()) | ||
->setIdentifier('wrongIdentifier') | ||
); | ||
|
||
// Act | ||
$result = $customerAuthorizationStrategyPlugin->authorize($authorizationRequestTransfer); | ||
|
||
// Assert | ||
$this->isFalse($result); | ||
$this->assertSame($customerAuthorizationStrategyPlugin->getStrategyName(), 'CustomerReferenceMatchingEntityId'); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/SprykerTest/Client/Customer/_support/CustomerClientTester.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerTest\Client\Customer; | ||
|
||
use Codeception\Actor; | ||
|
||
/** | ||
* Inherited Methods | ||
* | ||
* @method void wantToTest($text) | ||
* @method void wantTo($text) | ||
* @method void execute($callable) | ||
* @method void expectTo($prediction) | ||
* @method void expect($prediction) | ||
* @method void amGoingTo($argumentation) | ||
* @method void am($role) | ||
* @method void lookForwardTo($achieveValue) | ||
* @method void comment($description) | ||
* @method void pause() | ||
* | ||
* @SuppressWarnings(PHPMD) | ||
*/ | ||
class CustomerClientTester extends Actor | ||
{ | ||
use _generated\CustomerClientTesterActions; | ||
|
||
/** | ||
* Define custom actions here | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace: SprykerTest\Client\Customer | ||
paths: | ||
tests: . | ||
data: ../../../_data | ||
support: _support | ||
log: ../../../_output | ||
coverage: | ||
enabled: true | ||
remote: false | ||
whitelist: | ||
include: | ||
- '../../../../src/*' | ||
suites: | ||
Client: | ||
path: . | ||
class_name: CustomerClientTester | ||
modules: | ||
enabled: | ||
- Asserts | ||
- \SprykerTest\Shared\Testify\Helper\Environment | ||
- \SprykerTest\Shared\Testify\Helper\ConfigHelper | ||
- \SprykerTest\Shared\Testify\Helper\LocatorHelper |