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/PathAllowFilter.pm

    r14674 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); 
     7use File::Path qw(mkpath); 
    88use File::Spec; 
    99use IO::Handle; 
     
    7777  }, 
    7878 
     79  pathallowfilter_stor_denied_nocase_bug3592 => { 
     80    order => ++$order, 
     81    test_class => [qw(bug forking)], 
     82  }, 
     83 
     84  pathallowfilter_stor_denied_nocase_bug3609 => { 
     85    order => ++$order, 
     86    test_class => [qw(bug feature_pcre forking)], 
     87  }, 
     88 
    7989}; 
    8090 
     
    8595sub list_tests { 
    8696  return testsuite_get_runnable_tests($TESTS); 
    87 } 
    88  
    89 sub set_up { 
    90   my $self = shift; 
    91   $self->{tmpdir} = testsuite_get_tmp_dir(); 
    92  
    93   # Create temporary scratch dir 
    94   eval { mkpath($self->{tmpdir}) }; 
    95   if ($@) { 
    96     my $abs_path = File::Spec->rel2abs($self->{tmpdir}); 
    97     die("Can't create dir $abs_path: $@"); 
    98   } 
    99 } 
    100  
    101 sub tear_down { 
    102   my $self = shift; 
    103  
    104   # Remove temporary scratch dir 
    105   if ($self->{tmpdir}) { 
    106     eval { rmtree($self->{tmpdir}) }; 
    107   } 
    108  
    109   undef $self; 
    11097} 
    11198 
     
    16051592} 
    16061593 
     1594sub pathallowfilter_stor_denied_nocase_bug3592 { 
     1595  my $self = shift; 
     1596  my $tmpdir = $self->{tmpdir}; 
     1597 
     1598  my $config_file = "$tmpdir/config.conf"; 
     1599  my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); 
     1600  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); 
     1601 
     1602  my $log_file = File::Spec->rel2abs('tests.log'); 
     1603 
     1604  my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); 
     1605  my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); 
     1606 
     1607  my $user = 'proftpd'; 
     1608  my $passwd = 'test'; 
     1609  my $group = 'ftpd'; 
     1610  my $home_dir = File::Spec->rel2abs($tmpdir); 
     1611  my $uid = 500; 
     1612  my $gid = 500; 
     1613 
     1614  # Make sure that, if we're running as root, that the home directory has 
     1615  # permissions/privs set for the account we create 
     1616  if ($< == 0) { 
     1617    unless (chmod(0755, $home_dir)) { 
     1618      die("Can't set perms on $home_dir to 0755: $!"); 
     1619    } 
     1620 
     1621    unless (chown($uid, $gid, $home_dir)) { 
     1622      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     1623    } 
     1624  } 
     1625 
     1626  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     1627    '/bin/bash'); 
     1628  auth_group_write($auth_group_file, $group, $gid, $user); 
     1629 
     1630  my $config = { 
     1631    PidFile => $pid_file, 
     1632    ScoreboardFile => $scoreboard_file, 
     1633    SystemLog => $log_file, 
     1634 
     1635    AuthUserFile => $auth_user_file, 
     1636    AuthGroupFile => $auth_group_file, 
     1637    DefaultChdir => '~', 
     1638 
     1639    AllowOverwrite => 'on', 
     1640    PathAllowFilter => '\.txt$ [NC]', 
     1641 
     1642    IfModules => { 
     1643      'mod_delay.c' => { 
     1644        DelayEngine => 'off', 
     1645      }, 
     1646    }, 
     1647  }; 
     1648 
     1649  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     1650 
     1651  # Open pipes, for use between the parent and child processes.  Specifically, 
     1652  # the child will indicate when it's done with its test by writing a message 
     1653  # to the parent. 
     1654  my ($rfh, $wfh); 
     1655  unless (pipe($rfh, $wfh)) { 
     1656    die("Can't open pipe: $!"); 
     1657  } 
     1658 
     1659  my $ex; 
     1660 
     1661  # Fork child 
     1662  $self->handle_sigchld(); 
     1663  defined(my $pid = fork()) or die("Can't fork: $!"); 
     1664  if ($pid) { 
     1665    eval { 
     1666      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     1667      $client->login($user, $passwd); 
     1668 
     1669      my $filename = 'test.TxT'; 
     1670 
     1671      my $conn = $client->stor_raw($filename); 
     1672      unless ($conn) { 
     1673        die("STOR $filename failed: " . $client->response_code() . " " . 
     1674          $client->response_msg()); 
     1675      } 
     1676 
     1677      my $buf = "Hello, World!\n"; 
     1678      $conn->write($buf, length($buf), 25); 
     1679      $conn->close(); 
     1680 
     1681      my $resp_code = $client->response_code(); 
     1682      my $resp_msg = $client->response_msg(); 
     1683 
     1684      my $expected; 
     1685 
     1686      $expected = 226; 
     1687      $self->assert($expected == $resp_code, 
     1688        test_msg("Expected $expected, got $resp_code")); 
     1689 
     1690      $expected = "Transfer complete"; 
     1691      $self->assert($expected eq $resp_msg, 
     1692        test_msg("Expected '$expected', got '$resp_msg'")); 
     1693 
     1694      $client->quit(); 
     1695    }; 
     1696 
     1697    if ($@) { 
     1698      $ex = $@; 
     1699    } 
     1700 
     1701    $wfh->print("done\n"); 
     1702    $wfh->flush(); 
     1703 
     1704  } else { 
     1705    eval { server_wait($config_file, $rfh) }; 
     1706    if ($@) { 
     1707      warn($@); 
     1708      exit 1; 
     1709    } 
     1710 
     1711    exit 0; 
     1712  } 
     1713 
     1714  # Stop server 
     1715  server_stop($pid_file); 
     1716 
     1717  $self->assert_child_ok($pid); 
     1718 
     1719  if ($ex) { 
     1720    die($ex); 
     1721  } 
     1722 
     1723  unlink($log_file); 
     1724} 
     1725 
     1726sub pathallowfilter_stor_denied_nocase_bug3609 { 
     1727  my $self = shift; 
     1728  my $tmpdir = $self->{tmpdir}; 
     1729 
     1730  my $config_file = "$tmpdir/config.conf"; 
     1731  my $pid_file = File::Spec->rel2abs("$tmpdir/config.pid"); 
     1732  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/config.scoreboard"); 
     1733 
     1734  my $log_file = File::Spec->rel2abs('tests.log'); 
     1735 
     1736  my $auth_user_file = File::Spec->rel2abs("$tmpdir/config.passwd"); 
     1737  my $auth_group_file = File::Spec->rel2abs("$tmpdir/config.group"); 
     1738 
     1739  my $user = 'proftpd'; 
     1740  my $passwd = 'test'; 
     1741  my $group = 'ftpd'; 
     1742  my $home_dir = File::Spec->rel2abs($tmpdir); 
     1743  my $uid = 500; 
     1744  my $gid = 500; 
     1745 
     1746  # Make sure that, if we're running as root, that the home directory has 
     1747  # permissions/privs set for the account we create 
     1748  if ($< == 0) { 
     1749    unless (chmod(0755, $home_dir)) { 
     1750      die("Can't set perms on $home_dir to 0755: $!"); 
     1751    } 
     1752 
     1753    unless (chown($uid, $gid, $home_dir)) { 
     1754      die("Can't set owner of $home_dir to $uid/$gid: $!"); 
     1755    } 
     1756  } 
     1757 
     1758  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir, 
     1759    '/bin/bash'); 
     1760  auth_group_write($auth_group_file, $group, $gid, $user); 
     1761 
     1762  my $config = { 
     1763    PidFile => $pid_file, 
     1764    ScoreboardFile => $scoreboard_file, 
     1765    SystemLog => $log_file, 
     1766    TraceLog => $log_file, 
     1767    Trace => 'DEFAULT:0 regexp:10', 
     1768 
     1769    AuthUserFile => $auth_user_file, 
     1770    AuthGroupFile => $auth_group_file, 
     1771    DefaultChdir => '~', 
     1772 
     1773    AllowOverwrite => 'on', 
     1774    PathAllowFilter => '(?i)\.txt$', 
     1775 
     1776    IfModules => { 
     1777      'mod_delay.c' => { 
     1778        DelayEngine => 'off', 
     1779      }, 
     1780    }, 
     1781  }; 
     1782 
     1783  my ($port, $config_user, $config_group) = config_write($config_file, $config); 
     1784 
     1785  # Open pipes, for use between the parent and child processes.  Specifically, 
     1786  # the child will indicate when it's done with its test by writing a message 
     1787  # to the parent. 
     1788  my ($rfh, $wfh); 
     1789  unless (pipe($rfh, $wfh)) { 
     1790    die("Can't open pipe: $!"); 
     1791  } 
     1792 
     1793  my $ex; 
     1794 
     1795  # Fork child 
     1796  $self->handle_sigchld(); 
     1797  defined(my $pid = fork()) or die("Can't fork: $!"); 
     1798  if ($pid) { 
     1799    eval { 
     1800      my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port); 
     1801      $client->login($user, $passwd); 
     1802 
     1803      my $filename = 'test.TxT'; 
     1804 
     1805      my $conn = $client->stor_raw($filename); 
     1806      unless ($conn) { 
     1807        die("STOR $filename failed: " . $client->response_code() . " " . 
     1808          $client->response_msg()); 
     1809      } 
     1810 
     1811      my $buf = "Hello, World!\n"; 
     1812      $conn->write($buf, length($buf), 25); 
     1813      $conn->close(); 
     1814 
     1815      my $resp_code = $client->response_code(); 
     1816      my $resp_msg = $client->response_msg(); 
     1817 
     1818      my $expected; 
     1819 
     1820      $expected = 226; 
     1821      $self->assert($expected == $resp_code, 
     1822        test_msg("Expected $expected, got $resp_code")); 
     1823 
     1824      $expected = "Transfer complete"; 
     1825      $self->assert($expected eq $resp_msg, 
     1826        test_msg("Expected '$expected', got '$resp_msg'")); 
     1827 
     1828      $client->quit(); 
     1829    }; 
     1830 
     1831    if ($@) { 
     1832      $ex = $@; 
     1833    } 
     1834 
     1835    $wfh->print("done\n"); 
     1836    $wfh->flush(); 
     1837 
     1838  } else { 
     1839    eval { server_wait($config_file, $rfh) }; 
     1840    if ($@) { 
     1841      warn($@); 
     1842      exit 1; 
     1843    } 
     1844 
     1845    exit 0; 
     1846  } 
     1847 
     1848  # Stop server 
     1849  server_stop($pid_file); 
     1850 
     1851  $self->assert_child_ok($pid); 
     1852 
     1853  if ($ex) { 
     1854    die($ex); 
     1855  } 
     1856 
     1857  unlink($log_file); 
     1858} 
     1859 
    160718601; 
Note: See TracChangeset for help on using the changeset viewer.