Issues (2963)

tests/AddHostTest.php (1 issue)

1
<?php
2
/**
3
 * addhostTest.php
4
 *
5
 * Tests for addhost funcion
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
 *
20
 * @link https://www.librenms.org
21
 *
22
 * @copyright  2020 Lars Elgtvedt Susaas
23
 * @author     Lars Elgtvedt Susaas
24
 */
25
26
namespace LibreNMS\Tests;
27
28
use App\Models\Device;
29
use Illuminate\Foundation\Testing\DatabaseTransactions;
30
use LibreNMS\Config;
31
32
class AddHostTest extends DBTestCase
33
{
34
    use DatabaseTransactions;
0 ignored issues
show
The trait Illuminate\Foundation\Testing\DatabaseTransactions requires the property $connectionsToTransact which is not provided by LibreNMS\Tests\AddHostTest.
Loading history...
35
    private $host = 'testHost';
36
37
    public function testAddsnmpV1()
38
    {
39
        addHost($this->host, 'v1', 111, 'tcp', 0, true, 'ifIndex');
40
        $device = Device::findByHostname($this->host);
41
        $this->assertNotNull($device);
42
43
        $this->assertEquals(0, $device->snmp_disable, 'snmp is disabled');
44
        $this->assertEquals(1, $device->port_association_mode, 'Wrong port association mode');
45
        $this->assertEquals('v1', $device->snmpver, 'Wrong snmp version');
46
        $this->assertEquals(111, $device->port, 'Wrong snmp port');
47
        $this->assertEquals('tcp', $device->transport, 'Wrong snmp transport (udp/tcp)');
48
    }
49
50
    public function testAddsnmpV2()
51
    {
52
        addHost($this->host, 'v2c', 111, 'tcp', 0, true, 'ifName');
53
        $device = Device::findByHostname($this->host);
54
        $this->assertNotNull($device);
55
56
        $this->assertEquals(0, $device->snmp_disable, 'snmp is disabled');
57
        $this->assertEquals(2, $device->port_association_mode, 'Wrong port association mode');
58
        $this->assertEquals(Config::get('snmp.community')[0], $device->community, 'Wrong snmp community');
59
        $this->assertEquals('v2c', $device->snmpver, 'Wrong snmp version');
60
    }
61
62
    public function testAddsnmpV3()
63
    {
64
        addHost($this->host, 'v3', 111, 'tcp', 0, true, 'ifIndex');
65
        $device = Device::findByHostname($this->host);
66
        $this->assertNotNull($device);
67
68
        $this->assertEquals(0, $device->snmp_disable, 'snmp is disabled');
69
        $this->assertEquals(1, $device->port_association_mode, 'Wrong port association mode');
70
        $this->assertEquals(Config::get('snmp.v3')[0]['authlevel'], $device->authlevel, 'Wrong snmp v3 authlevel');
71
        $this->assertEquals('v3', $device->snmpver, 'Wrong snmp version');
72
        $this->assertEquals(Config::get('snmp.v3')[0]['authname'], $device->authname, 'Wrong snmp v3 username');
73
        $this->assertEquals(Config::get('snmp.v3')[0]['authpass'], $device->authpass, 'Wrong snmp v3 password');
74
    }
75
76
    public function testAddping()
77
    {
78
        $additional = [
79
            'snmp_disable' => 1,
80
            'os'           => 'nameOfOS',
81
            'hardware'     => 'hardware',
82
        ];
83
        addHost($this->host, '', 0, 0, 0, true, 'ifIndex', $additional);
84
        $device = Device::findByHostname($this->host);
85
        $this->assertNotNull($device);
86
        $this->assertEquals(1, $device->snmp_disable, 'snmp is not disabled');
87
        $this->assertEquals('hardware', $device->hardware, 'Wrong hardware');
88
        $this->assertEquals('nameOfOS', $device->os, 'Wrong os');
89
    }
90
}
91