Skip to content

Commit

Permalink
MAG2-312 - Fixed remote address problem in Mage 2.4.7
Browse files Browse the repository at this point in the history
  • Loading branch information
FatchipRobert committed Jul 8, 2024
1 parent b2f2baa commit 18990d4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 121 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.

10 changes: 5 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\RequestInterface;
use Payone\Core\Test\Unit\BaseTestCase;
use Payone\Core\Test\Unit\PayoneObjectManager;

Expand All @@ -58,11 +58,11 @@ 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(RequestInterface::class)->disableOriginalConstructor()->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 +73,7 @@ protected function setUp(): void
$this->environment = $this->objectManager->getObject(Environment::class, [
'context' => $context,
'storeManager' => $storeManager,
'remoteAddress' => $remoteAddress
'request' => $request
]);
}

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

This file was deleted.

0 comments on commit 18990d4

Please sign in to comment.