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

update proftp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/router/proftpd/tests/t/lib/ProFTPD/Tests/Config/TimeoutStalled.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 
    7 use File::Path qw(mkpath rmtree); 
    87use File::Spec; 
    98use IO::Handle; 
     
    2221  }, 
    2322 
    24   timeoutstalled_exceeded => { 
     23  timeoutstalled_exceeded_list => { 
    2524    order => ++$order, 
    2625    test_class => [qw(forking)], 
    2726  }, 
    2827 
     28  timeoutstalled_exceeded_nlst => { 
     29    order => ++$order, 
     30    test_class => [qw(forking)], 
     31  }, 
     32 
     33  timeoutstalled_exceeded_mlsd => { 
     34    order => ++$order, 
     35    test_class => [qw(forking)], 
     36  }, 
     37 
     38  timeoutstalled_exceeded_retr => { 
     39    order => ++$order, 
     40    test_class => [qw(forking)], 
     41  }, 
     42 
     43  timeoutstalled_exceeded_stor => { 
     44    order => ++$order, 
     45    test_class => [qw(forking)], 
     46  }, 
     47 
     48  timeoutstalled_exceeded_retr_usesendfile_on => { 
     49    order => ++$order, 
     50    test_class => [qw(feat_sendfile forking)], 
     51  }, 
     52 
    2953}; 
    3054 
     
    3761} 
    3862 
    39 sub set_up { 
    40   my $self = shift; 
    41   $self->{tmpdir} = testsuite_get_tmp_dir(); 
    42  
    43   # Create temporary scratch dir 
    44   eval { mkpath($self->{tmpdir}) }; 
    45   if ($@) { 
    46     my $abs_path = File::Spec->rel2abs($self->{tmpdir}); 
    47     die("Can't create dir $abs_path: $@"); 
    48   } 
    49 } 
    50  
    51 sub tear_down { 
    52   my $self = shift; 
    53  
    54   # Remove temporary scratch dir 
    55   if ($self->{tmpdir}) { 
    56     eval { rmtree($self->{tmpdir}) }; 
    57   } 
    58  
    59   undef $self; 
    60 }; 
    61  
    6263sub timeoutstalled_ok { 
    6364  my $self = shift; 
     
    7576  my $user = 'proftpd'; 
    7677  my $passwd = 'test'; 
     78  my $group = 'ftpd'; 
    7779  my $home_dir = File::Spec->rel2abs($tmpdir); 
    7880  my $uid = 500; 
     
    9395  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
    9496    '/bin/bash'); 
    95   auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     97  auth_group_write($auth_group_file, $group, $gid, $user); 
    9698 
    9799  my $timeout_stalled = 2; 
     
    145147 
    146148      my $buf; 
    147       $conn->read($buf, 8192); 
     149      $conn->read($buf, 8192, 30); 
    148150      $conn->close(); 
    149151 
     
    191193} 
    192194 
    193 sub timeoutstalled_exceeded { 
     195sub timeoutstalled_exceeded_list { 
    194196  my $self = shift; 
    195197  my $tmpdir = $self->{tmpdir}; 
     
    206208  my $user = 'proftpd'; 
    207209  my $passwd = 'test'; 
     210  my $group = 'ftpd'; 
    208211  my $home_dir = File::Spec->rel2abs($tmpdir); 
    209212  my $uid = 500; 
     
    224227  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
    225228    '/bin/bash'); 
    226   auth_group_write($auth_group_file, 'ftpd', $gid, $user); 
     229  auth_group_write($auth_group_file, $group, $gid, $user); 
    227230 
    228231  my $timeout_stalled = 1; 
     
    276279 
    277280      my $buf; 
    278       $conn->read($buf, 8192); 
     281      $conn->read($buf, 8192, 30); 
    279282      $conn->close(); 
    280283 
    281       my ($resp_code, $resp_msg); 
    282284      eval { $client->noop() }; 
    283285      unless ($@) { 
    284286        die("NOOP succeeded unexpectedly"); 
    285  
    286       } else { 
    287         $resp_code = $client->response_code(); 
    288         $resp_msg = $client->response_msg(); 
    289       } 
     287      } 
     288 
     289      my $resp_code = $client->response_code(); 
     290      my $resp_msg = $client->response_msg(); 
    290291 
    291292      my $expected; 
     
    331332} 
    332333 
     334sub timeoutstalled_exceeded_nlst { 
     335  my $self = shift; 
     336  my $tmpdir = $self->{tmpdir}; 
     337 
     338  my $config_file = "$tmpdir/config.conf"; 
     339  my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); 
     340  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); 
     341 
     342  my $log_file = File::Spec->rel2abs('tests.log'); 
     343 
     344  my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); 
     345  my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); 
     346 
     347  my $user = 'proftpd'; 
     348  my $passwd = 'test'; 
     349  my $group = 'ftpd'; 
     350  my $home_dir = File::Spec->rel2abs($tmpdir); 
     351  my $uid = 500; 
     352  my $gid = 500; 
     353 
     354  # Make sure that, if we're running as root, that the home directory has 
     355  # permissions/privs set for the account we create 
     356  if ($< == 0) { 
     357    unless (chmod(0755, $home_dir)) { 
     358      die("Can't set perms on $home_dir to 0755: $!"); 
     359    } 
     360     
     361    unless (chown($uid, $gid, $home_dir)) { 
     362      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     363    } 
     364  } 
     365 
     366  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     367    '/bin/bash'); 
     368  auth_group_write($auth_group_file, $group, $gid, $user); 
     369 
     370  my $timeout_stalled = 1; 
     371 
     372  my $config = { 
     373    PidFile => $pid_file, 
     374    ScoreboardFile => $scoreboard_file, 
     375    SystemLog => $log_file, 
     376 
     377    AuthUserFile => $auth_user_file, 
     378    AuthGroupFile => $auth_group_file, 
     379 
     380    TimeoutStalled => $timeout_stalled, 
     381 
     382    IfModules => { 
     383      'mod_delay.c' => { 
     384        DelayEngine => 'off', 
     385      }, 
     386    }, 
     387  }; 
     388 
     389  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     390 
     391  # Open pipes, for use between the parent and child processes.  Specifically, 
     392  # the child will indicate when it's done with its test by writing a message 
     393  # to the parent. 
     394  my ($rfh, $wfh); 
     395  unless (pipe($rfh, $wfh)) { 
     396    die("Can't open pipe: $!"); 
     397  } 
     398 
     399  my $ex; 
     400 
     401  # Fork child 
     402  $self->handle_sigchld(); 
     403  defined(my $pid = fork()) or die("Can't fork: $!"); 
     404  if ($pid) { 
     405    eval { 
     406      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     407 
     408      $client->login($user, $passwd); 
     409 
     410      my $conn = $client->nlst_raw($home_dir); 
     411      unless ($conn) { 
     412        die("NLST failed: " . $client->response_code() . " " . 
     413          $client->response_msg()); 
     414      } 
     415 
     416      # Wait for one second more than the stalled period 
     417      sleep($timeout_stalled + 1); 
     418 
     419      my $buf; 
     420      $conn->read($buf, 8192, 30); 
     421      $conn->close(); 
     422 
     423      eval { $client->noop() }; 
     424      unless ($@) { 
     425        die("NOOP succeeded unexpectedly"); 
     426      } 
     427 
     428      my $resp_code = $client->response_code(); 
     429      my $resp_msg = $client->response_msg(); 
     430 
     431      my $expected; 
     432 
     433      # Perl's Net::Cmd module uses a very non-standard 599 code to 
     434      # indicate that the connection is closed 
     435      $expected = 599; 
     436      $self->assert($expected == $resp_code, 
     437        test_msg("Expected $expected, got $resp_code")); 
     438 
     439      $expected = "Connection closed"; 
     440      $self->assert($expected eq $resp_msg, 
     441        test_msg("Expected '$expected', got '$resp_msg'")); 
     442    }; 
     443 
     444    if ($@) { 
     445      $ex = $@; 
     446    } 
     447 
     448    $wfh->print("done\n"); 
     449    $wfh->flush(); 
     450 
     451  } else { 
     452    eval { server_wait($config_file, $rfh) }; 
     453    if ($@) { 
     454      warn($@); 
     455      exit 1; 
     456    } 
     457 
     458    exit 0; 
     459  } 
     460 
     461  # Stop server 
     462  server_stop($pid_file); 
     463 
     464  $self->assert_child_ok($pid); 
     465 
     466  if ($ex) { 
     467    die($ex); 
     468  } 
     469 
     470  unlink($log_file); 
     471} 
     472 
     473sub timeoutstalled_exceeded_mlsd { 
     474  my $self = shift; 
     475  my $tmpdir = $self->{tmpdir}; 
     476 
     477  my $config_file = "$tmpdir/config.conf"; 
     478  my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); 
     479  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); 
     480 
     481  my $log_file = File::Spec->rel2abs('tests.log'); 
     482 
     483  my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); 
     484  my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); 
     485 
     486  my $user = 'proftpd'; 
     487  my $passwd = 'test'; 
     488  my $group = 'ftpd'; 
     489  my $home_dir = File::Spec->rel2abs($tmpdir); 
     490  my $uid = 500; 
     491  my $gid = 500; 
     492 
     493  # Make sure that, if we're running as root, that the home directory has 
     494  # permissions/privs set for the account we create 
     495  if ($< == 0) { 
     496    unless (chmod(0755, $home_dir)) { 
     497      die("Can't set perms on $home_dir to 0755: $!"); 
     498    } 
     499     
     500    unless (chown($uid, $gid, $home_dir)) { 
     501      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     502    } 
     503  } 
     504 
     505  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     506    '/bin/bash'); 
     507  auth_group_write($auth_group_file, $group, $gid, $user); 
     508 
     509  my $timeout_stalled = 1; 
     510 
     511  my $config = { 
     512    PidFile => $pid_file, 
     513    ScoreboardFile => $scoreboard_file, 
     514    SystemLog => $log_file, 
     515 
     516    AuthUserFile => $auth_user_file, 
     517    AuthGroupFile => $auth_group_file, 
     518 
     519    TimeoutStalled => $timeout_stalled, 
     520 
     521    IfModules => { 
     522      'mod_delay.c' => { 
     523        DelayEngine => 'off', 
     524      }, 
     525    }, 
     526  }; 
     527 
     528  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     529 
     530  # Open pipes, for use between the parent and child processes.  Specifically, 
     531  # the child will indicate when it's done with its test by writing a message 
     532  # to the parent. 
     533  my ($rfh, $wfh); 
     534  unless (pipe($rfh, $wfh)) { 
     535    die("Can't open pipe: $!"); 
     536  } 
     537 
     538  my $ex; 
     539 
     540  # Fork child 
     541  $self->handle_sigchld(); 
     542  defined(my $pid = fork()) or die("Can't fork: $!"); 
     543  if ($pid) { 
     544    eval { 
     545      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     546 
     547      $client->login($user, $passwd); 
     548 
     549      my $conn = $client->mlsd_raw($home_dir); 
     550      unless ($conn) { 
     551        die("MLSD failed: " . $client->response_code() . " " . 
     552          $client->response_msg()); 
     553      } 
     554 
     555      # Wait for one second more than the stalled period 
     556      sleep($timeout_stalled + 1); 
     557 
     558      my $buf; 
     559      $conn->read($buf, 8192, 30); 
     560      $conn->close(); 
     561 
     562      eval { $client->noop() }; 
     563      unless ($@) { 
     564        die("NOOP succeeded unexpectedly"); 
     565      } 
     566 
     567      my $resp_code = $client->response_code(); 
     568      my $resp_msg = $client->response_msg(); 
     569 
     570      my $expected; 
     571 
     572      # Perl's Net::Cmd module uses a very non-standard 599 code to 
     573      # indicate that the connection is closed 
     574      $expected = 599; 
     575      $self->assert($expected == $resp_code, 
     576        test_msg("Expected $expected, got $resp_code")); 
     577 
     578      $expected = "Connection closed"; 
     579      $self->assert($expected eq $resp_msg, 
     580        test_msg("Expected '$expected', got '$resp_msg'")); 
     581    }; 
     582 
     583    if ($@) { 
     584      $ex = $@; 
     585    } 
     586 
     587    $wfh->print("done\n"); 
     588    $wfh->flush(); 
     589 
     590  } else { 
     591    eval { server_wait($config_file, $rfh) }; 
     592    if ($@) { 
     593      warn($@); 
     594      exit 1; 
     595    } 
     596 
     597    exit 0; 
     598  } 
     599 
     600  # Stop server 
     601  server_stop($pid_file); 
     602 
     603  $self->assert_child_ok($pid); 
     604 
     605  if ($ex) { 
     606    die($ex); 
     607  } 
     608 
     609  unlink($log_file); 
     610} 
     611 
     612sub timeoutstalled_exceeded_retr { 
     613  my $self = shift; 
     614  my $tmpdir = $self->{tmpdir}; 
     615 
     616  my $config_file = "$tmpdir/config.conf"; 
     617  my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); 
     618  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); 
     619 
     620  my $log_file = File::Spec->rel2abs('tests.log'); 
     621 
     622  my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); 
     623  my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); 
     624 
     625  my $user = 'proftpd'; 
     626  my $passwd = 'test'; 
     627  my $group = 'ftpd'; 
     628  my $home_dir = File::Spec->rel2abs($tmpdir); 
     629  my $uid = 500; 
     630  my $gid = 500; 
     631 
     632  # Make sure that, if we're running as root, that the home directory has 
     633  # permissions/privs set for the account we create 
     634  if ($< == 0) { 
     635    unless (chmod(0755, $home_dir)) { 
     636      die("Can't set perms on $home_dir to 0755: $!"); 
     637    } 
     638     
     639    unless (chown($uid, $gid, $home_dir)) { 
     640      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     641    } 
     642  } 
     643 
     644  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     645    '/bin/bash'); 
     646  auth_group_write($auth_group_file, $group, $gid, $user); 
     647 
     648  my $timeout_stalled = 1; 
     649 
     650  my $config = { 
     651    PidFile => $pid_file, 
     652    ScoreboardFile => $scoreboard_file, 
     653    SystemLog => $log_file, 
     654 
     655    AuthUserFile => $auth_user_file, 
     656    AuthGroupFile => $auth_group_file, 
     657 
     658    TimeoutStalled => $timeout_stalled, 
     659 
     660    IfModules => { 
     661      'mod_delay.c' => { 
     662        DelayEngine => 'off', 
     663      }, 
     664    }, 
     665  }; 
     666 
     667  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     668 
     669  # Open pipes, for use between the parent and child processes.  Specifically, 
     670  # the child will indicate when it's done with its test by writing a message 
     671  # to the parent. 
     672  my ($rfh, $wfh); 
     673  unless (pipe($rfh, $wfh)) { 
     674    die("Can't open pipe: $!"); 
     675  } 
     676 
     677  my $ex; 
     678 
     679  # Fork child 
     680  $self->handle_sigchld(); 
     681  defined(my $pid = fork()) or die("Can't fork: $!"); 
     682  if ($pid) { 
     683    eval { 
     684      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     685 
     686      $client->login($user, $passwd); 
     687 
     688      my $conn = $client->retr_raw($config_file); 
     689      unless ($conn) { 
     690        die("RETR failed: " . $client->response_code() . " " . 
     691          $client->response_msg()); 
     692      } 
     693 
     694      # Wait for one second more than the stalled period 
     695      sleep($timeout_stalled + 1); 
     696 
     697      my $buf; 
     698      $conn->read($buf, 8192, 30); 
     699      $conn->close(); 
     700 
     701      eval { $client->noop() }; 
     702      unless ($@) { 
     703        die("NOOP succeeded unexpectedly"); 
     704      } 
     705 
     706      my $resp_code = $client->response_code(); 
     707      my $resp_msg = $client->response_msg(); 
     708 
     709      my $expected; 
     710 
     711      # Perl's Net::Cmd module uses a very non-standard 599 code to 
     712      # indicate that the connection is closed 
     713      $expected = 599; 
     714      $self->assert($expected == $resp_code, 
     715        test_msg("Expected $expected, got $resp_code")); 
     716 
     717      $expected = "Connection closed"; 
     718      $self->assert($expected eq $resp_msg, 
     719        test_msg("Expected '$expected', got '$resp_msg'")); 
     720    }; 
     721 
     722    if ($@) { 
     723      $ex = $@; 
     724    } 
     725 
     726    $wfh->print("done\n"); 
     727    $wfh->flush(); 
     728 
     729  } else { 
     730    eval { server_wait($config_file, $rfh) }; 
     731    if ($@) { 
     732      warn($@); 
     733      exit 1; 
     734    } 
     735 
     736    exit 0; 
     737  } 
     738 
     739  # Stop server 
     740  server_stop($pid_file); 
     741 
     742  $self->assert_child_ok($pid); 
     743 
     744  if ($ex) { 
     745    die($ex); 
     746  } 
     747 
     748  unlink($log_file); 
     749} 
     750 
     751sub timeoutstalled_exceeded_stor { 
     752  my $self = shift; 
     753  my $tmpdir = $self->{tmpdir}; 
     754 
     755  my $config_file = "$tmpdir/config.conf"; 
     756  my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); 
     757  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); 
     758 
     759  my $log_file = File::Spec->rel2abs('tests.log'); 
     760 
     761  my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); 
     762  my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); 
     763 
     764  my $user = 'proftpd'; 
     765  my $passwd = 'test'; 
     766  my $group = 'ftpd'; 
     767  my $home_dir = File::Spec->rel2abs($tmpdir); 
     768  my $uid = 500; 
     769  my $gid = 500; 
     770 
     771  # Make sure that, if we're running as root, that the home directory has 
     772  # permissions/privs set for the account we create 
     773  if ($< == 0) { 
     774    unless (chmod(0755, $home_dir)) { 
     775      die("Can't set perms on $home_dir to 0755: $!"); 
     776    } 
     777     
     778    unless (chown($uid, $gid, $home_dir)) { 
     779      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     780    } 
     781  } 
     782 
     783  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     784    '/bin/bash'); 
     785  auth_group_write($auth_group_file, $group, $gid, $user); 
     786 
     787  my $timeout_stalled = 1; 
     788 
     789  my $config = { 
     790    PidFile => $pid_file, 
     791    ScoreboardFile => $scoreboard_file, 
     792    SystemLog => $log_file, 
     793 
     794    AuthUserFile => $auth_user_file, 
     795    AuthGroupFile => $auth_group_file, 
     796 
     797    TimeoutStalled => $timeout_stalled, 
     798 
     799    IfModules => { 
     800      'mod_delay.c' => { 
     801        DelayEngine => 'off', 
     802      }, 
     803    }, 
     804  }; 
     805 
     806  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     807 
     808  # Open pipes, for use between the parent and child processes.  Specifically, 
     809  # the child will indicate when it's done with its test by writing a message 
     810  # to the parent. 
     811  my ($rfh, $wfh); 
     812  unless (pipe($rfh, $wfh)) { 
     813    die("Can't open pipe: $!"); 
     814  } 
     815 
     816  my $ex; 
     817 
     818  # Fork child 
     819  $self->handle_sigchld(); 
     820  defined(my $pid = fork()) or die("Can't fork: $!"); 
     821  if ($pid) { 
     822    eval { 
     823      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     824 
     825      $client->login($user, $passwd); 
     826 
     827      my $conn = $client->stor_raw('foo.bar.baz'); 
     828      unless ($conn) { 
     829        die("STOR failed: " . $client->response_code() . " " . 
     830          $client->response_msg()); 
     831      } 
     832 
     833      # Wait for one second more than the stalled period 
     834      sleep($timeout_stalled + 1); 
     835 
     836      my $buf; 
     837      $conn->read($buf, 8192, 30); 
     838      $conn->close(); 
     839 
     840      eval { $client->noop() }; 
     841      unless ($@) { 
     842        die("NOOP succeeded unexpectedly"); 
     843      } 
     844 
     845      my $resp_code = $client->response_code(); 
     846      my $resp_msg = $client->response_msg(); 
     847 
     848      my $expected; 
     849 
     850      # Perl's Net::Cmd module uses a very non-standard 599 code to 
     851      # indicate that the connection is closed 
     852      $expected = 599; 
     853      $self->assert($expected == $resp_code, 
     854        test_msg("Expected $expected, got $resp_code")); 
     855 
     856      $expected = "Connection closed"; 
     857      $self->assert($expected eq $resp_msg, 
     858        test_msg("Expected '$expected', got '$resp_msg'")); 
     859    }; 
     860 
     861    if ($@) { 
     862      $ex = $@; 
     863    } 
     864 
     865    $wfh->print("done\n"); 
     866    $wfh->flush(); 
     867 
     868  } else { 
     869    eval { server_wait($config_file, $rfh) }; 
     870    if ($@) { 
     871      warn($@); 
     872      exit 1; 
     873    } 
     874 
     875    exit 0; 
     876  } 
     877 
     878  # Stop server 
     879  server_stop($pid_file); 
     880 
     881  $self->assert_child_ok($pid); 
     882 
     883  if ($ex) { 
     884    die($ex); 
     885  } 
     886 
     887  unlink($log_file); 
     888} 
     889 
     890sub timeoutstalled_exceeded_retr_usesendfile_on { 
     891  my $self = shift; 
     892  my $tmpdir = $self->{tmpdir}; 
     893 
     894  my $config_file = "$tmpdir/config.conf"; 
     895  my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); 
     896  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); 
     897 
     898  my $log_file = File::Spec->rel2abs('tests.log'); 
     899 
     900  my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); 
     901  my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); 
     902 
     903  my $user = 'proftpd'; 
     904  my $passwd = 'test'; 
     905  my $group = 'ftpd'; 
     906  my $home_dir = File::Spec->rel2abs($tmpdir); 
     907  my $uid = 500; 
     908  my $gid = 500; 
     909 
     910  # Make sure that, if we're running as root, that the home directory has 
     911  # permissions/privs set for the account we create 
     912  if ($< == 0) { 
     913    unless (chmod(0755, $home_dir)) { 
     914      die("Can't set perms on $home_dir to 0755: $!"); 
     915    } 
     916     
     917    unless (chown($uid, $gid, $home_dir)) { 
     918      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     919    } 
     920  } 
     921 
     922  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     923    '/bin/bash'); 
     924  auth_group_write($auth_group_file, $group, $gid, $user); 
     925 
     926  my $timeout_stalled = 1; 
     927 
     928  my $config = { 
     929    PidFile => $pid_file, 
     930    ScoreboardFile => $scoreboard_file, 
     931    SystemLog => $log_file, 
     932 
     933    AuthUserFile => $auth_user_file, 
     934    AuthGroupFile => $auth_group_file, 
     935 
     936    TimeoutStalled => $timeout_stalled, 
     937    UseSendfile => 'on', 
     938 
     939    IfModules => { 
     940      'mod_delay.c' => { 
     941        DelayEngine => 'off', 
     942      }, 
     943    }, 
     944  }; 
     945 
     946  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     947 
     948  # Open pipes, for use between the parent and child processes.  Specifically, 
     949  # the child will indicate when it's done with its test by writing a message 
     950  # to the parent. 
     951  my ($rfh, $wfh); 
     952  unless (pipe($rfh, $wfh)) { 
     953    die("Can't open pipe: $!"); 
     954  } 
     955 
     956  my $ex; 
     957 
     958  # Fork child 
     959  $self->handle_sigchld(); 
     960  defined(my $pid = fork()) or die("Can't fork: $!"); 
     961  if ($pid) { 
     962    eval { 
     963      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     964 
     965      $client->login($user, $passwd); 
     966 
     967      my $conn = $client->retr_raw($config_file); 
     968      unless ($conn) { 
     969        die("RETR failed: " . $client->response_code() . " " . 
     970          $client->response_msg()); 
     971      } 
     972 
     973      # Wait for one second more than the stalled period 
     974      sleep($timeout_stalled + 1); 
     975 
     976      my $buf; 
     977      $conn->read($buf, 8192, 30); 
     978      $conn->close(); 
     979 
     980      eval { $client->noop() }; 
     981      unless ($@) { 
     982        die("NOOP succeeded unexpectedly"); 
     983      } 
     984 
     985      my $resp_code = $client->response_code(); 
     986      my $resp_msg = $client->response_msg(); 
     987 
     988      my $expected; 
     989 
     990      # Perl's Net::Cmd module uses a very non-standard 599 code to 
     991      # indicate that the connection is closed 
     992      $expected = 599; 
     993      $self->assert($expected == $resp_code, 
     994        test_msg("Expected $expected, got $resp_code")); 
     995 
     996      $expected = "Connection closed"; 
     997      $self->assert($expected eq $resp_msg, 
     998        test_msg("Expected '$expected', got '$resp_msg'")); 
     999    }; 
     1000 
     1001    if ($@) { 
     1002      $ex = $@; 
     1003    } 
     1004 
     1005    $wfh->print("done\n"); 
     1006    $wfh->flush(); 
     1007 
     1008  } else { 
     1009    eval { server_wait($config_file, $rfh) }; 
     1010    if ($@) { 
     1011      warn($@); 
     1012      exit 1; 
     1013    } 
     1014 
     1015    exit 0; 
     1016  } 
     1017 
     1018  # Stop server 
     1019  server_stop($pid_file); 
     1020 
     1021  $self->assert_child_ok($pid); 
     1022 
     1023  if ($ex) { 
     1024    die($ex); 
     1025  } 
     1026 
     1027  unlink($log_file); 
     1028} 
     1029 
    33310301; 
Note: See TracChangeset for help on using the changeset viewer.