1--TEST--
2OO API: SNMP::setSecurity (errors)
3--CREDITS--
4Boris Lytochkin
5--SKIPIF--
6<?php
7require_once(__DIR__.'/skipif.inc');
8?>
9--FILE--
10<?php
11require_once(__DIR__.'/snmp_include.inc');
12
13//EXPECTF format is quickprint OFF
14snmp_set_quick_print(false);
15snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
16
17$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
18$session->setSecurity('noAuthNoPriv');
19
20#echo "Checking error handling\n";
21
22try {
23var_dump($session->setSecurity(''));
24} catch (\ValueError $e) {
25    echo $e->getMessage() . \PHP_EOL;
26}
27try {
28var_dump($session->setSecurity('bugusPriv'));
29} catch (\ValueError $e) {
30    echo $e->getMessage() . \PHP_EOL;
31}
32try {
33var_dump($session->setSecurity('authNoPriv', 'TTT'));
34} catch (\ValueError $e) {
35    echo $e->getMessage() . \PHP_EOL;
36}
37
38var_dump($session->setSecurity('authNoPriv', 'MD5', ''));
39var_dump($session->setSecurity('authNoPriv', 'MD5', 'te'));
40
41try {
42    var_dump(snmp3_get($hostname, $community, 'authPriv', 'MD5', $auth_pass, 'BBB', '', '.1.3.6.1.2.1.1.1.0'));
43} catch (\ValueError $e) {
44    echo $e->getMessage() . \PHP_EOL;
45}
46try {
47    var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'BBB'));
48} catch (\ValueError $e) {
49    echo $e->getMessage() . \PHP_EOL;
50}
51
52var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', ''));
53var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', 'ty'));
54var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', 'test12345', 'context', 'dsa'));
55
56var_dump($session->close());
57
58?>
59--EXPECTF--
60Security level must be one of "noAuthNoPriv", "authNoPriv", or "authPriv"
61Security level must be one of "noAuthNoPriv", "authNoPriv", or "authPriv"
62Authentication protocol must be either "MD5" or "SHA"
63
64Warning: SNMP::setSecurity(): Error generating a key for authentication pass phrase '': Generic error (The supplied password length is too short.) in %s on line %d
65bool(false)
66
67Warning: SNMP::setSecurity(): Error generating a key for authentication pass phrase 'te': Generic error (The supplied password length is too short.) in %s on line %d
68bool(false)
69Security protocol must be one of "DES", "AES128", or "AES"
70Security protocol must be one of "DES", "AES128", or "AES"
71
72Warning: SNMP::setSecurity(): Error generating a key for privacy pass phrase '': Generic error (The supplied password length is too short.) in %s on line %d
73bool(false)
74
75Warning: SNMP::setSecurity(): Error generating a key for privacy pass phrase 'ty': Generic error (The supplied password length is too short.) in %s on line %d
76bool(false)
77
78Warning: SNMP::setSecurity(): Bad engine ID value 'dsa' in %s on line %d
79bool(false)
80bool(true)
81