1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
<?php
/*
** Zabbix
** Copyright (C) 2001-2021 Zabbix SIA
**
** 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 2 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
require_once dirname(__FILE__).'/../include/CLegacyWebTest.php';
define('PROXY_GOOD', 0);
define('PROXY_BAD', 1);
use Facebook\WebDriver\WebDriverBy;
/**
* @backup hosts
*/
class testFormAdministrationDMProxies extends CLegacyWebTest {
private $proxy_name = 'proxy_name_1';
private $new_proxy_name = 'proxy_name_new';
private $cloned_proxy_name = 'proxy_name_new_clone';
private $long_proxy_name = '1234567890123456789012345678901234567890123456789012345678901234';
private $long_proxy_name2 = '12345678901234567890123456789012345678901234567890123456789012345';
private $proxy_host = 'Zabbix server';
private $passive_proxy_host = 'H1';
private $passive_proxy_name = 'passive_proxy_name1';
public function testFormAdministrationDMProxies_CheckLayout() {
$this->zbxTestLogin('zabbix.php?action=proxy.list');
$this->zbxTestCheckTitle('Configuration of proxies');
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestClickButtonText('Create proxy');
$this->zbxTestTextPresent(['Proxy name', 'Proxy mode', 'Proxy address', 'Description']);
$this->zbxTestAssertElementPresentId('host');
$this->zbxTestAssertAttribute('//input[@id=\'host\']', 'maxlength', '128');
$this->zbxTestAssertElementText("//ul[@id='status']//label[@for='status_0']", 'Active');
$this->zbxTestAssertElementText("//ul[@id='status']//label[@for='status_1']", 'Passive');
$this->zbxTestAssertElementPresentXpath("//button[@value='proxy.create']");
$this->zbxTestAssertElementPresentXpath("//button[text()='Cancel']");
// Switch to passive mode
$this->zbxTestClickXpathWait("//ul[@id='status']//label[@for='status_1']");
$this->zbxTestWaitUntilElementVisible(WebDriverBy::id('ip'));
$this->zbxTestTextPresent(['Proxy name', 'Proxy mode', 'Interface', 'Description']);
$this->zbxTestTextPresent(['IP address', 'DNS name', 'Connect to', 'Port']);
$this->zbxTestAssertElementPresentId('host');
$this->zbxTestAssertAttribute('//input[@id=\'host\']', 'maxlength', '128');
$this->zbxTestAssertElementPresentId('status');
$this->zbxTestAssertElementPresentId('ip');
$this->zbxTestAssertAttribute('//input[@id=\'ip\']', 'maxlength', '64');
$this->zbxTestAssertElementPresentId('dns');
$this->zbxTestAssertAttribute('//input[@id=\'dns\']', 'maxlength', '255');
$this->zbxTestAssertElementPresentId('port');
$this->zbxTestAssertAttribute('//input[@id=\'port\']', 'maxlength', '64');
$this->zbxTestAssertElementPresentXpath("//button[@value='proxy.create']");
$this->zbxTestAssertElementPresentXpath("//button[text()='Cancel']");
}
// Returns all possible proxy data
public static function dataCreate() {
// Ok/bad, name, mode, hosts, ip, dns, connect_to, port, error
return [
[PROXY_GOOD, 'New active proxy 1', HOST_STATUS_PROXY_ACTIVE,
0, 0, 'No encryption', 0, ''
],
[PROXY_GOOD, 'New active proxy 2', HOST_STATUS_PROXY_ACTIVE,
0, 0, 'PSK', 0, ''
],
[PROXY_GOOD, 'New active proxy 3', HOST_STATUS_PROXY_ACTIVE,
0, 0, 'Certificate', 0, ''
],
[PROXY_GOOD, 'New passive proxy 1', HOST_STATUS_PROXY_PASSIVE,
'192.168.1.1', 'proxy123.zabbix.com', 'No encryption', 11051, ''
],
[PROXY_GOOD, 'New passive proxy with IP macro', HOST_STATUS_PROXY_PASSIVE,
'{$PROXY_IP}', 'proxy123.zabbix.com', 'PSK', 11051, ''
],
[PROXY_GOOD, 'New passive proxy with port macro', HOST_STATUS_PROXY_PASSIVE,
'192.168.1.1', 'proxy123.zabbix.com', 'Certificate', '{$PROXY_PORT}', ''
],
[
PROXY_BAD,
'New passive proxy 2',
HOST_STATUS_PROXY_PASSIVE,
'wrong ip',
'proxy123.zabbix.com',
11051,
0,
['Cannot add proxy', 'Invalid IP address "wrong ip".']
],
[
PROXY_BAD,
'%^&',
HOST_STATUS_PROXY_PASSIVE,
'wrong ip',
'proxy123.zabbix.com',
11051,
0,
['Cannot add proxy', 'Incorrect characters used for proxy name']
],
[
PROXY_BAD,
'Прокси',
HOST_STATUS_PROXY_PASSIVE,
'wrong ip',
'proxy123.zabbix.com',
11051,
0,
['Cannot add proxy', 'Incorrect characters used for proxy name "Прокси".']
],
[
PROXY_BAD,
'New passive proxy 3',
HOST_STATUS_PROXY_PASSIVE,
'192.168.1.1',
'proxy123.zabbix.com',
0,
'port',
['Cannot add proxy', 'Incorrect interface port "port" provided.']
],
[PROXY_BAD,
'Active proxy 1',
HOST_STATUS_PROXY_ACTIVE,
0,
0,
0,
0,
['Cannot add proxy', 'Proxy "Active proxy 1" already exists.']
],
[PROXY_BAD,
'New passive proxy with wrong port macro',
HOST_STATUS_PROXY_PASSIVE,
'192.168.1.1',
'proxy123.zabbix.com',
0,
'$PROXY_PORT',
['Cannot add proxy', 'Incorrect interface port "$PROXY_PORT" provided.']
],
[PROXY_BAD,
'New passive proxy with wrong IP macro',
HOST_STATUS_PROXY_PASSIVE,
'$PROXY_IP',
'proxy123.zabbix.com',
0,
11051,
['Cannot add proxy', 'Invalid IP address "$PROXY_IP".']
]
];
}
/**
* @dataProvider dataCreate
*/
public function testFormAdministrationDMProxies_Create($expected, $name, $mode, $ip, $dns, $connect_to, $port, $errormsgs) {
$this->zbxTestLogin('zabbix.php?action=proxy.list');
$this->zbxTestCheckTitle('Configuration of proxies');
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestClickButtonText('Create proxy');
$this->zbxTestCheckTitle('Configuration of proxies');
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestInputTypeWait('host', $name);
switch ($mode) {
case HOST_STATUS_PROXY_ACTIVE:
$this->zbxTestClickXpathWait("//ul[@id='status']//label[@for='status_0']");
$this->zbxTestClickWait('tab_encryptionTab');
$this->zbxTestWaitUntilElementVisible(WebDriverBy::id('encryption'));
$this->zbxTestAssertElementPresentXpath("//input[@id='tls_connect_0'][@disabled]");
$this->zbxTestAssertElementPresentXpath("//input[@id='tls_connect_1'][@disabled]");
$this->zbxTestAssertElementPresentXpath("//input[@id='tls_connect_2'][@disabled]");
switch ($connect_to) {
case 'No encryption':
$this->zbxTestAssertNotVisibleId('tls_psk_identity');
$this->zbxTestAssertNotVisibleId('tls_psk');
$this->zbxTestAssertNotVisibleId('tls_issuer');
$this->zbxTestAssertNotVisibleId('tls_subject');
break;
case 'PSK':
$this->zbxTestCheckboxSelect('tls_in_psk');
$this->zbxTestInputTypeWait('tls_psk_identity', 'test identity');
$this->zbxTestInputTypeWait('tls_psk', '12345678901234567890123456789012');
break;
case 'Certificate':
$this->zbxTestCheckboxSelect('tls_in_cert');
$this->zbxTestAssertElementPresentId('tls_issuer');
$this->zbxTestAssertElementPresentId('tls_subject');
break;
}
break;
case HOST_STATUS_PROXY_PASSIVE:
$this->zbxTestClickXpathWait("//ul[@id='status']//label[@for='status_1']");
$this->zbxTestInputTypeOverwrite('ip', $ip);
$this->zbxTestInputTypeOverwrite('dns', $dns);
$this->zbxTestInputTypeOverwrite('port', $port);
$this->zbxTestClickWait('tab_encryptionTab');
$this->zbxTestWaitUntilElementVisible(WebDriverBy::id('encryption'));
$this->zbxTestAssertElementPresentXpath("//input[@id='tls_in_none'][@disabled]");
$this->zbxTestAssertElementPresentXpath("//input[@id='tls_psk_identity'][@disabled]");
$this->zbxTestAssertElementPresentXpath("//input[@id='tls_psk'][@disabled]");
switch ($connect_to) {
case 'No encryption':
$this->assertTrue($this->zbxTestCheckboxSelected('tls_connect_0'));
break;
case 'PSK':
$this->zbxTestClickXpathWait("//ul[@id='tls_connect']//label[@for='tls_connect_1']");
$this->zbxTestInputTypeWait('tls_psk_identity', 'test identity');
$this->zbxTestInputTypeWait('tls_psk', '12345678901234567890123456789012');
break;
case 'Certificate':
$this->zbxTestClickXpathWait("//ul[@id='tls_connect']//label[@for='tls_connect_2']");
$this->zbxTestAssertElementPresentId('tls_issuer');
$this->zbxTestAssertElementPresentId('tls_subject');
break;
}
break;
}
$this->zbxTestClickButton('proxy.create');
switch ($expected) {
case PROXY_GOOD:
$this->zbxTestTextNotPresent('Cannot add proxy');
$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Proxy added');
$this->zbxTestCheckTitle('Configuration of proxies');
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestTextPresent(['Mode', 'Name', 'Encryption', 'Last seen (age)', 'Host count', 'Required performance (vps)', 'Hosts']);
$this->zbxTestTextPresent($name);
switch ($mode) {
case HOST_STATUS_PROXY_ACTIVE:
$sql = "SELECT hostid FROM hosts WHERE host='$name' AND status=$mode";
$this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Active proxy has not been added into Zabbix DB');
break;
case HOST_STATUS_PROXY_PASSIVE:
$sql = "SELECT hostid FROM hosts WHERE host='$name' AND status=$mode";
$this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Active proxy has not been added into Zabbix DB');
$sql = "SELECT h.hostid FROM hosts h, interface i WHERE h.host='$name' AND h.status=$mode and h.hostid=i.hostid and i.port='$port' and i.dns='$dns' and i.ip='$ip' and i.main=".INTERFACE_PRIMARY;
$this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Interface was not linked correctly to proxy');
break;
}
break;
case PROXY_BAD:
$this->zbxTestCheckTitle('Configuration of proxies');
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestTextPresent('Proxy name');
foreach ($errormsgs as $msg) {
$this->zbxTestTextPresent($msg);
}
break;
}
}
public static function dataUpdateProxyName() {
// Name, newname
return [
['Active proxy 3', 'New active proxy 3 updated'],
['Passive proxy 3', 'New passive proxy 3 updated']
];
}
/**
* @dataProvider dataUpdateProxyName
*/
public function testFormAdministrationDMProxies_UpdateProxyName($name, $newname) {
$this->zbxTestLogin('zabbix.php?action=proxy.list');
$this->zbxTestCheckTitle('Configuration of proxies');
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestClickLinkText($name);
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestAssertElementPresentXpath("//button[@value='proxy.update']");
$this->zbxTestAssertElementPresentId('clone');
$this->zbxTestAssertElementPresentXpath("//button[text()='Delete']");
$this->zbxTestAssertElementPresentXpath("//button[text()='Cancel']");
$sql=
'SELECT hostid,proxy_hostid,status,ipmi_authtype,ipmi_privilege,ipmi_username,'.
'ipmi_password,maintenanceid,maintenance_status,maintenance_type,maintenance_from'.
' FROM hosts'.
' ORDER BY hostid';
$oldHash = CDBHelper::getHash($sql);
$this->zbxTestInputTypeOverwrite('host', $newname);
$this->zbxTestClickButton('proxy.update');
$this->zbxTestTextPresent('Proxy updated');
$this->zbxTestCheckTitle('Configuration of proxies');
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestTextPresent($newname);
$this->assertEquals($oldHash, CDBHelper::getHash($sql));
$sql = "SELECT * FROM hosts WHERE host='$newname' AND status in (".HOST_STATUS_PROXY_ACTIVE.",".HOST_STATUS_PROXY_PASSIVE.")";
$this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Proxy name has not been updated');
}
public static function dataClone() {
// Name, clone name
return [
['Active proxy 1', 'Active proxy 1 cloned'],
['Passive proxy 1', 'Passive proxy 1 cloned']
];
}
/**
* @dataProvider dataClone
*/
public function testFormAdministrationDMProxies_Clone($name, $newname) {
$this->zbxTestLogin('zabbix.php?action=proxy.list');
$this->zbxTestCheckTitle('Configuration of proxies');
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestClickLinkText($name);
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestAssertElementPresentXpath("//button[@value='proxy.update']");
$this->zbxTestAssertElementPresentId('clone');
$this->zbxTestAssertElementPresentXpath("//button[text()='Delete']");
$this->zbxTestAssertElementPresentXpath("//button[text()='Cancel']");
$this->zbxTestClickWait('clone');
$this->zbxTestTextPresent('Proxy');
$this->zbxTestInputTypeOverwrite('host', $newname);
$this->zbxTestClickButton('proxy.create');
$this->zbxTestTextPresent('Proxy added');
$this->zbxTestCheckTitle('Configuration of proxies');
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestTextPresent($newname);
$sql = "SELECT * FROM hosts WHERE host='$newname' AND status in (".HOST_STATUS_PROXY_ACTIVE.",".HOST_STATUS_PROXY_PASSIVE.")";
$this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Proxy has not been created');
}
public static function dataDelete() {
return [
['Active proxy to delete'],
['Passive proxy to delete']
];
}
/**
* @dataProvider dataDelete
*/
public function testFormAdministrationDMProxies_Delete($name) {
$this->zbxTestLogin('zabbix.php?action=proxy.list');
$this->zbxTestCheckTitle('Configuration of proxies');
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestClickLinkText($name);
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestTextPresent(['Update', 'Clone', 'Delete', 'Cancel']);
$this->zbxTestClickButtonText('Delete');
$this->zbxTestAcceptAlert();
$this->zbxTestCheckTitle('Configuration of proxies');
$this->zbxTestCheckHeader('Proxies');
$this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Proxy deleted');
$this->zbxTestAssertElementNotPresentXpath("//a[text()='".$name."']");
$sql = "SELECT * FROM hosts WHERE host='$name'";
$this->assertEquals(0, CDBHelper::getCount($sql), 'Chuck Norris: Proxy has not been deleted');
}
}
|