diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2017-04-04 11:57:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-04 11:57:43 +0200 |
commit | e0227cb4588a343db9eadfefc2733660877fb60d (patch) | |
tree | f5407b1201cbd2b23e230b6e16e6d4c74ae1cfc7 /tests | |
parent | da178db98edf54088cb94391088a53257f682b5d (diff) | |
parent | aee2d6318fef503528c94947596bafeb43594ed3 (diff) | |
download | nextcloud-server-e0227cb4588a343db9eadfefc2733660877fb60d.tar.gz nextcloud-server-e0227cb4588a343db9eadfefc2733660877fb60d.zip |
Merge pull request #2095 from nextcloud/bruteforcesetttings
Introduce bruteforce settings
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Security/Bruteforce/ThrottlerTest.php | 90 | ||||
-rw-r--r-- | tests/lib/Settings/ManagerTest.php | 6 |
2 files changed, 93 insertions, 3 deletions
diff --git a/tests/lib/Security/Bruteforce/ThrottlerTest.php b/tests/lib/Security/Bruteforce/ThrottlerTest.php index 604aecd3a65..02d5b701679 100644 --- a/tests/lib/Security/Bruteforce/ThrottlerTest.php +++ b/tests/lib/Security/Bruteforce/ThrottlerTest.php @@ -40,7 +40,7 @@ class ThrottlerTest extends TestCase { private $dbConnection; /** @var ILogger */ private $logger; - /** @var IConfig */ + /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ private $config; public function setUp() { @@ -120,4 +120,92 @@ class ThrottlerTest extends TestCase { $this->invokePrivate($this->throttler, 'getIPv6Subnet', ['2001:0db8:85a3:0000:0000:8a2e:0370:7334', 40]) ); } + + public function dataIsIPWhitelisted() { + return [ + [ + '10.10.10.10', + [ + 'whitelist_0' => '10.10.10.0/24', + ], + true, + ], + [ + '10.10.10.10', + [ + 'whitelist_0' => '192.168.0.0/16', + ], + false, + ], + [ + '10.10.10.10', + [ + 'whitelist_0' => '192.168.0.0/16', + 'whitelist_1' => '10.10.10.0/24', + ], + true, + ], + [ + 'dead:beef:cafe::1', + [ + 'whitelist_0' => '192.168.0.0/16', + 'whitelist_1' => '10.10.10.0/24', + 'whitelist_2' => 'deaf:beef:cafe:1234::/64' + ], + false, + ], + [ + 'dead:beef:cafe::1', + [ + 'whitelist_0' => '192.168.0.0/16', + 'whitelist_1' => '10.10.10.0/24', + 'whitelist_2' => 'deaf:beef::/64' + ], + false, + ], + [ + 'dead:beef:cafe::1', + [ + 'whitelist_0' => '192.168.0.0/16', + 'whitelist_1' => '10.10.10.0/24', + 'whitelist_2' => 'deaf:cafe::/8' + ], + true, + ], + [ + 'invalid', + [], + false, + ], + ]; + } + + /** + * @dataProvider dataIsIPWhitelisted + * + * @param string $ip + * @param string[] $whitelists + * @param bool $isWhiteListed + */ + public function testIsIPWhitelisted($ip, $whitelists, $isWhiteListed) { + $this->config->method('getAppKeys') + ->with($this->equalTo('bruteForce')) + ->willReturn(array_keys($whitelists)); + + $this->config->method('getAppValue') + ->will($this->returnCallback(function($app, $key, $default) use ($whitelists) { + if ($app !== 'bruteForce') { + return $default; + } + if (isset($whitelists[$key])) { + return $whitelists[$key]; + } + return $default; + })); + + $this->assertSame( + $isWhiteListed, + $this->invokePrivate($this->throttler, 'isIPWhitelisted', [$ip]) + ); + } } diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php index 2122c8b3750..497a0df9f4e 100644 --- a/tests/lib/Settings/ManagerTest.php +++ b/tests/lib/Settings/ManagerTest.php @@ -146,7 +146,7 @@ class ManagerTest extends TestCase { ['class' => \OCA\WorkflowEngine\Settings\Section::class, 'priority' => 90] ])); - $this->url->expects($this->exactly(5)) + $this->url->expects($this->exactly(6)) ->method('imagePath') ->willReturnMap([ ['settings', 'admin.svg', '1'], @@ -159,6 +159,7 @@ class ManagerTest extends TestCase { $this->assertEquals([ 0 => [new Section('server', 'Server settings', 0, '1')], 5 => [new Section('sharing', 'Sharing', 0, '2')], + 10 => [new Section('security', 'Security', 0, '3')], 45 => [new Section('encryption', 'Encryption', 0, '3')], 90 => [\OC::$server->query(\OCA\WorkflowEngine\Settings\Section::class)], 98 => [new Section('additional', 'Additional settings', 0, '4')], @@ -177,7 +178,7 @@ class ManagerTest extends TestCase { ->will($this->returnValue([ ])); - $this->url->expects($this->exactly(5)) + $this->url->expects($this->exactly(6)) ->method('imagePath') ->willReturnMap([ ['settings', 'admin.svg', '1'], @@ -190,6 +191,7 @@ class ManagerTest extends TestCase { $this->assertEquals([ 0 => [new Section('server', 'Server settings', 0, '1')], 5 => [new Section('sharing', 'Sharing', 0, '2')], + 10 => [new Section('security', 'Security', 0, '3')], 45 => [new Section('encryption', 'Encryption', 0, '3')], 98 => [new Section('additional', 'Additional settings', 0, '4')], 99 => [new Section('tips-tricks', 'Tips & tricks', 0, '5')], |