File size: 1,106 Bytes
e4f4821
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?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->expectException('\JsonRPC\Exception\AccessDeniedException');
        HostValidator::validate(array('192.168.10.1/24'), '192.168.11.1');
    }

    public function testWithNotAuthorizedHosts()
    {
        $this->expectException('\JsonRPC\Exception\AccessDeniedException');
        HostValidator::validate(array('192.168.1.1'), '127.0.0.1', '127.0.0.1');
    }
}