Merge pull request #22774 from nextcloud/bugfix/noid/no-delay-without-ip

Don't break when the IP is empty
This commit is contained in:
Morris Jobke 2020-09-10 16:11:06 +02:00 committed by GitHub
commit 3d61f7b258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -227,6 +227,10 @@ class Throttler {
* @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;

View File

@ -40,8 +40,6 @@ class CapabilitiesTest extends TestCase {
parent::setUp();
$this->request = $this->createMock(IRequest::class);
$this->request->method('getRemoteAddress')
->willReturn('10.10.10.10');
$this->throttler = $this->createMock(Throttler::class);
@ -57,6 +55,9 @@ class CapabilitiesTest extends TestCase {
->with('10.10.10.10')
->willReturn(42);
$this->request->method('getRemoteAddress')
->willReturn('10.10.10.10');
$expected = [
'bruteforce' => [
'delay' => 42
@ -66,4 +67,23 @@ class CapabilitiesTest extends TestCase {
$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);
}
}