Remove legacy function calls (#12651)

* massive inlines

* fix style and wtf

* remove rrdtool.inc.php include

* fix CommonFunctions namespace issues

* looking for missing class space, fix undefined class issues

* style fixes
This commit is contained in:
Tony Murray
2021-03-28 17:25:30 -05:00
committed by GitHub
parent 1695f86af8
commit 1c379dcd05
832 changed files with 2023 additions and 2596 deletions

View File

@@ -26,6 +26,8 @@ namespace LibreNMS\Tests;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Util\Clean;
use LibreNMS\Util\Validate;
class CommonFunctionsTest extends TestCase
{
@@ -71,7 +73,7 @@ class CommonFunctionsTest extends TestCase
public function testRrdDescriptions()
{
$data = 'Toner, S/N:CR_UM-16021314488.';
$this->assertEquals('Toner, S/N CR_UM-16021314488.', safedescr($data));
$this->assertEquals('Toner, S/N CR_UM-16021314488.', \LibreNMS\Data\Store\Rrd::safeDescr($data));
}
public function testSetNull()
@@ -87,8 +89,8 @@ class CommonFunctionsTest extends TestCase
public function testDisplay()
{
$this->assertEquals('&lt;html&gt;string&lt;/html&gt;', display('<html>string</html>'));
$this->assertEquals('&lt;script&gt;alert("test")&lt;/script&gt;', display('<script>alert("test")</script>'));
$this->assertEquals('&lt;html&gt;string&lt;/html&gt;', Clean::html('<html>string</html>', []));
$this->assertEquals('&lt;script&gt;alert("test")&lt;/script&gt;', Clean::html('<script>alert("test")</script>', []));
$tmp_config = [
'HTML.Allowed' => 'b,iframe,i,ul,li,h1,h2,h3,h4,br,p',
@@ -96,8 +98,8 @@ class CommonFunctionsTest extends TestCase
'HTML.SafeIframe' => true,
];
$this->assertEquals('<b>Bold</b>', display('<b>Bold</b>', $tmp_config));
$this->assertEquals('', display('<script>alert("test")</script>', $tmp_config));
$this->assertEquals('<b>Bold</b>', Clean::html('<b>Bold</b>', $tmp_config));
$this->assertEquals('', Clean::html('<script>alert("test")</script>', $tmp_config));
}
public function testStringToClass()
@@ -111,31 +113,31 @@ class CommonFunctionsTest extends TestCase
public function testIsValidHostname()
{
$this->assertTrue(is_valid_hostname('a'), 'a');
$this->assertTrue(is_valid_hostname('a.'), 'a.');
$this->assertTrue(is_valid_hostname('0'), '0');
$this->assertTrue(is_valid_hostname('a.b'), 'a.b');
$this->assertTrue(is_valid_hostname('localhost'), 'localhost');
$this->assertTrue(is_valid_hostname('google.com'), 'google.com');
$this->assertTrue(is_valid_hostname('news.google.co.uk'), 'news.google.co.uk');
$this->assertTrue(is_valid_hostname('xn--fsqu00a.xn--0zwm56d'), 'xn--fsqu00a.xn--0zwm56d');
$this->assertTrue(is_valid_hostname('www.averylargedomainthatdoesnotreallyexist.com'), 'www.averylargedomainthatdoesnotreallyexist.com');
$this->assertTrue(is_valid_hostname('cont-ains.h-yph-en-s.com'), 'cont-ains.h-yph-en-s.com');
$this->assertTrue(is_valid_hostname('cisco-3750x'), 'cisco-3750x');
$this->assertFalse(is_valid_hostname('cisco_3750x'), 'cisco_3750x');
$this->assertFalse(is_valid_hostname('goo gle.com'), 'goo gle.com');
$this->assertFalse(is_valid_hostname('google..com'), 'google..com');
$this->assertFalse(is_valid_hostname('google.com '), 'google.com ');
$this->assertFalse(is_valid_hostname('google-.com'), 'google-.com');
$this->assertFalse(is_valid_hostname('.google.com'), '.google.com');
$this->assertFalse(is_valid_hostname('..google.com'), '..google.com');
$this->assertFalse(is_valid_hostname('<script'), '<script');
$this->assertFalse(is_valid_hostname('alert('), 'alert(');
$this->assertFalse(is_valid_hostname('.'), '.');
$this->assertFalse(is_valid_hostname('..'), '..');
$this->assertFalse(is_valid_hostname(' '), 'Just a space');
$this->assertFalse(is_valid_hostname('-'), '-');
$this->assertFalse(is_valid_hostname(''), 'Empty string');
$this->assertTrue(Validate::hostname('a'), 'a');
$this->assertTrue(Validate::hostname('a.'), 'a.');
$this->assertTrue(Validate::hostname('0'), '0');
$this->assertTrue(Validate::hostname('a.b'), 'a.b');
$this->assertTrue(Validate::hostname('localhost'), 'localhost');
$this->assertTrue(Validate::hostname('google.com'), 'google.com');
$this->assertTrue(Validate::hostname('news.google.co.uk'), 'news.google.co.uk');
$this->assertTrue(Validate::hostname('xn--fsqu00a.xn--0zwm56d'), 'xn--fsqu00a.xn--0zwm56d');
$this->assertTrue(Validate::hostname('www.averylargedomainthatdoesnotreallyexist.com'), 'www.averylargedomainthatdoesnotreallyexist.com');
$this->assertTrue(Validate::hostname('cont-ains.h-yph-en-s.com'), 'cont-ains.h-yph-en-s.com');
$this->assertTrue(Validate::hostname('cisco-3750x'), 'cisco-3750x');
$this->assertFalse(Validate::hostname('cisco_3750x'), 'cisco_3750x');
$this->assertFalse(Validate::hostname('goo gle.com'), 'goo gle.com');
$this->assertFalse(Validate::hostname('google..com'), 'google..com');
$this->assertFalse(Validate::hostname('google.com '), 'google.com ');
$this->assertFalse(Validate::hostname('google-.com'), 'google-.com');
$this->assertFalse(Validate::hostname('.google.com'), '.google.com');
$this->assertFalse(Validate::hostname('..google.com'), '..google.com');
$this->assertFalse(Validate::hostname('<script'), '<script');
$this->assertFalse(Validate::hostname('alert('), 'alert(');
$this->assertFalse(Validate::hostname('.'), '.');
$this->assertFalse(Validate::hostname('..'), '..');
$this->assertFalse(Validate::hostname(' '), 'Just a space');
$this->assertFalse(Validate::hostname('-'), '-');
$this->assertFalse(Validate::hostname(''), 'Empty string');
}
public function testResolveGlues()