From a491348d442ab8e6cd2fa403d4365cdad78e52ce Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 21 Jun 2018 14:13:41 -0700 Subject: Vendoring deprecated composer libs --- libs/jsonrpc/tests/Validator/HostValidatorTest.php | 32 +++++++++++++++ .../tests/Validator/JsonEncodingValidatorTest.php | 22 ++++++++++ .../tests/Validator/JsonFormatValidatorTest.php | 19 +++++++++ .../tests/Validator/RpcFormatValidatorTest.php | 48 ++++++++++++++++++++++ libs/jsonrpc/tests/Validator/UserValidatorTest.php | 24 +++++++++++ 5 files changed, 145 insertions(+) create mode 100644 libs/jsonrpc/tests/Validator/HostValidatorTest.php create mode 100644 libs/jsonrpc/tests/Validator/JsonEncodingValidatorTest.php create mode 100644 libs/jsonrpc/tests/Validator/JsonFormatValidatorTest.php create mode 100644 libs/jsonrpc/tests/Validator/RpcFormatValidatorTest.php create mode 100644 libs/jsonrpc/tests/Validator/UserValidatorTest.php (limited to 'libs/jsonrpc/tests/Validator') 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 @@ +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'); + } +} diff --git a/libs/jsonrpc/tests/Validator/JsonEncodingValidatorTest.php b/libs/jsonrpc/tests/Validator/JsonEncodingValidatorTest.php new file mode 100644 index 00000000..a1b2b80e --- /dev/null +++ b/libs/jsonrpc/tests/Validator/JsonEncodingValidatorTest.php @@ -0,0 +1,22 @@ +assertNull(JsonEncodingValidator::validate()); + } + + public function testWithJsonError() + { + json_encode("\xB1\x31"); + + $this->setExpectedException('\JsonRPC\Exception\ResponseEncodingFailureException'); + JsonEncodingValidator::validate(); + } +} diff --git a/libs/jsonrpc/tests/Validator/JsonFormatValidatorTest.php b/libs/jsonrpc/tests/Validator/JsonFormatValidatorTest.php new file mode 100644 index 00000000..a838ada9 --- /dev/null +++ b/libs/jsonrpc/tests/Validator/JsonFormatValidatorTest.php @@ -0,0 +1,19 @@ +assertNull(JsonFormatValidator::validate(array('foobar'))); + } + + public function testJsonNotParsedCorrectly() + { + $this->setExpectedException('\JsonRPC\Exception\InvalidJsonFormatException'); + JsonFormatValidator::validate(''); + } +} diff --git a/libs/jsonrpc/tests/Validator/RpcFormatValidatorTest.php b/libs/jsonrpc/tests/Validator/RpcFormatValidatorTest.php new file mode 100644 index 00000000..3e6ba8bc --- /dev/null +++ b/libs/jsonrpc/tests/Validator/RpcFormatValidatorTest.php @@ -0,0 +1,48 @@ +assertNull(RpcFormatValidator::validate(array('jsonrpc' => '2.0', 'method' => 'foobar'))); + } + + public function testWithNoVersion() + { + $this->setExpectedException('\JsonRPC\Exception\InvalidJsonRpcFormatException'); + RpcFormatValidator::validate(array('method' => 'foobar')); + } + + public function testWithNoMethod() + { + $this->setExpectedException('\JsonRPC\Exception\InvalidJsonRpcFormatException'); + RpcFormatValidator::validate(array('jsonrpc' => '2.0')); + } + + public function testWithMethodNotString() + { + $this->setExpectedException('\JsonRPC\Exception\InvalidJsonRpcFormatException'); + RpcFormatValidator::validate(array('jsonrpc' => '2.0', 'method' => array())); + } + + public function testWithBadVersion() + { + $this->setExpectedException('\JsonRPC\Exception\InvalidJsonRpcFormatException'); + RpcFormatValidator::validate(array('jsonrpc' => '1.0', 'method' => 'abc')); + } + + public function testWithBadParams() + { + $this->setExpectedException('\JsonRPC\Exception\InvalidJsonRpcFormatException'); + RpcFormatValidator::validate(array('jsonrpc' => '2.0', 'method' => 'abc', 'params' => 'foobar')); + } + + public function testWithParams() + { + $this->assertNull(RpcFormatValidator::validate(array('jsonrpc' => '2.0', 'method' => 'abc', 'params' => array(1, 2)))); + } +} diff --git a/libs/jsonrpc/tests/Validator/UserValidatorTest.php b/libs/jsonrpc/tests/Validator/UserValidatorTest.php new file mode 100644 index 00000000..e514c105 --- /dev/null +++ b/libs/jsonrpc/tests/Validator/UserValidatorTest.php @@ -0,0 +1,24 @@ +assertNull(UserValidator::validate(array(), 'user', 'pass')); + } + + public function testWithValidHosts() + { + $this->assertNull(UserValidator::validate(array('user' => 'pass'), 'user', 'pass')); + } + + public function testWithNotAuthorizedHosts() + { + $this->setExpectedException('\JsonRPC\Exception\AuthenticationFailureException'); + UserValidator::validate(array('user' => 'pass'), 'user', 'wrong password'); + } +} -- cgit v1.2.3