mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Refactor remove use of pear Net_IPv4 and Net_IPv6 Caution, I added tests to test the functionality of the new functions, but I'm not 100% certain the replaced usages match 100%. Please test. Left usage in generate-iplist.php because I'm not sure the use of that script, so I didn't want to implement additional functionality to support it. Add support for ipv6 fo ipInNetwork() function Add phpdocs to functions Remove accidental inclusion Use binary operations instead of string for networKFromIp() Tidy up binary operations in ipInNetwork() tidy parsing cidr network Change to a class based implementation. Update phpdocs. Fully catch exceptions for hex parsing. Fix mistake. support older phpunit versions Fix php shifting to negative with php 5 * Fix graph authorization. Uncaught exception and checking an ipv4 against an ipv6 network == fail. * Also remove colons from hex strings. * Fix typo in bgp polling Two passes of removing invalid characters from hex strings. (That way we don't mangle valid IPs)
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* FunctionsTest.php
|
|
*
|
|
* tests functions in includes/functions.php
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* @package LibreNMS
|
|
* @link http://librenms.org
|
|
* @copyright 2017 Tony Murray
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
*/
|
|
|
|
namespace LibreNMS\Tests;
|
|
|
|
class FunctionsTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function testMacCleanToReadable()
|
|
{
|
|
$this->assertEquals('de:ad:be:ef:a0:c3', mac_clean_to_readable('deadbeefa0c3'));
|
|
}
|
|
|
|
public function testHex2Str()
|
|
{
|
|
$this->assertEquals('Big 10 UP', hex2str('426967203130205550'));
|
|
}
|
|
|
|
public function testSnmpHexstring()
|
|
{
|
|
$input = '4c 61 72 70 69 6e 67 20 34 20 55 00 0a';
|
|
$this->assertEquals("Larping 4 U\n", snmp_hexstring($input));
|
|
}
|
|
|
|
public function testIsHexString()
|
|
{
|
|
$this->assertTrue(isHexString('af 28 02'));
|
|
$this->assertTrue(isHexString('aF 28 02 CE'));
|
|
$this->assertFalse(isHexString('a5 fj 53'));
|
|
$this->assertFalse(isHexString('a5fe53'));
|
|
}
|
|
}
|