Ignore:
Timestamp:
11/11/11 13:17:43 (20 months ago)
Author:
BrainSlayer
Message:

update proftp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/router/proftpd/tests/t/lib/ProFTPD/Tests/Config/Directory/Lookups.pm

    r14672 r17876  
    22 
    33use lib qw(t/lib); 
    4 use base qw(Test::Unit::TestCase ProFTPD::TestSuite::Child); 
     4use base qw(ProFTPD::TestSuite::Child); 
    55use strict; 
    66 
    77use Data::Dumper; 
    8 use File::Path qw(mkpath rmtree); 
     8use File::Path qw(mkpath); 
    99use File::Spec; 
    1010use IO::Handle; 
     
    3535 
    3636  dir_lookup_deep_layout_rel_paths => { 
     37    order => ++$order, 
     38    test_class => [qw(bug forking slow)], 
     39  }, 
     40 
     41  dir_lookup_many_files_hidefiles_bug3526 => { 
    3742    order => ++$order, 
    3843    test_class => [qw(bug forking slow)], 
     
    5964#  return testsuite_get_runnable_tests($TESTS); 
    6065  return qw( 
    61     dir_lookup_wide_layout_abs_paths 
    62     dir_lookup_deep_layout_abs_paths 
     66    dir_lookup_many_files_hidefiles_bug3526 
    6367  ); 
    6468} 
     
    6670sub set_up { 
    6771  my $self = shift; 
    68   $self->{tmpdir} = testsuite_get_tmp_dir(); 
    69  
    70   # Create temporary scratch dir 
    71   eval { mkpath($self->{tmpdir}) }; 
    72   if ($@) { 
    73     my $abs_path = File::Spec->rel2abs($self->{tmpdir}); 
    74     die("Can't create dir $abs_path: $@"); 
    75   } 
     72  $self->SUPER::set_up(@_); 
    7673 
    7774  make_name(0, 0); 
    78 } 
    79  
    80 sub tear_down { 
    81   my $self = shift; 
    82  
    83   # Remove temporary scratch dir 
    84   if ($self->{tmpdir}) { 
    85     eval { 
    86       local $SIG{__WARN__} = sub {}; 
    87       rmtree($self->{tmpdir}); 
    88     }; 
    89   } 
    90  
    91   undef $self; 
    9275} 
    9376 
     
    928911} 
    929912 
     913sub dir_lookup_many_files_hidefiles_bug3526 { 
     914  my $self = shift; 
     915  my $tmpdir = $self->{tmpdir}; 
     916 
     917  my $config_file = "$tmpdir/dir.conf"; 
     918  my $pid_file = File::Spec->rel2abs("$tmpdir/dir.pid"); 
     919  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/dir.scoreboard"); 
     920 
     921  my $log_file = File::Spec->rel2abs('tests.log'); 
     922 
     923  my $auth_user_file = File::Spec->rel2abs("$tmpdir/dir.passwd"); 
     924  my $auth_group_file = File::Spec->rel2abs("$tmpdir/dir.group"); 
     925 
     926  my $user = 'proftpd'; 
     927  my $passwd = 'test'; 
     928  my $home_dir = File::Spec->rel2abs($tmpdir); 
     929  my $uid = 500; 
     930  my $gid = 500; 
     931 
     932  # Make sure that, if we're running as root, that the home directory has 
     933  # permissions/privs set for the account we create 
     934  if ($< == 0) { 
     935    unless (chmod(0755, $home_dir)) { 
     936      die("Can't set perms on $home_dir to 0755: $!"); 
     937    } 
     938 
     939    unless (chown($uid, $gid, $home_dir)) { 
     940      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     941    } 
     942  } 
     943  
     944  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     945    '/bin/bash'); 
     946  auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     947 
     948  my $timeout = 300; 
     949 
     950  my $config = { 
     951    PidFile => $pid_file, 
     952    ScoreboardFile => $scoreboard_file, 
     953    SystemLog => $log_file, 
     954    TraceLog => $log_file, 
     955    Trace => 'DEFAULT:10 auth:0 config:0 directory:10 fsio:10 lock:0 ftpaccess:10', 
     956 
     957    AuthUserFile => $auth_user_file, 
     958    AuthGroupFile => $auth_group_file, 
     959 
     960    AllowOverride => 'on', 
     961    TimeoutIdle => $timeout, 
     962    TimeoutLogin => $timeout, 
     963 
     964    Directory => { 
     965      '/' => { 
     966        Umask => '066 077', 
     967      }, 
     968    }, 
     969 
     970    IfModules => { 
     971      'mod_delay.c' => { 
     972        DelayEngine => 'off', 
     973      }, 
     974    }, 
     975  }; 
     976 
     977  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     978 
     979  # Create 1500 files in the target directory. 
     980 
     981  my $count = 1500; 
     982  print STDOUT "# Creating $count files\n"; 
     983 
     984  my $test_dir = File::Spec->rel2abs("$tmpdir/" . make_name(1, 1)); 
     985  mkpath($test_dir); 
     986 
     987  for (my $i = 0; $i < $count; $i++) { 
     988    my $test_file = File::Spec->rel2abs(File::Spec->catdir($test_dir, 
     989      make_name(5, 1))); 
     990    $test_file .= ".txt"; 
     991 
     992    if (open(my $fh, "> $test_file")) { 
     993      close($fh); 
     994 
     995    } else { 
     996      die("Can't open $test_file: $!"); 
     997    } 
     998  } 
     999 
     1000  # Create a .ftpaccess file in the test directory with a simple HideFiles 
     1001  # pattern. 
     1002  my $ftpaccess_file = File::Spec->rel2abs("$test_dir/.ftpaccess"); 
     1003  if (open(my $fh, "> $ftpaccess_file")) { 
     1004    print $fh <<EOC; 
     1005HideFiles ^\\. 
     1006EOC 
     1007 
     1008    unless (close($fh)) { 
     1009      die("Can't write $ftpaccess_file: $!"); 
     1010    } 
     1011 
     1012  } else { 
     1013    die("Can't open $ftpaccess_file: $!"); 
     1014  } 
     1015 
     1016  # Open pipes, for use between the parent and child processes.  Specifically, 
     1017  # the child will indicate when it's done with its test by writing a message 
     1018  # to the parent. 
     1019  my ($rfh, $wfh); 
     1020  unless (pipe($rfh, $wfh)) { 
     1021    die("Can't open pipe: $!"); 
     1022  } 
     1023 
     1024  my $ex; 
     1025 
     1026  # Fork child 
     1027  $self->handle_sigchld(); 
     1028  defined(my $pid = fork()) or die("Can't fork: $!"); 
     1029  if ($pid) { 
     1030    eval { 
     1031      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port, undef, 
     1032        $timeout); 
     1033 
     1034      # Make sure the underlying Net::FTP uses our long timeout 
     1035      my $old_timeout = $client->{ftp}->timeout($timeout); 
     1036 
     1037      my $start_login = [gettimeofday()]; 
     1038      $client->login($user, $passwd, $timeout); 
     1039      my $login_elapsed = tv_interval($start_login); 
     1040      print STDOUT "# Login elapsed: ", Dumper($login_elapsed); 
     1041 
     1042      $client->cwd($test_dir); 
     1043 
     1044      my ($resp_code, $resp_msg); 
     1045 
     1046      my $nlst_start = [gettimeofday()]; 
     1047 
     1048      my $conn = $client->nlst_raw($test_dir); 
     1049      unless ($conn) { 
     1050        die("Failed to NLST $test_dir: " . $client->response_code() . 
     1051          " " . $client->response_msg()); 
     1052      } 
     1053 
     1054      my $buf; 
     1055      while ($conn->read($buf, 8192, $timeout)) { 
     1056        if ($ENV{TEST_VERBOSE}) { 
     1057          print STDERR "recvd: $buf\n"; 
     1058        } 
     1059      } 
     1060 
     1061      $conn->close(); 
     1062 
     1063      my $nlst_elapsed = tv_interval($nlst_start); 
     1064      print STDOUT "# NLST elapsed: ", Dumper($nlst_elapsed); 
     1065 
     1066      $resp_code = $client->response_code(); 
     1067      $resp_msg = $client->response_msg(); 
     1068 
     1069      $client->quit(); 
     1070 
     1071      my $expected; 
     1072 
     1073      $expected = 226; 
     1074      $self->assert($expected == $resp_code, 
     1075        test_msg("Expected '$expected', got '$resp_code'")); 
     1076 
     1077      $expected = "Transfer complete"; 
     1078      $self->assert($expected eq $resp_msg, 
     1079        test_msg("Expected '$expected', got '$resp_msg'")); 
     1080    }; 
     1081 
     1082    if ($@) { 
     1083      $ex = $@; 
     1084    } 
     1085 
     1086    $wfh->print("done\n"); 
     1087    $wfh->flush(); 
     1088 
     1089  } else { 
     1090    eval { server_wait($config_file, $rfh, $timeout + 5) }; 
     1091    if ($@) { 
     1092      warn($@); 
     1093      exit 1; 
     1094    } 
     1095 
     1096    exit 0; 
     1097  } 
     1098 
     1099  # Stop server 
     1100  server_stop($pid_file); 
     1101 
     1102  $self->assert_child_ok($pid); 
     1103 
     1104  if ($ex) { 
     1105    die($ex); 
     1106  } 
     1107 
     1108  unlink($log_file); 
     1109} 
     1110 
    93011111; 
Note: See TracChangeset for help on using the changeset viewer.