File: 04change2-pg.t

package info (click to toggle)
pbnj 2.04-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 640 kB
  • ctags: 309
  • sloc: perl: 4,838; xml: 748; sh: 109; makefile: 37
file content (183 lines) | stat: -rwxr-xr-x 6,866 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/perl


use strict;
#use blib;
use File::Spec;
use Cwd;
use DBI;
use File::Copy;
use Test::DatabaseRow;
use Test::More tests => 29;
my $test_file = 'change2.xml';
use vars qw($host $np $session $svc $os $FH);

is(system("sudo ./scanpbnj -x t/$test_file > /dev/null"),0,"Scanpbnj input from $test_file");

#my $dbh = DBI->connect('dbi:SQLite:dbname=data.dbl');
my $dsn = "DBI:Pg:database=pbnjdb;host=localhost;port=5432";
my $dbh = DBI->connect( $dsn, "pbnjdb", "tmp" );

# set the default database handle
local $Test::DatabaseRow::dbh = $dbh;

# service 25
testService( {
        service         => 'ssh',
        port            => 22,
        proto           => 'tcp',
        version         => '4.2p1 Debian-7ubuntu3',
        state           => 'up',
        banner          => 'OpenSSH',
        updated_on      => 'Sat May 27 19:02:53 2006',
        machine_updated => '1148770973'
        });
testService( {
        service         => 'ipp',
        port            => 631,
        proto           => 'tcp',
        version         => '1.2',
        state           => 'up',
        banner          => 'CUPS',
        updated_on      => 'Sat May 27 19:02:53 2006',
        machine_updated => '1148770973'
        });
testService( {
        service         => 'smtp',
        port            => 25,
        proto           => 'tcp',
        version         => 'unknown version',
        state           => 'up',
        banner          => 'Postfix smtpd',
        updated_on      => 'Sat May 27 19:02:53 2006',
        machine_updated => '1148770973'
        });

testServiceChange( {
        service         => 'ssh',
        port            => 22,
        proto           => 'tcp',
        version         => '4.2p1 Debian-7ubuntu3',
        state           => 'down',
        banner          => 'OpenSSH',
        updated_on      => 'Sat May 27 19:03:24 2006',
        machine_updated => '1148771004'
        });
#system("./04change3.t");






sub testService{
   my ($href) = @_;

   die "testService: port not defined"      unless defined $href->{port};
   die "testService: service not defined" unless defined $href->{service};
   die "testService: version not defined"    unless defined $href->{version};
   die "testService: proto not defined"  unless defined $href->{proto};
   die "testService: state not defined"      unless defined $href->{state};
   die "testService: updated_on not defined" unless defined $href->{updated_on};
   die "testService: machine_updated not defined"
     unless defined $href->{machine_updated};

   my $service         = $href->{service};
   my $port            = $href->{port};
   my $version         = $href->{version};
   my $proto           = $href->{proto};
   my $state           = $href->{state};
   my $updated         = $href->{updated_on};
   my $machine_updated = $href->{machine_updated};


    row_ok( 
        sql   => "SELECT service FROM services WHERE mid = '1' and port=$port",
        tests => [ service => $service ],
        label => "Testing table:service port $port element:service");
    row_ok( 
        sql   => "SELECT port FROM services WHERE mid = '1' and port=$port",
        tests => [ port => $port ],
        label => "Testing table:service element:port");
    row_ok( 
        sql   => "SELECT protocol FROM services WHERE mid = '1' and
port=$port",        
        tests => [ protocol => $proto ],
        label => "Testing table:service element:protocol");

    row_ok( 
        sql   => "SELECT state FROM services WHERE mid = '1' and port=$port",
        tests => [ state => $state ],
        label => "Testing table:service element:state");

    row_ok( 
        sql   => "SELECT version FROM services WHERE mid = '1' and port=$port",
        tests => [ version => $version ],
        label => "Testing table:service element:protocol");

    row_ok( 
        sql   => "SELECT machine_updated FROM services WHERE mid = '1'  and
        port=$port",
        tests => [ machine_updated => $machine_updated ],
        label => "Testing table:service element:machine_updated");

    row_ok( 
        sql   => "SELECT updated_on FROM services WHERE mid = '1' and port=$port",
        tests => [ updated_on => $updated ],
        label => "Testing table:service element:updated_on");
 }


sub testServiceChange{
 my ($href) = @_;

   die "testService: port not defined"      unless defined $href->{port};
   die "testService: service not defined" unless defined $href->{service};
   die "testService: version not defined"    unless defined $href->{version};
   die "testService: proto not defined"  unless defined $href->{proto};
   die "testService: state not defined"      unless defined $href->{state};
   die "testService: updated_on not defined" unless defined $href->{updated_on};   
   die "testService: machine_updated not defined" unless defined $href->{machine_updated};

   my $service         = $href->{service};
   my $port            = $href->{port};
   my $version         = $href->{version};
   my $proto           = $href->{proto};
   my $state           = $href->{state};
   my $updated         = $href->{updated_on};
   my $machine_updated = $href->{machine_updated};

    row_ok(
        sql   => "SELECT service FROM services WHERE mid = '1' and port=$port",
        tests => [ service => $service ],
        label => "Testing table:service port $port element:service");
    row_ok(
        sql   => "SELECT port FROM services WHERE mid = '1' and port=$port",
        tests => [ port => $port ],
        label => "Testing table:service element:port");
    row_ok(
        sql   => "SELECT protocol FROM services WHERE mid = '1' and port=$port",
        tests => [ protocol => $proto ],
        label => "Testing table:service element:protocol");
    row_ok(
        sql   => "SELECT state FROM services WHERE mid = '1' and port=$port and machine_updated=$machine_updated",
        tests => [ state => $state ],
        label => "Testing table:service element:state");

    row_ok(
        sql   => "SELECT version FROM services WHERE mid = '1' and port=$port",
        tests => [ version => $version ],
        label => "Testing table:service element:protocol");

    row_ok(
        sql   => "SELECT machine_updated FROM services WHERE mid = '1' and
port=$port and machine_updated=$machine_updated",
        tests => [ machine_updated => $machine_updated ],
        label => "Testing table:service element:machine_updated");

    row_ok(
        sql   => "SELECT updated_on FROM services WHERE mid = '1' and port=$port and machine_updated=$machine_updated",
        tests => [ updated_on => $updated ],
        label => "Testing table:service element:updated_on");
 }