Skip to content
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
4 changes: 4 additions & 0 deletions lib/private/Security/Bruteforce/Throttler.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ private function isIPWhitelisted(string $ip): bool {
* @return int
*/
public function getAttempts(string $ip, string $action = '', float $maxAgeHours = 12): int {
if ($ip === '') {
return 0;
}

$ipAddress = new IpAddress($ip);
if ($this->isIPWhitelisted((string)$ipAddress)) {
return 0;
Expand Down
24 changes: 22 additions & 2 deletions tests/lib/Security/Bruteforce/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ protected function setUp(): void {
parent::setUp();

$this->request = $this->createMock(IRequest::class);
$this->request->method('getRemoteAddress')
->willReturn('10.10.10.10');

$this->throttler = $this->createMock(Throttler::class);

Expand All @@ -57,6 +55,9 @@ public function testGetCapabilities() {
->with('10.10.10.10')
->willReturn(42);

$this->request->method('getRemoteAddress')
->willReturn('10.10.10.10');

$expected = [
'bruteforce' => [
'delay' => 42
Expand All @@ -66,4 +67,23 @@ public function testGetCapabilities() {

$this->assertEquals($expected, $result);
}

public function testGetCapabilitiesOnCli() {
$this->throttler->expects($this->atLeastOnce())
->method('getDelay')
->with('')
->willReturn(0);

$this->request->method('getRemoteAddress')
->willReturn('');

$expected = [
'bruteforce' => [
'delay' => 0
]
];
$result = $this->capabilities->getCapabilities();

$this->assertEquals($expected, $result);
}
}