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