Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-07-28 15:16:01 +0300
committerJoas Schilling <coding@schilljs.com>2016-08-01 18:19:05 +0300
commit2cfd67e13b6f5f9e37f0dbd7988aad6a23be45c5 (patch)
tree07ac1d547a0ee03667d0df939a7b95aac673ebeb /apps/workflowengine/tests/Check
parent1091cbb7786c0826b8e8aca65512347b199235ca (diff)
Add remote address
Diffstat (limited to 'apps/workflowengine/tests/Check')
-rw-r--r--apps/workflowengine/tests/Check/RequestRemoteAddressTest.php123
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));
+ }
+}