-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7340 from magento-cia/2.4-bugfixes-121621
Bugfixes
- Loading branch information
Showing
50 changed files
with
1,588 additions
and
305 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
app/code/Magento/Analytics/Plugin/BearerTokenValidatorPlugin.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,49 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Analytics\Plugin; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Integration\Model\Integration; | ||
use Magento\Integration\Model\Validator\BearerTokenValidator; | ||
|
||
/** | ||
* Overrides authorization config to always allow analytics token to be used as bearer | ||
*/ | ||
class BearerTokenValidatorPlugin | ||
{ | ||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private ScopeConfigInterface $config; | ||
|
||
/** | ||
* @param ScopeConfigInterface $config | ||
*/ | ||
public function __construct(ScopeConfigInterface $config) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
/*** | ||
* Always allow access token for analytics to be used as bearer | ||
* | ||
* @param BearerTokenValidator $subject | ||
* @param bool $result | ||
* @param Integration $integration | ||
* @return bool | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterIsIntegrationAllowedAsBearerToken( | ||
BearerTokenValidator $subject, | ||
bool $result, | ||
Integration $integration | ||
): bool { | ||
return $result || $integration->getName() === $this->config->getValue('analytics/integration_name'); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
app/code/Magento/Analytics/Test/Unit/Plugin/BearerTokenValidatorPluginTest.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,72 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Analytics\Test\Unit\Plugin; | ||
|
||
use Magento\Analytics\Plugin\BearerTokenValidatorPlugin; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Integration\Model\Integration; | ||
use Magento\Integration\Model\Validator\BearerTokenValidator; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class BearerTokenValidatorPluginTest extends TestCase | ||
{ | ||
/** | ||
* @var BearerTokenValidatorPlugin | ||
*/ | ||
private BearerTokenValidatorPlugin $plugin; | ||
|
||
/** | ||
* @var BearerTokenValidator|MockObject | ||
*/ | ||
private $validator; | ||
|
||
public function setUp(): void | ||
{ | ||
$config = $this->createMock(ScopeConfigInterface::class); | ||
$config->method('getValue') | ||
->with('analytics/integration_name') | ||
->willReturn('abc'); | ||
$this->plugin = new BearerTokenValidatorPlugin($config); | ||
$this->validator = $this->createMock(BearerTokenValidator::class); | ||
} | ||
|
||
public function testTrueIsPassedThrough() | ||
{ | ||
$integration = $this->createMock(Integration::class); | ||
$integration->method('__call') | ||
->with('getName') | ||
->willReturn('invalid'); | ||
|
||
$result = $this->plugin->afterIsIntegrationAllowedAsBearerToken($this->validator, true, $integration); | ||
self::assertTrue($result); | ||
} | ||
|
||
public function testFalseWhenIntegrationDoesntMatch() | ||
{ | ||
$integration = $this->createMock(Integration::class); | ||
$integration->method('__call') | ||
->with('getName') | ||
->willReturn('invalid'); | ||
|
||
$result = $this->plugin->afterIsIntegrationAllowedAsBearerToken($this->validator, false, $integration); | ||
self::assertFalse($result); | ||
} | ||
|
||
public function testTrueWhenIntegrationMatches() | ||
{ | ||
$integration = $this->createMock(Integration::class); | ||
$integration->method('__call') | ||
->with('getName') | ||
->willReturn('abc'); | ||
|
||
$result = $this->plugin->afterIsIntegrationAllowedAsBearerToken($this->validator, true, $integration); | ||
self::assertTrue($result); | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
app/code/Magento/Integration/Model/CompositeTokenReader.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,48 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Integration\Model; | ||
|
||
use Magento\Integration\Api\Data\UserToken; | ||
use Magento\Integration\Api\Exception\UserTokenException; | ||
use Magento\Integration\Api\UserTokenReaderInterface; | ||
|
||
/** | ||
* Checks multiple sources for reading a token | ||
*/ | ||
class CompositeTokenReader implements UserTokenReaderInterface | ||
{ | ||
/** | ||
* @var UserTokenReaderInterface[] | ||
*/ | ||
private $readers; | ||
|
||
/** | ||
* @param UserTokenReaderInterface[] $readers | ||
*/ | ||
public function __construct(array $readers) | ||
{ | ||
$this->readers = $readers; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function read(string $token): UserToken | ||
{ | ||
foreach ($this->readers as $reader) { | ||
try { | ||
return $reader->read($token); | ||
} catch (UserTokenException $exception) { | ||
continue; | ||
} | ||
} | ||
|
||
throw new UserTokenException('Composite reader could not read a token'); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
app/code/Magento/Integration/Model/Config/AuthorizationConfig.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,49 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Integration\Model\Config; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
/** | ||
* Represents configuration related to WebAPI Authorization | ||
*/ | ||
class AuthorizationConfig | ||
{ | ||
/** | ||
* XML Path for Enable Integration as Bearer | ||
*/ | ||
private const CONFIG_PATH_INTEGRATION_BEARER = 'oauth/consumer/enable_integration_as_bearer'; | ||
|
||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private ScopeConfigInterface $scopeConfig; | ||
|
||
/** | ||
* @param ScopeConfigInterface $scopeConfig | ||
*/ | ||
public function __construct(ScopeConfigInterface $scopeConfig) | ||
{ | ||
$this->scopeConfig = $scopeConfig; | ||
} | ||
|
||
/** | ||
* Return if integration access tokens can be used as bearer tokens | ||
* | ||
* @return bool | ||
*/ | ||
public function isIntegrationAsBearerEnabled(): bool | ||
{ | ||
return $this->scopeConfig->isSetFlag( | ||
self::CONFIG_PATH_INTEGRATION_BEARER, | ||
ScopeInterface::SCOPE_STORE | ||
); | ||
} | ||
} |
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
Oops, something went wrong.