Commit | Line | Data |
f54428ab |
1 | #!/usr/bin/env perl -T |
83542a7d |
2 | |
3 | # the above line forces Test::Harness into taint-mode |
f54428ab |
4 | # DO NOT REMOVE |
83542a7d |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
9f72d93a |
9 | # When in taint mode, PERL5LIB is ignored (but *not* unset) |
10 | # Put it back in INC so that local-lib users can actually |
11 | # run this test |
12 | use Config; |
13 | BEGIN { |
14 | for (map { defined $ENV{$_} ? $ENV{$_} : () } (qw/PERLLIB PERL5LIB/) ) { # we unshift, so reverse precedence |
15 | my ($envvar) = ($_ =~ /^(.+)$/); # untaint |
16 | unshift @INC, map { length($_) ? $_ : () } (split /\Q$Config{path_sep}\E/, $envvar); |
17 | } |
18 | } |
19 | |
689e22d1 |
20 | # We need to specify 'lib' here as well because even if it was already in |
21 | # @INC, the above will have put our local::lib in front of it, so now an |
22 | # installed DBIx::Class will take precedence over the one we're trying to test. |
23 | # In some cases, prove will have supplied ./lib as an absolute path so it |
24 | # doesn't seem worth trying to remove the second copy since it won't hurt |
25 | # anything. |
26 | use lib qw(lib); |
27 | use lib qw(t/lib); |
28 | |
91b0ad0b |
29 | use Test::More; |
f54428ab |
30 | use Test::Exception; |
8d6b1478 |
31 | use DBICTest; |
83542a7d |
32 | |
f54428ab |
33 | throws_ok ( |
34 | sub { $ENV{PATH} . (kill (0)) }, |
35 | qr/Insecure dependency in kill/, |
36 | 'taint mode active' |
37 | ); |
83542a7d |
38 | |
f54428ab |
39 | { |
40 | package DBICTest::Taint::Classes; |
83542a7d |
41 | |
f54428ab |
42 | use Test::More; |
43 | use Test::Exception; |
91b0ad0b |
44 | |
f54428ab |
45 | use base qw/DBIx::Class::Schema/; |
91b0ad0b |
46 | |
f54428ab |
47 | lives_ok (sub { |
48 | __PACKAGE__->load_classes(qw/Manual/); |
49 | ok( __PACKAGE__->source('Manual'), 'The Classes::Manual source has been registered' ); |
50 | __PACKAGE__->_unregister_source (qw/Manual/); |
51 | }, 'Loading classes with explicit load_classes worked in taint mode' ); |
91b0ad0b |
52 | |
f54428ab |
53 | lives_ok (sub { |
54 | __PACKAGE__->load_classes(); |
55 | ok( __PACKAGE__->source('Auto'), 'The Classes::Auto source has been registered' ); |
56 | ok( __PACKAGE__->source('Auto'), 'The Classes::Manual source has been re-registered' ); |
57 | }, 'Loading classes with Module::Find/load_classes worked in taint mode' ); |
58 | } |
83542a7d |
59 | |
f54428ab |
60 | { |
61 | package DBICTest::Taint::Namespaces; |
83542a7d |
62 | |
f54428ab |
63 | use Test::More; |
64 | use Test::Exception; |
91b0ad0b |
65 | |
f54428ab |
66 | use base qw/DBIx::Class::Schema/; |
83542a7d |
67 | |
f54428ab |
68 | lives_ok (sub { |
69 | __PACKAGE__->load_namespaces(); |
70 | ok( __PACKAGE__->source('Test'), 'The Namespaces::Test source has been registered' ); |
71 | }, 'Loading classes with Module::Find/load_namespaces worked in taint mode' ); |
72 | } |
91b0ad0b |
73 | |
f54428ab |
74 | done_testing; |