|
| 1 | +BEGIN { chdir 't' if -d 't' } |
| 2 | + |
| 3 | +use lib '../lib'; |
| 4 | + |
| 5 | +use strict; |
| 6 | +use File::Spec; |
| 7 | +use File::Path; |
| 8 | +use Test::More; |
| 9 | +use Config; |
| 10 | + |
| 11 | +my $win32_symlink_enabled = 0; |
| 12 | + |
| 13 | +if($^O =~ /MSWin32/i && $Config{d_symlink}) { |
| 14 | + # Creation of symlinks is available to this system, |
| 15 | + # but might not have been enabled. We check on this |
| 16 | + # by checking whether symlink() actually works. |
| 17 | + |
| 18 | + if(-e '../Makefile.PL') { |
| 19 | + symlink '../Makefile.PL', 'make.sym'; |
| 20 | + if(-e 'make.sym') { |
| 21 | + $win32_symlink_enabled = 1; |
| 22 | + unlink 'make.sym'; |
| 23 | + } |
| 24 | + } |
| 25 | + else { |
| 26 | + warn "Cannot establish whether symlink() is enabled as Makefile.PL was not found"; |
| 27 | + $win32_symlink_enabled = 1; # We have no reason to assume otherwise. |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +### developer tests mostly |
| 32 | +if (($^O !~ /(linux|bsd|darwin|solaris|hpux|aix| |
| 33 | + sunos|dynixptx|haiku|irix|next|dec_osf|svr4|sco_sv|unicos| |
| 34 | + cygwin)/x and !$Config{d_symlink}) |
| 35 | + || |
| 36 | + ($^O =~ /MSWin/i and !$win32_symlink_enabled)) { |
| 37 | + plan skip_all => "Skipping tests on this platform"; |
| 38 | +} |
| 39 | +plan 'no_plan'; |
| 40 | + |
| 41 | +my $Class = 'Archive::Tar'; |
| 42 | +my $Dir = File::Spec->catdir( qw[src linktest] ); |
| 43 | +my %Map = ( |
| 44 | + File::Spec->catfile( $Dir, "linktest_with_dir.tar" ) => [ |
| 45 | + [ 0, qr/SECURE EXTRACT MODE/ ], |
| 46 | + [ 1, qr/^$/ ] |
| 47 | + ], |
| 48 | + File::Spec->catfile( $Dir, "linktest_missing_dir.tar" ) => [ |
| 49 | + [ 0, qr/SECURE EXTRACT MODE/ ], |
| 50 | + [ 0, qr/Could not create directory/ ], |
| 51 | + ], |
| 52 | +); |
| 53 | + |
| 54 | +use_ok( $Class ); |
| 55 | + |
| 56 | +{ while( my($file, $aref) = each %Map ) { |
| 57 | + |
| 58 | + for my $mode ( 0, 1 ) { |
| 59 | + my $expect = $aref->[$mode]->[0]; |
| 60 | + my $regex = $aref->[$mode]->[1]; |
| 61 | + |
| 62 | + my $tar = $Class->new( $file ); |
| 63 | + ok( $tar, "Object created from $file" ); |
| 64 | + |
| 65 | + ### damn warnings |
| 66 | + local $Archive::Tar::INSECURE_EXTRACT_MODE = $mode; |
| 67 | + local $Archive::Tar::INSECURE_EXTRACT_MODE = $mode; |
| 68 | + |
| 69 | + ok( 1, " Extracting with insecure mode: $mode" ); |
| 70 | + |
| 71 | + my $warning; |
| 72 | + local $SIG{__WARN__} = sub { $warning .= "@_" }; |
| 73 | + |
| 74 | + my $rv = eval { $tar->extract } || 0; |
| 75 | + ok( !$@, " No fatal error" ); |
| 76 | + is( !!$rv, !!$expect, " RV as expected" ); |
| 77 | + like( $warning, $regex, " Error matches $regex" ); |
| 78 | + |
| 79 | + rmtree( 'linktest' ); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments