add new IPTools class; add new callback to show link to domain in domain-overview; validate possible allowed_ip-ranges in FroxlorRPC; fix possible duplicate ips for mysql-access-host in installation

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-04-22 10:36:46 +02:00
parent d3ae4c5d72
commit b869c84f4d
11 changed files with 267 additions and 64 deletions

View File

@@ -0,0 +1,40 @@
<?php
use PHPUnit\Framework\TestCase;
use Froxlor\System\IPTools;
/**
*
* @covers \Froxlor\System\IPTools
*/
class IPToolsTest extends TestCase
{
public function testValidateIPv6()
{
$result = IPTools::is_ipv6('1.1.1.1/4');
$this->assertFalse($result);
$result = IPTools::is_ipv6('1.1.1.1');
$this->assertFalse($result);
$result = IPTools::is_ipv6('::ffff:10.20.30.40');
$this->assertEquals('::ffff:10.20.30.40', $result);
$result = IPTools::is_ipv6('2620:0:2d0:200::7/32');
$this->assertFalse($result);
$result = IPTools::is_ipv6('2620:0:2d0:200::7');
$this->assertEquals('2620:0:2d0:200::7', $result);
}
public function testValidateIPinRange()
{
$result = IPTools::ip_in_range([0=>'82.149.225.46',1=>24], '123.213.132.1');
$this->assertFalse($result);
$result = IPTools::ip_in_range([0=>'82.149.225.46',1=>24], '2620:0:2d0:200::7');
$this->assertFalse($result);
$result = IPTools::ip_in_range([0=>'82.149.225.46',1=>24], '82.149.225.152');
$this->assertTrue($result);
$result = IPTools::ip_in_range([0=>'2620:0:2d0:200::1',1=>116], '2620:0:2d0:200::fff1');
$this->assertFalse($result);
$result = IPTools::ip_in_range([0=>'2620:0:2d0:200::1',1=>64], '2620:0:2d0:200::fff1');
$this->assertTrue($result);
}
}

View File

@@ -109,20 +109,6 @@ class ValidateTest extends TestCase
$this->assertEquals("8.8.8.8/128.0.0.0", $result);
}
public function testValidateIPv6()
{
$result = Validate::is_ipv6('1.1.1.1/4');
$this->assertFalse($result);
$result = Validate::is_ipv6('1.1.1.1');
$this->assertFalse($result);
$result = Validate::is_ipv6('::ffff:10.20.30.40');
$this->assertEquals('::ffff:10.20.30.40', $result);
$result = Validate::is_ipv6('2620:0:2d0:200::7/32');
$this->assertFalse($result);
$result = Validate::is_ipv6('2620:0:2d0:200::7');
$this->assertEquals('2620:0:2d0:200::7', $result);
}
public function testValidateIpLocalhostAllowedWrongIp()
{
$this->expectException("Exception");