summaryrefslogtreecommitdiff
path: root/libs/jsonrpc/tests/Validator/HostValidatorTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'libs/jsonrpc/tests/Validator/HostValidatorTest.php')
-rw-r--r--libs/jsonrpc/tests/Validator/HostValidatorTest.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/libs/jsonrpc/tests/Validator/HostValidatorTest.php b/libs/jsonrpc/tests/Validator/HostValidatorTest.php
new file mode 100644
index 00000000..a5fed7e0
--- /dev/null
+++ b/libs/jsonrpc/tests/Validator/HostValidatorTest.php
@@ -0,0 +1,32 @@
+<?php
+
+use JsonRPC\Validator\HostValidator;
+
+require_once __DIR__.'/../../../../vendor/autoload.php';
+
+class HostValidatorTest extends PHPUnit_Framework_TestCase
+{
+ public function testWithEmptyHosts()
+ {
+ $this->assertNull(HostValidator::validate(array(), '127.0.0.1', '127.0.0.1'));
+ }
+
+ public function testWithValidHosts()
+ {
+ $this->assertNull(HostValidator::validate(array('127.0.0.1'), '127.0.0.1', '127.0.0.1'));
+ }
+
+ public function testWithValidNetwork()
+ {
+ $this->assertNull(HostValidator::validate(array('192.168.10.1/24'), '192.168.10.1'),'test ip match');
+ $this->assertNull(HostValidator::validate(array('192.168.10.1/24'), '192.168.10.250'),'test ip match');
+ $this->setExpectedException('\JsonRPC\Exception\AccessDeniedException');
+ HostValidator::validate(array('192.168.10.1/24'), '192.168.11.1');
+ }
+
+ public function testWithNotAuthorizedHosts()
+ {
+ $this->setExpectedException('\JsonRPC\Exception\AccessDeniedException');
+ HostValidator::validate(array('192.168.1.1'), '127.0.0.1', '127.0.0.1');
+ }
+}