2020-04-19 22:36:01 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* addhostTest.php
|
|
|
|
*
|
|
|
|
* Tests for addhost funcion
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
* @link http://librenms.org
|
|
|
|
* @copyright 2020 Lars Elgtvedt Susaas
|
|
|
|
* @author Lars Elgtvedt Susaas
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace LibreNMS\Tests;
|
|
|
|
|
|
|
|
use App\Models\Device;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use LibreNMS\Config;
|
|
|
|
|
|
|
|
class AddHostTest extends DBTestCase
|
|
|
|
{
|
|
|
|
use DatabaseTransactions;
|
2020-09-21 13:59:34 +00:00
|
|
|
private $host = 'testHost';
|
2020-04-19 22:36:01 +00:00
|
|
|
|
|
|
|
public function testAddsnmpV1()
|
|
|
|
{
|
2020-09-21 13:59:34 +00:00
|
|
|
addHost($this->host, 'v1', 111, 'tcp', 0, true, 'ifIndex');
|
2020-04-19 22:36:01 +00:00
|
|
|
$device = Device::findByHostname($this->host);
|
|
|
|
$this->assertNotNull($device);
|
|
|
|
|
2020-09-21 13:59:34 +00:00
|
|
|
$this->assertEquals(0, $device->snmp_disable, 'snmp is disabled');
|
|
|
|
$this->assertEquals(1, $device->port_association_mode, 'Wrong port association mode');
|
|
|
|
$this->assertEquals('v1', $device->snmpver, 'Wrong snmp version');
|
|
|
|
$this->assertEquals(111, $device->port, 'Wrong snmp port');
|
|
|
|
$this->assertEquals('tcp', $device->transport, 'Wrong snmp transport (udp/tcp)');
|
2020-04-19 22:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddsnmpV2()
|
|
|
|
{
|
2020-09-21 13:59:34 +00:00
|
|
|
addHost($this->host, 'v2c', 111, 'tcp', 0, true, 'ifName');
|
2020-04-19 22:36:01 +00:00
|
|
|
$device = Device::findByHostname($this->host);
|
|
|
|
$this->assertNotNull($device);
|
|
|
|
|
2020-09-21 13:59:34 +00:00
|
|
|
$this->assertEquals(0, $device->snmp_disable, 'snmp is disabled');
|
|
|
|
$this->assertEquals(2, $device->port_association_mode, 'Wrong port association mode');
|
|
|
|
$this->assertEquals(Config::get('snmp.community')[0], $device->community, 'Wrong snmp community');
|
|
|
|
$this->assertEquals('v2c', $device->snmpver, 'Wrong snmp version');
|
2020-04-19 22:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddsnmpV3()
|
|
|
|
{
|
2020-09-21 13:59:34 +00:00
|
|
|
addHost($this->host, 'v3', 111, 'tcp', 0, true, 'ifIndex');
|
2020-04-19 22:36:01 +00:00
|
|
|
$device = Device::findByHostname($this->host);
|
|
|
|
$this->assertNotNull($device);
|
|
|
|
|
2020-09-21 13:59:34 +00:00
|
|
|
$this->assertEquals(0, $device->snmp_disable, 'snmp is disabled');
|
|
|
|
$this->assertEquals(1, $device->port_association_mode, 'Wrong port association mode');
|
|
|
|
$this->assertEquals(Config::get('snmp.v3')[0]['authlevel'], $device->authlevel, 'Wrong snmp v3 authlevel');
|
|
|
|
$this->assertEquals('v3', $device->snmpver, 'Wrong snmp version');
|
|
|
|
$this->assertEquals(Config::get('snmp.v3')[0]['authname'], $device->authname, 'Wrong snmp v3 username');
|
|
|
|
$this->assertEquals(Config::get('snmp.v3')[0]['authpass'], $device->authpass, 'Wrong snmp v3 password');
|
2020-04-19 22:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddping()
|
|
|
|
{
|
2020-09-21 12:54:51 +00:00
|
|
|
$additional = [
|
2020-04-19 22:36:01 +00:00
|
|
|
'snmp_disable' => 1,
|
|
|
|
'os' => 'nameOfOS',
|
|
|
|
'hardware' => 'hardware',
|
2020-09-21 12:54:51 +00:00
|
|
|
];
|
2020-09-21 13:59:34 +00:00
|
|
|
addHost($this->host, '', 0, 0, 0, true, 'ifIndex', $additional);
|
2020-04-19 22:36:01 +00:00
|
|
|
$device = Device::findByHostname($this->host);
|
|
|
|
$this->assertNotNull($device);
|
2020-09-21 13:59:34 +00:00
|
|
|
$this->assertEquals(1, $device->snmp_disable, 'snmp is not disabled');
|
|
|
|
$this->assertEquals('hardware', $device->hardware, 'Wrong hardware');
|
|
|
|
$this->assertEquals('nameOfOS', $device->os, 'Wrong os');
|
2020-04-19 22:36:01 +00:00
|
|
|
}
|
|
|
|
}
|