Skip to content

Commit

Permalink
GLUE-11936 : Authorization Enabler (#8404)
Browse files Browse the repository at this point in the history
GLUE-11936: Authorization Enabler
  • Loading branch information
vol4onok authored Aug 6, 2021
1 parent 0f3ab6d commit 81e0509
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 0 deletions.
1 change: 1 addition & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace: Customer
include:
- tests/SprykerTest/Zed/Customer
- tests/SprykerTest/Client/Customer

paths:
tests: tests
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"license": "proprietary",
"require": {
"php": ">=7.3",
"spryker/authorization-extension": "^1.0.0",
"spryker/country": "^3.0.0",
"spryker/customer-extension": "^1.3.0",
"spryker/gui": "^3.39.0",
Expand Down
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;
}
}
12 changes: 12 additions & 0 deletions src/Spryker/Shared/Customer/Transfer/customer.transfer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,16 @@
<property name="customerReference" type="string"/>
<property name="withExpanders" type="bool"/>
</transfer>

<transfer name="AuthorizationRequest">
<property name="identity" type="AuthorizationIdentity"/>
<property name="entity" type="AuthorizationEntity"/>
</transfer>

<transfer name="AuthorizationIdentity">
<property name="identifier" type="string"/>
</transfer>

<transfer name="AuthorizationEntity">
</transfer>
</transfers>
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');
}
}
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
*/
}
22 changes: 22 additions & 0 deletions tests/SprykerTest/Client/Customer/codeception.yml
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

0 comments on commit 81e0509

Please sign in to comment.