diff options
author | Joas Schilling <coding@schilljs.com> | 2016-07-28 14:16:01 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-08-01 17:19:05 +0200 |
commit | 2cfd67e13b6f5f9e37f0dbd7988aad6a23be45c5 (patch) | |
tree | 07ac1d547a0ee03667d0df939a7b95aac673ebeb /apps/workflowengine/tests | |
parent | 1091cbb7786c0826b8e8aca65512347b199235ca (diff) | |
download | nextcloud-server-2cfd67e13b6f5f9e37f0dbd7988aad6a23be45c5.tar.gz nextcloud-server-2cfd67e13b6f5f9e37f0dbd7988aad6a23be45c5.zip |
Add remote address
Diffstat (limited to 'apps/workflowengine/tests')
-rw-r--r-- | apps/workflowengine/tests/Check/RequestRemoteAddressTest.php | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php b/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php new file mode 100644 index 00000000000..ec8798794df --- /dev/null +++ b/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php @@ -0,0 +1,123 @@ +<?php +/** + * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\WorkflowEngine\Tests\Check; + + +class RequestRemoteAddressTest extends \Test\TestCase { + + /** @var \OCP\IRequest|\PHPUnit_Framework_MockObject_MockObject */ + protected $request; + + protected function setUp() { + parent::setUp(); + + $this->request = $this->getMockBuilder('OCP\IRequest') + ->getMock(); + } + + public function dataExecuteCheckIPv4() { + return [ + ['127.0.0.1/32', '127.0.0.1', true], + ['127.0.0.1/32', '127.0.0.0', false], + ['127.0.0.1/31', '127.0.0.0', true], + ['127.0.0.1/32', '127.0.0.2', false], + ['127.0.0.1/31', '127.0.0.2', false], + ['127.0.0.1/30', '127.0.0.2', true], + ]; + } + + /** + * @dataProvider dataExecuteCheckIPv4 + * @param string $value + * @param string $ip + * @param bool $expected + */ + public function testExecuteCheckMatchesIPv4($value, $ip, $expected) { + $check = new \OCA\WorkflowEngine\Check\RequestRemoteAddress($this->request); + + $this->request->expects($this->once()) + ->method('getRemoteAddress') + ->willReturn($ip); + + $this->assertEquals($expected, $check->executeCheck('matchesIPv4', $value)); + } + + /** + * @dataProvider dataExecuteCheckIPv4 + * @param string $value + * @param string $ip + * @param bool $expected + */ + public function testExecuteCheckNotMatchesIPv4($value, $ip, $expected) { + $check = new \OCA\WorkflowEngine\Check\RequestRemoteAddress($this->request); + + $this->request->expects($this->once()) + ->method('getRemoteAddress') + ->willReturn($ip); + + $this->assertEquals(!$expected, $check->executeCheck('!matchesIPv4', $value)); + } + + public function dataExecuteCheckIPv6() { + return [ + ['::1/128', '::1', true], + ['::2/128', '::3', false], + ['::2/127', '::3', true], + ['::1/128', '::2', false], + ['::1/127', '::2', false], + ['::1/126', '::2', true], + ['1234::1/127', '1234::', true], + ]; + } + + /** + * @dataProvider dataExecuteCheckIPv6 + * @param string $value + * @param string $ip + * @param bool $expected + */ + public function testExecuteCheckMatchesIPv6($value, $ip, $expected) { + $check = new \OCA\WorkflowEngine\Check\RequestRemoteAddress($this->request); + + $this->request->expects($this->once()) + ->method('getRemoteAddress') + ->willReturn($ip); + + $this->assertEquals($expected, $check->executeCheck('matchesIPv6', $value)); + } + + /** + * @dataProvider dataExecuteCheckIPv6 + * @param string $value + * @param string $ip + * @param bool $expected + */ + public function testExecuteCheckNotMatchesIPv6($value, $ip, $expected) { + $check = new \OCA\WorkflowEngine\Check\RequestRemoteAddress($this->request); + + $this->request->expects($this->once()) + ->method('getRemoteAddress') + ->willReturn($ip); + + $this->assertEquals(!$expected, $check->executeCheck('!matchesIPv6', $value)); + } +} |