/usr/share/perl5/CGI/ValidOp/Test.pm is in libcgi-validop-perl 0.56-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 184 185 186 187 188 189 190 | package CGI::ValidOp::Test;
use strict;
use warnings;
require Exporter;
use vars qw/
@ISA @EXPORT
$one $tmp @tmp %tmp
$vars1 $ops1 $ops2 $ops3
/;
@ISA = qw/ Exporter /;
@EXPORT = qw/
$vars1 $ops1 $ops2 $ops3
&check_taint &check_check
&init_param
&init_obj
init_obj_via_cgi_pm
/;
use Carp;
use Data::Dumper;
use Test::More;
use Test::Taint;
# {{{ data 1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$vars1 = {
name => 'Mouse-a-meal',
item => 'Cat food',
price => '10.99',
shipping => 'FedEx',
client_email => 'whitemice@hyperintelligent_pandimensional_beings.com',
no_client => 1,
client => undef,
};
$ops1 = {
add => {
name => [ 'item brand name', 'required' ],
item => [ 'item name', 'required' ],
number => [ 'item number', 'required' ],
shipping => [ 'shipping method', 'required' ],
client => [ 'client name', 'alternative(no_client)' ],
no_client => [ 'no client option' ],
client_email => [ 'client email address', 'email' ],
},
remove => {
number => [ 'item number', 'required' ],
item => [ 'item name', 'required' ],
},
};
$ops2 = {
add => {
stuff => {
name => [ 'item brand name', 'required' ],
item => [ 'item name', 'required' ],
number => [ 'item number', 'required' ],
shipping => [ 'shipping method', 'required' ],
client => [ 'client name', 'alternative(no_client)' ],
no_client => [ 'no client option' ],
client_email => [ 'client email address', 'email' ],
}
}
};
$ops3 = {
add => {
stuff => {
-construct_object => 'Stuff',
name => [ 'item brand name', 'required' ],
item => [ 'item name', 'required' ],
number => [ 'item number', 'required' ],
shipping => [ 'shipping method', 'required' ],
client => [ 'client name', 'alternative(no_client)' ],
no_client => [ 'no client option' ],
client_email => [ 'client email address', 'email' ],
}
}
};
# }}}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sub check_check {
my( $check_name, $value, $expect_value, $expect_tainted, $errmsg ) = @_;
no warnings qw/ uninitialized /; # many of these values are optional
taint_checking_ok( undef );
taint( $value );
tainted_ok( $value );
my $test_id = $errmsg
? "testing: $value fails with $check_name"
: "testing: $value = $expect_value with $check_name";
my $caller = join ' : ' => ( caller() )[ 1, 2 ];
my $param = CGI::ValidOp::Param->new({ name => 'tester', label => 'William Blake' });
ok( $param->isa( 'CGI::ValidOp::Param' ), $test_id );
my $new_value;
eval{ $new_value = $param->check( $value, $check_name )};
croak "Unexpected check failure: $@"
if $@ and $expect_value ne 'DIE';
# if we tell it to expect 'DIE', then it should die and we match
# $@ against the expected error message
defined $expect_value and $expect_value eq 'DIE'
? like( $@, qr/$errmsg/, $caller )
: is( $new_value, $expect_value, $caller );
$expect_tainted
? tainted_ok( $new_value, $caller )
: untainted_ok( $new_value, $caller );
$errmsg and !( $expect_value and $expect_value eq 'DIE' )
? like( @{ $param->errors }[0], qr/$errmsg/, $caller )
: is( $param->errors, undef, $caller );
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sub init_param {
my $spec = shift;
ok( my $param = CGI::ValidOp::Param->new( $spec ));
$param;
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sub init_obj {
$ENV{ REQUEST_METHOD } = 'GET';
$ENV{ QUERY_STRING } = join '&',
"comment=Now is the time for\nall good men\nto come to the aid",
'crackme=$ENV{ meat_of_evil }',
'date=2004-09-29',
'name=Mouse-a-meal',
'item=Cat food',
'multi=banana',
'multi=orange',
'multi=plum',
'notdefined=',
'op=add',
'price=10.99',
'shipping=FedEx',
'unexpect=I am the slime',
'checkme=ON',
'donotcheckme=',
'xssme=<script>alert("haxored")</script>',
'client_email=whitemice@hyperintelligent_pandimensional_beings.com',
'no_client=1',
'client=disappear',
;
my $obj = CGI::ValidOp->new ( @_ );
ok( $obj->isa( 'CGI::ValidOp' ));
return $obj;
}
sub init_obj_via_cgi_pm {
my ($params, $ops) = @_;
my $q = new CGI;
$q->param( -name => $_, -value => $params->{$_} ) foreach (keys %$params);
return CGI::ValidOp->new({ -cgi_object => $q, %$ops});
}
1;
__END__
=head1 NAME
CGI::ValidOp::Test - test class for CGI::ValidOp and its associates.
=head1 DESCRIPTION
none yet
=head1 AUTHOR
Randall Hansen <legless@cpan.org>
=head1 COPYRIGHT
Copyright (c) 2003-2005 Randall Hansen. All rights reserved.
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
=cut
# $Id: Base.pm 40 2004-10-03 06:26:24Z soh $
|