~ubuntu-branches/ubuntu/gutsy/net-snmp/gutsy-security

« back to all changes in this revision

Viewing changes to perl/SNMP/t/session.t

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-13 12:06:21 UTC
  • Revision ID: james.westby@ubuntu.com-20040913120621-g952ntonlleihcvm
Tags: upstream-5.1.1
ImportĀ upstreamĀ versionĀ 5.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!./perl
 
2
 
 
3
BEGIN {
 
4
    unless(grep /blib/, @INC) {
 
5
        chdir 't' if -d 't';
 
6
        @INC = '../lib' if -d '../lib';
 
7
    }
 
8
}
 
9
use Test;
 
10
BEGIN { plan tests => 5}
 
11
use SNMP;
 
12
use vars qw($agent_port $comm $agent_host $bad_auth_pass $auth_pass $sec_name $bad_sec_name $bad_version $bad_priv_pass $priv_pass);
 
13
require "t/startagent.pl";
 
14
 
 
15
$SNMP::debugging = 0;
 
16
 
 
17
# create list of varbinds for GETS, val field can be null or omitted
 
18
my $vars = new SNMP::VarList (
 
19
                           ['sysDescr', '0', ''],
 
20
                           ['sysContact', '0'],
 
21
                           ['sysName', '0'],
 
22
                           ['sysLocation', '0'],
 
23
                           ['sysServices', '0'],
 
24
                           ['ifNumber', '0'],
 
25
                           ['ifDescr', '1'],
 
26
                           ['ifSpeed', '1'],
 
27
                          );
 
28
 
 
29
#########################== 1 ===#########################################
 
30
# Create a bogus session, undef means the host can't be found.
 
31
# removed! this test can hang for a long time if DNS is not functioning
 
32
# my $s1 = new SNMP::Session (DestHost => $bad_host );
 
33
# ok(!defined($s1));
 
34
#print("\n");
 
35
#####################== 2 ====############################################
 
36
# Fire up a session.
 
37
    my $s2 =
 
38
    new SNMP::Session (DestHost=>$agent_host, Community=>$comm,
 
39
                       RemotePort=>$agent_port);
 
40
    ok(defined($s2));
 
41
######################==  3 ==== ##########################################
 
42
 
 
43
# Fire up a V3 session 
 
44
my $s3 = new SNMP::Session (Version => 3 , RemotePort => $agent_port, 
 
45
                            SecName => $sec_name );
 
46
ok(defined($s3));
 
47
#print STDERR "Error string1 = $s3->{ErrorStr}:$s3->{ErrorInd}\n";
 
48
#print("\n");
 
49
#####################=== 4 ====###########################################
 
50
#create a V3 session by setting an IP address/port not running an agent
 
51
my $s4 = new SNMP::Session (Version => 3, RemotePort => 1002, Retries => 0);
 
52
# engineId discovery should fail resulting in session creation failure (undef)
 
53
ok(!defined($s4));
 
54
#print STDERR "Error string1 = $s4->{ErrorStr}:$s4->{ErrorInd}\n";
 
55
#print("\n");
 
56
######################  5  ###########################################
 
57
#create a session with bad version
 
58
my $s5 = new SNMP::Session (Version=>$bad_version);
 
59
ok(!defined($s5));
 
60
#print("\n");
 
61
########################  6  ########################################
 
62
#Test for v3 session creation success
 
63
my $s6 = new SNMP::Session (Version => 3, RemotePort => $agent_port,
 
64
                            SecLevel => 'authPriv', 
 
65
                            SecName => $sec_name, 
 
66
                            PrivPass => $priv_pass, 
 
67
                            AuthPass => $auth_pass);
 
68
ok(defined($s6));
 
69
#print STDERR "Error string2 = $s6->{ErrorStr}:$s6->{ErrorInd}\n";
 
70
#print("\n");
 
71
#####################  7  ############################################
 
72
 
 
73
snmptest_cleanup();