snmp-object-setSecurity_error.phpt 2.6 KB

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