Skip to content

Commit

Permalink
Fix magento#30296 - fix retrieving send count by ip, add verification…
Browse files Browse the repository at this point in the history
… of ip conversion into int to integration test
  • Loading branch information
Bartlomiejsz committed Oct 7, 2020
1 parent ccc83b2 commit bc53649
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getSendCount($object, $ip, $startTime, $websiteId = null)
AND time>=:time
AND website_id=:website_id'
);
$bind = ['ip' => ip2long($ip), 'time' => $startTime, 'website_id' => (int)$websiteId];
$bind = ['ip' => $ip, 'time' => $startTime, 'website_id' => (int)$websiteId];

$row = $connection->fetchRow($select, $bind);
return $row['count'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class SendFriendTest extends TestCase
/** @var SendFriend */
private $sendFriend;

/** @var ResourceModel\SendFriend */
private $sendFriendResource;

/** @var CookieManagerInterface */
private $cookieManager;

Expand All @@ -43,6 +46,7 @@ protected function setUp(): void

$this->objectManager = Bootstrap::getObjectManager();
$this->sendFriend = $this->objectManager->get(SendFriendFactory::class)->create();
$this->sendFriendResource = $this->objectManager->get(ResourceModel\SendFriend::class);
$this->cookieManager = $this->objectManager->get(CookieManagerInterface::class);
$this->request = $this->objectManager->get(RequestInterface::class);
}
Expand Down Expand Up @@ -191,10 +195,21 @@ public function testisExceedLimitByCookies(): void
*/
public function testisExceedLimitByIp(): void
{
$remoteAddr = '127.0.0.1';
$parameters = $this->objectManager->create(Parameters::class);
$parameters->set('REMOTE_ADDR', '127.0.0.1');
$parameters->set('REMOTE_ADDR', $remoteAddr);
$this->request->setServer($parameters);
$this->assertTrue($this->sendFriend->isExceedLimit());
// Verify that ip is saved correctly as integer value
$this->assertEquals(
1,
(int)$this->sendFriendResource->getSendCount(
null,
ip2long($remoteAddr),
time() - (60 * 60 * 24 * 365),
1
)
);
}

/**
Expand Down

0 comments on commit bc53649

Please sign in to comment.