Fix ::Sybase::ASE incorrect attempt to retrieve an autoinc on blob inserts
[dbsrgits/DBIx-Class.git] / t / 54taint.t
index d6e3535..6b866e6 100644 (file)
@@ -1,16 +1,52 @@
-#!/usr/bin/env perl -T
-
-# the above line forces Test::Harness into taint-mode
-# DO NOT REMOVE
-
 use strict;
 use warnings;
+use Config;
+
+# there is talk of possible perl compilations where -T is fatal or just
+# doesn't work. We don't want to have the user deal with that.
+BEGIN { unless ($INC{'t/lib/DBICTest/WithTaint.pm'}) {
+
+  if ( $^O eq 'MSWin32' and $^X =~ /\x20/ ) {
+    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";
+    exit 0;
+  }
+
+  # it is possible the test itself is initially invoked in taint mode
+  # and with relative paths *and* with a relative $^X and some other
+  # craziness... in short: just be proactive
+  require File::Spec;
+
+  if (length $ENV{PATH}) {
+    ( $ENV{PATH} ) = join ( $Config{path_sep},
+      map { length($_) ? File::Spec->rel2abs($_) : () }
+        split /\Q$Config{path_sep}/, $ENV{PATH}
+    ) =~ /\A(.+)\z/;
+  }
+
+  my ($perl) = $^X =~ /\A(.+)\z/;
+
+  {
+    local $ENV{PATH} = "/nosuchrootbindir";
+    system( $perl => -T => -e => '
+      use warnings;
+      use strict;
+      eval { my $x = $ENV{PATH} . (kill (0)); 1 } or exit 42;
+      exit 0;
+    ');
+  }
+
+  if ( ($? >> 8) != 42 ) {
+    print "1..0 # SKIP Your perl does not seem to like/support -T...\n";
+    exit 0;
+  }
+
+  exec( $perl, qw( -I. -Mt::lib::DBICTest::WithTaint -T ), __FILE__ );
+}}
 
 # When in taint mode, PERL5LIB is ignored (but *not* unset)
 # Put it back in INC so that local-lib users can actually
 # run this test. Use lib.pm instead of an @INC unshift as
 # it will correctly add any arch subdirs encountered
-use Config;
 
 use lib (
   grep { length }
@@ -35,7 +71,7 @@ throws_ok (
   sub { $ENV{PATH} . (kill (0)) },
   qr/Insecure dependency in kill/,
   'taint mode active'
-);
+) if length $ENV{PATH};
 
 {
   package DBICTest::Taint::Classes;
@@ -72,4 +108,13 @@ throws_ok (
   }, 'Loading classes with Module::Find/load_namespaces worked in taint mode' );
 }
 
+# check that we can create a database and all
+{
+  my $s = DBICTest->init_schema( sqlite_use_file => 1 );
+  my $art = $s->resultset('Artist')->search({}, {
+    prefetch => 'cds', order_by => 'artistid',
+  })->next;
+  is ($art->artistid, 1, 'got artist');
+}
+
 done_testing;