line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::ValidOp::Test; |
2
|
18
|
|
|
18
|
|
119468
|
use strict; |
|
18
|
|
|
|
|
47
|
|
|
18
|
|
|
|
|
635
|
|
3
|
18
|
|
|
18
|
|
95
|
use warnings; |
|
18
|
|
|
|
|
34
|
|
|
18
|
|
|
|
|
697
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
require Exporter; |
6
|
18
|
|
|
|
|
2686
|
use vars qw/ |
7
|
|
|
|
|
|
|
@ISA @EXPORT |
8
|
|
|
|
|
|
|
$one $tmp @tmp %tmp |
9
|
|
|
|
|
|
|
$vars1 $ops1 $ops2 $ops3 |
10
|
18
|
|
|
18
|
|
204
|
/; |
|
18
|
|
|
|
|
35
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = qw/ Exporter /; |
13
|
|
|
|
|
|
|
@EXPORT = qw/ |
14
|
|
|
|
|
|
|
$vars1 $ops1 $ops2 $ops3 |
15
|
|
|
|
|
|
|
&check_taint &check_check |
16
|
|
|
|
|
|
|
&init_param |
17
|
|
|
|
|
|
|
&init_obj |
18
|
|
|
|
|
|
|
init_obj_via_cgi_pm |
19
|
|
|
|
|
|
|
/; |
20
|
|
|
|
|
|
|
|
21
|
18
|
|
|
18
|
|
168
|
use Carp; |
|
18
|
|
|
|
|
36
|
|
|
18
|
|
|
|
|
1432
|
|
22
|
18
|
|
|
18
|
|
38871
|
use Data::Dumper; |
|
18
|
|
|
|
|
242387
|
|
|
18
|
|
|
|
|
1763
|
|
23
|
18
|
|
|
18
|
|
17347
|
use Test::More; |
|
18
|
|
|
|
|
368808
|
|
|
18
|
|
|
|
|
181
|
|
24
|
18
|
|
|
18
|
|
35126
|
use Test::Taint; |
|
18
|
|
|
|
|
78255
|
|
|
18
|
|
|
|
|
118
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# {{{ data 1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
27
|
|
|
|
|
|
|
$vars1 = { |
28
|
|
|
|
|
|
|
name => 'Mouse-a-meal', |
29
|
|
|
|
|
|
|
item => 'Cat food', |
30
|
|
|
|
|
|
|
price => '10.99', |
31
|
|
|
|
|
|
|
shipping => 'FedEx', |
32
|
|
|
|
|
|
|
client_email => 'whitemice@hyperintelligent_pandimensional_beings.com', |
33
|
|
|
|
|
|
|
no_client => 1, |
34
|
|
|
|
|
|
|
client => undef, |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$ops1 = { |
38
|
|
|
|
|
|
|
add => { |
39
|
|
|
|
|
|
|
name => [ 'item brand name', 'required' ], |
40
|
|
|
|
|
|
|
item => [ 'item name', 'required' ], |
41
|
|
|
|
|
|
|
number => [ 'item number', 'required' ], |
42
|
|
|
|
|
|
|
shipping => [ 'shipping method', 'required' ], |
43
|
|
|
|
|
|
|
client => [ 'client name', 'alternative(no_client)' ], |
44
|
|
|
|
|
|
|
no_client => [ 'no client option' ], |
45
|
|
|
|
|
|
|
client_email => [ 'client email address', 'email' ], |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
remove => { |
49
|
|
|
|
|
|
|
number => [ 'item number', 'required' ], |
50
|
|
|
|
|
|
|
item => [ 'item name', 'required' ], |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$ops2 = { |
55
|
|
|
|
|
|
|
add => { |
56
|
|
|
|
|
|
|
stuff => { |
57
|
|
|
|
|
|
|
name => [ 'item brand name', 'required' ], |
58
|
|
|
|
|
|
|
item => [ 'item name', 'required' ], |
59
|
|
|
|
|
|
|
number => [ 'item number', 'required' ], |
60
|
|
|
|
|
|
|
shipping => [ 'shipping method', 'required' ], |
61
|
|
|
|
|
|
|
client => [ 'client name', 'alternative(no_client)' ], |
62
|
|
|
|
|
|
|
no_client => [ 'no client option' ], |
63
|
|
|
|
|
|
|
client_email => [ 'client email address', 'email' ], |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$ops3 = { |
69
|
|
|
|
|
|
|
add => { |
70
|
|
|
|
|
|
|
stuff => { |
71
|
|
|
|
|
|
|
-construct_object => 'Stuff', |
72
|
|
|
|
|
|
|
name => [ 'item brand name', 'required' ], |
73
|
|
|
|
|
|
|
item => [ 'item name', 'required' ], |
74
|
|
|
|
|
|
|
number => [ 'item number', 'required' ], |
75
|
|
|
|
|
|
|
shipping => [ 'shipping method', 'required' ], |
76
|
|
|
|
|
|
|
client => [ 'client name', 'alternative(no_client)' ], |
77
|
|
|
|
|
|
|
no_client => [ 'no client option' ], |
78
|
|
|
|
|
|
|
client_email => [ 'client email address', 'email' ], |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
# }}} |
83
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
84
|
|
|
|
|
|
|
sub check_check { |
85
|
412
|
|
|
412
|
0
|
41203
|
my( $check_name, $value, $expect_value, $expect_tainted, $errmsg ) = @_; |
86
|
|
|
|
|
|
|
|
87
|
18
|
|
|
18
|
|
6067
|
no warnings qw/ uninitialized /; # many of these values are optional |
|
18
|
|
|
|
|
57
|
|
|
18
|
|
|
|
|
12256
|
|
88
|
|
|
|
|
|
|
|
89
|
412
|
|
|
|
|
1575
|
taint_checking_ok( undef ); |
90
|
412
|
|
|
|
|
199940
|
taint( $value ); |
91
|
412
|
|
|
|
|
6089
|
tainted_ok( $value ); |
92
|
|
|
|
|
|
|
|
93
|
412
|
100
|
|
|
|
215094
|
my $test_id = $errmsg |
94
|
|
|
|
|
|
|
? "testing: $value fails with $check_name" |
95
|
|
|
|
|
|
|
: "testing: $value = $expect_value with $check_name"; |
96
|
|
|
|
|
|
|
|
97
|
412
|
|
|
|
|
2946
|
my $caller = join ' : ' => ( caller() )[ 1, 2 ]; |
98
|
412
|
|
|
|
|
3318
|
my $param = CGI::ValidOp::Param->new({ name => 'tester', label => 'William Blake' }); |
99
|
412
|
|
|
|
|
3041
|
ok( $param->isa( 'CGI::ValidOp::Param' ), $test_id ); |
100
|
|
|
|
|
|
|
|
101
|
412
|
|
|
|
|
204004
|
my $new_value; |
102
|
412
|
|
|
|
|
791
|
eval{ $new_value = $param->check( $value, $check_name )}; |
|
412
|
|
|
|
|
1576
|
|
103
|
412
|
50
|
66
|
|
|
1356
|
croak "Unexpected check failure: $@" |
104
|
|
|
|
|
|
|
if $@ and $expect_value ne 'DIE'; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# if we tell it to expect 'DIE', then it should die and we match |
107
|
|
|
|
|
|
|
# $@ against the expected error message |
108
|
412
|
100
|
|
|
|
1951
|
defined $expect_value and $expect_value eq 'DIE' |
|
|
100
|
|
|
|
|
|
109
|
|
|
|
|
|
|
? like( $@, qr/$errmsg/, $caller ) |
110
|
|
|
|
|
|
|
: is( $new_value, $expect_value, $caller ); |
111
|
412
|
100
|
|
|
|
164315
|
$expect_tainted |
112
|
|
|
|
|
|
|
? tainted_ok( $new_value, $caller ) |
113
|
|
|
|
|
|
|
: untainted_ok( $new_value, $caller ); |
114
|
118
|
|
|
|
|
516
|
$errmsg and !( $expect_value and $expect_value eq 'DIE' ) |
115
|
412
|
100
|
66
|
|
|
211402
|
? like( @{ $param->errors }[0], qr/$errmsg/, $caller ) |
|
|
100
|
|
|
|
|
|
116
|
|
|
|
|
|
|
: is( $param->errors, undef, $caller ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
120
|
|
|
|
|
|
|
sub init_param { |
121
|
0
|
|
|
0
|
0
|
0
|
my $spec = shift; |
122
|
0
|
|
|
|
|
0
|
ok( my $param = CGI::ValidOp::Param->new( $spec )); |
123
|
0
|
|
|
|
|
0
|
$param; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
127
|
|
|
|
|
|
|
sub init_obj { |
128
|
5
|
|
|
5
|
0
|
94
|
$ENV{ REQUEST_METHOD } = 'GET'; |
129
|
5
|
|
|
|
|
64
|
$ENV{ QUERY_STRING } = join '&', |
130
|
|
|
|
|
|
|
"comment=Now is the time for\nall good men\nto come to the aid", |
131
|
|
|
|
|
|
|
'crackme=$ENV{ meat_of_evil }', |
132
|
|
|
|
|
|
|
'date=2004-09-29', |
133
|
|
|
|
|
|
|
'name=Mouse-a-meal', |
134
|
|
|
|
|
|
|
'item=Cat food', |
135
|
|
|
|
|
|
|
'multi=banana', |
136
|
|
|
|
|
|
|
'multi=orange', |
137
|
|
|
|
|
|
|
'multi=plum', |
138
|
|
|
|
|
|
|
'notdefined=', |
139
|
|
|
|
|
|
|
'op=add', |
140
|
|
|
|
|
|
|
'price=10.99', |
141
|
|
|
|
|
|
|
'shipping=FedEx', |
142
|
|
|
|
|
|
|
'unexpect=I am the slime', |
143
|
|
|
|
|
|
|
'checkme=ON', |
144
|
|
|
|
|
|
|
'donotcheckme=', |
145
|
|
|
|
|
|
|
'xssme=', |
146
|
|
|
|
|
|
|
'client_email=whitemice@hyperintelligent_pandimensional_beings.com', |
147
|
|
|
|
|
|
|
'no_client=1', |
148
|
|
|
|
|
|
|
'client=disappear', |
149
|
|
|
|
|
|
|
; |
150
|
5
|
|
|
|
|
87
|
my $obj = CGI::ValidOp->new ( @_ ); |
151
|
5
|
|
|
|
|
84
|
ok( $obj->isa( 'CGI::ValidOp' )); |
152
|
5
|
|
|
|
|
4084
|
return $obj; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub init_obj_via_cgi_pm { |
156
|
2
|
|
|
2
|
0
|
1944
|
my ($params, $ops) = @_; |
157
|
|
|
|
|
|
|
|
158
|
2
|
|
|
|
|
15
|
my $q = new CGI; |
159
|
2
|
|
|
|
|
9809
|
$q->param( -name => $_, -value => $params->{$_} ) foreach (keys %$params); |
160
|
2
|
|
|
|
|
1508
|
return CGI::ValidOp->new({ -cgi_object => $q, %$ops}); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__END__ |