Skip to content

Commit

Permalink
Merge pull request PAYONE-GmbH#545 from FatchipRobert/MAG2-312-247-pr…
Browse files Browse the repository at this point in the history
…oblem

MAG2-312 - Fixed remote address problem in Mage 2.4.7
  • Loading branch information
janteuber authored Jul 8, 2024
2 parents b2f2baa + 678a345 commit 29bd580
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 122 deletions.
17 changes: 6 additions & 11 deletions Helper/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@
class Environment extends \Payone\Core\Helper\Base
{
/**
* Extended remote address object
*
* @var \Payone\Core\Model\Environment\RemoteAddress
* @var \Magento\Framework\App\RequestInterface
*/
protected $remoteAddress;
protected $request;

/**
* Constructor
Expand All @@ -45,17 +43,17 @@ class Environment extends \Payone\Core\Helper\Base
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Payone\Core\Helper\Shop $shopHelper
* @param \Magento\Framework\App\State $state
* @param \Payone\Core\Model\Environment\RemoteAddress $remoteAddress
* @param \Magento\Framework\App\RequestInterface $request
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Payone\Core\Helper\Shop $shopHelper,
\Magento\Framework\App\State $state,
\Payone\Core\Model\Environment\RemoteAddress $remoteAddress
\Magento\Framework\App\RequestInterface $request
) {
parent::__construct($context, $storeManager, $shopHelper, $state);
$this->remoteAddress = $remoteAddress;
$this->request = $request;
}

/**
Expand All @@ -76,10 +74,7 @@ public function getEncoding()
public function getRemoteIp()
{
$blProxyMode = (bool)$this->getConfigParam('proxy_mode', 'processing', 'payone_misc');
if ($blProxyMode === true) {
$this->remoteAddress->useHttpXForwarded();
}
return $this->remoteAddress->getRemoteAddress();
return $this->request->getClientIp($blProxyMode);
}

/**
Expand Down
47 changes: 0 additions & 47 deletions Model/Environment/RemoteAddress.php

This file was deleted.

15 changes: 10 additions & 5 deletions Test/Unit/Helper/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
use Magento\Framework\App\Helper\Context;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Payone\Core\Model\Environment\RemoteAddress;
use Magento\Framework\App\Request\Http;
use Payone\Core\Test\Unit\BaseTestCase;
use Payone\Core\Test\Unit\PayoneObjectManager;

Expand All @@ -58,11 +58,16 @@ protected function setUp(): void
{
$this->objectManager = $this->getObjectManager();

$remoteAddress = $this->getMockBuilder(RemoteAddress::class)->disableOriginalConstructor()->getMock();
$remoteAddress->method('getRemoteAddress')->willReturn('192.168.1.100');
$request = $this->getMockBuilder(Http::class)
->disableOriginalConstructor()
->setMethods([
'getClientIp'
])
->getMock();
$request->method('getClientIp')->willReturn('192.168.1.100');

$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)->disableOriginalConstructor()->getMock();
$context = $this->objectManager->getObject(Context::class, ['scopeConfig' => $this->scopeConfig, 'remoteAddress' => $remoteAddress]);
$context = $this->objectManager->getObject(Context::class, ['scopeConfig' => $this->scopeConfig]);

$store = $this->getMockBuilder(StoreInterface::class)->disableOriginalConstructor()->getMock();
$store->method('getCode')->willReturn(null);
Expand All @@ -73,7 +78,7 @@ protected function setUp(): void
$this->environment = $this->objectManager->getObject(Environment::class, [
'context' => $context,
'storeManager' => $storeManager,
'remoteAddress' => $remoteAddress
'request' => $request
]);
}

Expand Down
2 changes: 1 addition & 1 deletion Test/Unit/Helper/ToolkitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function testIsKeyValid()
]
);

$hash = $this->toolkit->hashString($key);
$hash = $this->toolkit->hashString($key, 'md5');
$result = $this->toolkit->isKeyValid($hash);
$this->assertTrue($result);

Expand Down
58 changes: 0 additions & 58 deletions Test/Unit/Model/Environment/RemoteAddressTest.php

This file was deleted.

0 comments on commit 29bd580

Please sign in to comment.