xref: /php-src/ext/snmp/tests/snmp3-error.phpt (revision ba1d9d0a)
1--TEST--
2SNMPv3 Support (errors)
3--CREDITS--
4Boris Lytochkin
5--EXTENSIONS--
6snmp
7--SKIPIF--
8<?php
9require_once(__DIR__.'/skipif.inc');
10if (getenv('SKIP_ASAN')) die('skip Timeouts under ASAN');
11?>
12--FILE--
13<?php
14require_once(__DIR__.'/snmp_include.inc');
15
16echo "Checking error handling\n";
17
18//int snmp3_get(string host, string sec_name, string sec_level, string auth_protocol,
19//              string auth_passphrase, string priv_protocol, string priv_passphrase,
20//              string object_id [, int timeout [, int retries]]);
21
22try {
23    var_dump(snmp3_get($hostname, $community, '', '', '', '', '', '.1.3.6.1.2.1.1.1.0'));
24} catch (\ValueError $e) {
25    echo $e->getMessage() . \PHP_EOL;
26}
27try {
28    var_dump(snmp3_get($hostname, $community, 'bugusPriv', '', '', '', '', '.1.3.6.1.2.1.1.1.0'));
29} catch (\ValueError $e) {
30    echo $e->getMessage() . \PHP_EOL;
31}
32try {
33    var_dump(snmp3_get($hostname, $community, 'authNoPriv', 'TTT', '', '', '', '.1.3.6.1.2.1.1.1.0'));
34} catch (\ValueError $e) {
35    echo $e->getMessage() . \PHP_EOL;
36}
37
38var_dump(snmp3_get($hostname, $community, 'authNoPriv', 'MD5', '', '', '', '.1.3.6.1.2.1.1.1.0'));
39var_dump(snmp3_get($hostname, $community, 'authNoPriv', 'MD5', 'te', '', '', '.1.3.6.1.2.1.1.1.0'));
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}
46
47var_dump(snmp3_get($hostname, $community, 'authPriv', 'MD5', $auth_pass, 'AES', '', '.1.3.6.1.2.1.1.1.0'));
48var_dump(snmp3_get($hostname, $community, 'authPriv', 'MD5', $auth_pass, 'AES', 'ty', '.1.3.6.1.2.1.1.1.0'));
49var_dump(snmp3_get($hostname, 'somebogususer', 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
50
51var_dump(snmp3_set($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '.1.3.6.777...7.5.3', 's', 'ttt', $timeout, $retries));
52
53try {
54    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));
55} catch (\TypeError $e) {
56    echo $e->getMessage() . \PHP_EOL;
57}
58
59?>
60--EXPECTF--
61Checking error handling
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: snmp3_get(): 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: 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
70bool(false)
71Security protocol must be one of "DES", "AES128", or "AES"
72
73Warning: snmp3_get(): Error generating a key for privacy pass phrase '': Generic error (The supplied password length is too short.) in %s on line %d
74bool(false)
75
76Warning: 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
77bool(false)
78
79Warning: snmp3_get(): Fatal error: Unknown user name in %s on line %d
80bool(false)
81
82Warning: snmp3_set(): Invalid object identifier: .1.3.6.777...7.5.3 in %s on line %d
83bool(false)
84Type must be of type string when object ID is a string
85