1 | <?php |
||
2 | /** |
||
3 | * addhostCliTest.php |
||
4 | * |
||
5 | * Tests for addhost.php cli tool |
||
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 | |||
31 | class AddHostCliTest extends DBTestCase |
||
32 | { |
||
33 | use DatabaseTransactions; |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
34 | private $hostName = 'testHost'; |
||
35 | |||
36 | public function testCLIsnmpV1() |
||
37 | { |
||
38 | $result = \Artisan::call('device:add ' . $this->hostName . ' -force -ccommunity --v1'); |
||
39 | $this->assertEquals(0, $result, 'command returned non zero value'); |
||
40 | $device = Device::findByHostname($this->hostName); |
||
41 | $this->assertNotNull($device); |
||
42 | |||
43 | $this->assertEquals(0, $device->snmp_disable, 'snmp is disabled'); |
||
44 | $this->assertEquals('community', $device->community, 'Wrong snmp community'); |
||
45 | $this->assertEquals('v1', $device->snmpver, 'Wrong snmp version'); |
||
46 | } |
||
47 | |||
48 | public function testCLIsnmpV2() |
||
49 | { |
||
50 | $result = \Artisan::call('device:add ' . $this->hostName . ' -force -ccommunity --v2c'); |
||
51 | $this->assertEquals(0, $result, 'command returned non zero value'); |
||
52 | $device = Device::findByHostname($this->hostName); |
||
53 | $this->assertNotNull($device); |
||
54 | |||
55 | $this->assertEquals(0, $device->snmp_disable, 'snmp is disabled'); |
||
56 | $this->assertEquals('community', $device->community, 'Wrong snmp community'); |
||
57 | $this->assertEquals('v2c', $device->snmpver, 'Wrong snmp version'); |
||
58 | } |
||
59 | |||
60 | public function testCLIsnmpV3UserAndPW() |
||
61 | { |
||
62 | $result = \Artisan::call('device:add ' . $this->hostName . ' -force -uSecName -AAuthPW -XPrivPW --v3'); |
||
63 | $this->assertEquals(0, $result, 'command returned non zero value'); |
||
64 | $device = Device::findByHostname($this->hostName); |
||
65 | $this->assertNotNull($device); |
||
66 | |||
67 | $this->assertEquals(0, $device->snmp_disable, 'snmp is disabled'); |
||
68 | $this->assertEquals('authPriv', $device->authlevel, 'Wrong snmp v3 authlevel'); |
||
69 | $this->assertEquals('SecName', $device->authname, 'Wrong snmp v3 security username'); |
||
70 | $this->assertEquals('AuthPW', $device->authpass, 'Wrong snmp v3 authentication password'); |
||
71 | $this->assertEquals('PrivPW', $device->cryptopass, 'Wrong snmp v3 crypto password'); |
||
72 | $this->assertEquals('v3', $device->snmpver, 'Wrong snmp version'); |
||
73 | } |
||
74 | |||
75 | public function testPortAssociationMode() |
||
76 | { |
||
77 | $modes = ['ifIndex', 'ifName', 'ifDescr', 'ifAlias']; |
||
78 | foreach ($modes as $index => $mode) { |
||
79 | $host = 'hostName' . $mode; |
||
80 | $result = \Artisan::call('device:add ' . $host . ' -force -p ' . $mode . ' --v1'); |
||
81 | $this->assertEquals(0, $result, 'command returned non zero value'); |
||
82 | $device = Device::findByHostname($host); |
||
83 | $this->assertNotNull($device); |
||
84 | $this->assertEquals($index + 1, $device->port_association_mode, 'Wrong port association mode ' . $mode); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | public function testSnmpTransport() |
||
89 | { |
||
90 | $modes = ['udp', 'udp6', 'tcp', 'tcp6']; |
||
91 | foreach ($modes as $mode) { |
||
92 | $host = 'hostName' . $mode; |
||
93 | $result = \Artisan::call('device:add ' . $host . ' -force -t ' . $mode . ' --v1'); |
||
94 | $this->assertEquals(0, $result, 'command returned non zero value'); |
||
95 | $device = Device::findByHostname($host); |
||
96 | $this->assertNotNull($device); |
||
97 | |||
98 | $this->assertEquals($mode, $device->transport, 'Wrong snmp transport (udp/tcp) ipv4/ipv6'); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | public function testSnmpV3AuthProtocol() |
||
103 | { |
||
104 | $modes = ['MD5', 'SHA', 'SHA-224', 'SHA-256', 'SHA-384', 'SHA-512']; |
||
105 | foreach ($modes as $mode) { |
||
106 | $host = 'hostName' . $mode; |
||
107 | $result = \Artisan::call('device:add ' . $host . ' -force -a ' . $mode . ' --v3'); |
||
108 | $this->assertEquals(0, $result, 'command returned non zero value'); |
||
109 | $device = Device::findByHostname($host); |
||
110 | $this->assertNotNull($device); |
||
111 | |||
112 | $this->assertEquals(strtoupper($mode), $device->authalgo, 'Wrong snmp v3 password algorithm'); |
||
113 | } |
||
114 | } |
||
115 | |||
116 | public function testSnmpV3PrivacyProtocol() |
||
117 | { |
||
118 | $modes = ['DES', 'AES', 'AES-192', 'AES-256', 'AES-256-C']; |
||
119 | foreach ($modes as $mode) { |
||
120 | $host = 'hostName' . $mode; |
||
121 | $result = \Artisan::call('device:add ' . $host . ' -force -x ' . $mode . ' --v3'); |
||
122 | $this->assertEquals(0, $result, 'command returned non zero value'); |
||
123 | $device = Device::findByHostname($host); |
||
124 | $this->assertNotNull($device); |
||
125 | |||
126 | $this->assertEquals(strtoupper($mode), $device->cryptoalgo, 'Wrong snmp v3 crypt algorithm'); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | public function testCLIping() |
||
131 | { |
||
132 | $result = \Artisan::call('device:add ' . $this->hostName . ' -force -P -onameOfOS -whardware -sSystem --v1'); |
||
133 | $this->assertEquals(0, $result, 'command returned non zero value'); |
||
134 | |||
135 | $device = Device::findByHostname($this->hostName); |
||
136 | $this->assertNotNull($device); |
||
137 | |||
138 | $this->assertEquals(1, $device->snmp_disable, 'snmp is not disabled'); |
||
139 | $this->assertEquals('hardware', $device->hardware, 'Wrong hardware name'); |
||
140 | $this->assertEquals('nameOfOS', $device->os, 'Wrong os name'); |
||
141 | $this->assertEquals('System', $device->sysName, 'Wrong system name'); |
||
142 | } |
||
143 | } |
||
144 |