xref: /PHP-8.2/ext/snmp/tests/snmp3-error.phpt (revision 718e9134)
1--TEST--
2SNMPv3 Support (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
15echo "Checking error handling\n";
16
17//int snmp3_get(string host, string sec_name, string sec_level, string auth_protocol,
18//              string auth_passphrase, string priv_protocol, string priv_passphrase,
19//              string object_id [, int timeout [, int retries]]);
20
21try {
22    var_dump(snmp3_get($hostname, $community, '', '', '', '', '', '.1.3.6.1.2.1.1.1.0'));
23} catch (\ValueError $e) {
24    echo $e->getMessage() . \PHP_EOL;
25}
26try {
27    var_dump(snmp3_get($hostname, $community, 'bugusPriv', '', '', '', '', '.1.3.6.1.2.1.1.1.0'));
28} catch (\ValueError $e) {
29    echo $e->getMessage() . \PHP_EOL;
30}
31try {
32    var_dump(snmp3_get($hostname, $community, 'authNoPriv', 'TTT', '', '', '', '.1.3.6.1.2.1.1.1.0'));
33} catch (\ValueError $e) {
34    echo $e->getMessage() . \PHP_EOL;
35}
36
37var_dump(snmp3_get($hostname, $community, 'authNoPriv', 'MD5', '', '', '', '.1.3.6.1.2.1.1.1.0'));
38var_dump(snmp3_get($hostname, $community, 'authNoPriv', 'MD5', 'te', '', '', '.1.3.6.1.2.1.1.1.0'));
39
40try {
41    var_dump(snmp3_get($hostname, $community, 'authPriv', 'MD5', $auth_pass, 'BBB', '', '.1.3.6.1.2.1.1.1.0'));
42} catch (\ValueError $e) {
43    echo $e->getMessage() . \PHP_EOL;
44}
45
46var_dump(snmp3_get($hostname, $community, 'authPriv', 'MD5', $auth_pass, 'AES', '', '.1.3.6.1.2.1.1.1.0'));
47var_dump(snmp3_get($hostname, $community, 'authPriv', 'MD5', $auth_pass, 'AES', 'ty', '.1.3.6.1.2.1.1.1.0'));
48var_dump(snmp3_get($hostname, 'somebogususer', 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
49
50var_dump(snmp3_set($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '.1.3.6.777...7.5.3', 's', 'ttt', $timeout, $retries));
51
52try {
53    var_dump(snmp3_set($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '.1.3.6.777.7.5.3', array('s'), 'yyy', $timeout, $retries));
54} catch (\TypeError $e) {
55    echo $e->getMessage() . \PHP_EOL;
56}
57
58?>
59--EXPECTF--
60Checking error handling
61Security level must be one of "noAuthNoPriv", "authNoPriv", or "authPriv"
62Security level must be one of "noAuthNoPriv", "authNoPriv", or "authPriv"
63Authentication protocol must be %s
64
65Warning: snmp3_get(): Error generating a key for authentication pass phrase '': Generic error (The supplied password length is too short.) in %s on line %d
66bool(false)
67
68Warning: snmp3_get(): Error generating a key for authentication pass phrase 'te': Generic error (The supplied password length is too short.) in %s on line %d
69bool(false)
70Security protocol must be one of "DES", "AES128", or "AES"
71
72Warning: snmp3_get(): 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: snmp3_get(): 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: snmp3_get(): Fatal error: Unknown user name in %s on line %d
79bool(false)
80
81Warning: snmp3_set(): Invalid object identifier: .1.3.6.777...7.5.3 in %s on line %d
82bool(false)
83Type must be of type string when object ID is a string
84