12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- declare(strict_types=1);
- namespace Test\Security\Ip;
- use OC\Security\Ip\RemoteAddress;
- use OCP\IConfig;
- use OCP\IRequest;
- class RemoteAddressTest extends \Test\TestCase {
- private IConfig $config;
- private IRequest $request;
- protected function setUp(): void {
- parent::setUp();
- $this->config = $this->createMock(IConfig::class);
- $this->request = $this->createMock(IRequest::class);
- }
-
- public function testAllowedIps(string $remoteIp, $allowedRanges, bool $expected): void {
- $this->request
- ->method('getRemoteAddress')
- ->willReturn($remoteIp);
- $this->config
- ->method('getSystemValue')
- ->with('allowed_admin_ranges', false)
- ->willReturn($allowedRanges);
- $remoteAddress = new RemoteAddress($this->config, $this->request);
- $this->assertEquals($expected, $remoteAddress->allowsAdminActions());
- }
-
- public function dataProvider(): array {
- return [
-
- ['', ['192.168.1.2/24'], true],
- ['', ['fe80/8'], true],
-
- ['1.2.3.4', false, true],
- ['1234:4567:8910::', false, true],
-
- ['fe80::1fc4:15d8:78db:2319%enp4s0', false, true],
-
- ['1.2.3.4', [], true],
- ['1234:4567:8910::', [], true],
-
- ['1.2.3.4', 'hello', true],
- ['1234:4567:8910::', 'world', true],
-
- ['192.168.1.5', ['1.2.3.*', '1234::/8'], false],
- ['::1', ['127.0.0.1', '1234::/8'], false],
- ['192.168.1.5', ['192.168.1.0/24', '1234::/8'], true],
-
- ['1.2.3.4', ['1.2.3.*'], true],
- ['fc00:1:2:3::1', ['fc00::/7'], true],
- ['1.2.3.4', ['192.168.1.2/24', '1.2.3.0/24'], true],
- ['1234:4567:8910::1', ['fe80::/8','1234:4567::/16'], true],
-
- ['192.168.1.5', ['1.2.3.*'], false],
- ['9234:4567:8910::', ['1234:4567::1'], false],
- ['192.168.2.1', ['192.168.1.2/24', '1.2.3.0/24'], false],
- ['9234:4567:8910::', ['fe80::/8','1234:4567::/16'], false],
- ];
- }
- }
|