1 BEGIN { $ENV{DBICTEST_ANFANG_DEFANG} = 1 }
3 # When in taint mode, PERL5LIB is ignored (but *not* unset)
4 # Put it back in INC so that local-lib users can actually
5 # run this test. Use lib.pm instead of an @INC unshift as
6 # it will correctly add any arch subdirs encountered
8 # Yes, this is a lazy solution: adding -I args in the exec below is the
9 # more sensible approach, but no time to properly do it at present
13 map { split /\Q$Config{path_sep}\E/, (/^(.*)$/)[0] } # untainting regex
15 @ENV{qw(PERL5LIB PERLLIB)} # precedence preserved by lib
21 # there is talk of possible perl compilations where -T is fatal or just
22 # doesn't work. We don't want to have the user deal with that.
23 BEGIN { unless ($INC{'t/lib/DBICTest/WithTaint.pm'}) {
25 if ( $^O eq 'MSWin32' and $^X =~ /\x20/ ) {
26 print "1..0 # SKIP Running this test on Windows with spaces within the perl executable path (\$^X) is not possible due to https://rt.perl.org/Ticket/Display.html?id=123907\n";
30 # it is possible the test itself is initially invoked in taint mode
31 # and with relative paths *and* with a relative $^X and some other
32 # craziness... in short: just be proactive
35 if (length $ENV{PATH}) {
36 ( $ENV{PATH} ) = join ( $Config{path_sep},
37 map { length($_) ? File::Spec->rel2abs($_) : () }
38 split /\Q$Config{path_sep}/, $ENV{PATH}
42 my ($perl) = $^X =~ /\A(.+)\z/;
45 local $ENV{PATH} = "/nosuchrootbindir";
46 system( $perl => -T => -e => '
49 eval { my $x = $ENV{PATH} . (kill (0)); 1 } or exit 42;
54 if ( ($? >> 8) != 42 ) {
55 print "1..0 # SKIP Your perl does not seem to like/support -T...\n";
59 exec( $perl, qw( -I. -Mt::lib::DBICTest::WithTaint -T ), __FILE__ );
62 # We need to specify 'lib' here as well because even if it was already in
63 # @INC, the above will have put our local::lib in front of it, so now an
64 # installed DBIx::Class will take precedence over the one we're trying to test.
65 # In some cases, prove will have supplied ./lib as an absolute path so it
66 # doesn't seem worth trying to remove the second copy since it won't hurt
68 use lib qw(t/lib lib);
75 sub { $ENV{PATH} . (kill (0)) },
76 qr/Insecure dependency in kill/,
78 ) if length $ENV{PATH};
81 package DBICTest::Taint::Classes;
86 use base qw/DBIx::Class::Schema/;
89 __PACKAGE__->load_classes(qw/Manual/);
90 ok( __PACKAGE__->source('Manual'), 'The Classes::Manual source has been registered' );
91 __PACKAGE__->_unregister_source (qw/Manual/);
92 }, 'Loading classes with explicit load_classes worked in taint mode' );
95 __PACKAGE__->load_classes();
96 ok( __PACKAGE__->source('Auto'), 'The Classes::Auto source has been registered' );
97 ok( __PACKAGE__->source('Auto'), 'The Classes::Manual source has been re-registered' );
98 }, 'Loading classes with Module::Find/load_classes worked in taint mode' );
102 package DBICTest::Taint::Namespaces;
107 use base qw/DBIx::Class::Schema/;
110 __PACKAGE__->load_namespaces();
111 ok( __PACKAGE__->source('Test'), 'The Namespaces::Test source has been registered' );
112 }, 'Loading classes with Module::Find/load_namespaces worked in taint mode' );
115 # check that we can create a database and all
117 my $s = DBICTest->init_schema( sqlite_use_file => 1 );
118 my $art = $s->resultset('Artist')->search({}, {
119 prefetch => 'cds', order_by => 'artistid',
121 is ($art->artistid, 1, 'got artist');