Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAG2-312 - Fixed remote address problem in Mage 2.4.7 #545

Merged
merged 4 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading