Skip to content

Commit

Permalink
Merge pull request #412 from freezy-sk/bugfix/isThrottled
Browse files Browse the repository at this point in the history
[Bugfix] CacheLoginThrottleService->isThrottled
  • Loading branch information
Zizaco committed Sep 20, 2014
2 parents b5a55a7 + 1644f09 commit c27d251
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/vendor
composer.lock
composer.lock
8 changes: 5 additions & 3 deletions src/Confide/CacheLoginThrottleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ protected function parseIdentity($identity)
// If is an array, remove password, remember and then
// transforms it into a string.
if (is_array($identity)) {
unset($identity['password']);
unset($identity['remember']);
$identity = serialize($identity);
if (isset($identity['email'])) {
return $identity['email'];
} elseif (isset($identity['username'])) {
return $identity['username'];
}
}

return $identity;
Expand Down
10 changes: 5 additions & 5 deletions tests/Confide/CacheLoginThrottleServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public function testShouldCheckIsThrottled()
*/
$throttleService->shouldReceive('parseIdentity')
->once()->with($identity)
->andReturn(serialize(['email'=>'someone@somewhere.com']));
->andReturn('someone@somewhere.com');

$throttleService->shouldReceive('countThrottle')
->once()->with(serialize(['email'=>'someone@somewhere.com']), 0)
->once()->with('someone@somewhere.com', 0)
->andReturn(10); // More than the limit specified bellow

$config->shouldReceive('get')
Expand Down Expand Up @@ -106,10 +106,10 @@ public function testShouldCheckIsThrottledOnNonThrottled()
*/
$throttleService->shouldReceive('parseIdentity')
->once()->with($identity)
->andReturn(serialize(['email'=>'someone@somewhere.com']));
->andReturn('someone@somewhere.com');

$throttleService->shouldReceive('countThrottle')
->once()->with(serialize(['email'=>'someone@somewhere.com']), 0)
->once()->with('someone@somewhere.com', 0)
->andReturn(5); // Less than the limit specified bellow

$config->shouldReceive('get')
Expand Down Expand Up @@ -149,7 +149,7 @@ public function testShouldParseIdentity()
|------------------------------------------------------------
*/
$this->assertEquals(
serialize(['email'=>'someone@somewhere.com']),
'someone@somewhere.com',
$throttleService->parseIdentity($identity)
);
}
Expand Down

0 comments on commit c27d251

Please sign in to comment.