source: src/router/proftpd/tests/t/lib/ProFTPD/Tests/Config/Limit/LOGIN.pm @ 17880

Last change on this file since 17880 was 17880, checked in by BrainSlayer, 19 months ago

update

File size: 3.3 KB
Line 
1package ProFTPD::Tests::Config::Limit::LOGIN;
2
3use lib qw(t/lib);
4use base qw(ProFTPD::TestSuite::Child);
5use strict;
6
7use File::Spec;
8use IO::Handle;
9
10use ProFTPD::TestSuite::FTP;
11use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
12
13$| = 1;
14
15my $order = 0;
16
17my $TESTS = {
18  login_limit_ip_glob_range_bug3484 => {
19    order => ++$order,
20    test_class => [qw(bug forking inprogress)],
21  },
22
23};
24
25sub new {
26  return shift()->SUPER::new(@_);
27}
28
29sub list_tests {
30  return testsuite_get_runnable_tests($TESTS);
31}
32
33sub login_limit_ip_glob_range_bug3484 {
34  my $self = shift;
35  my $tmpdir = $self->{tmpdir};
36
37  my $config_file = "$tmpdir/limit.conf";
38  my $pid_file = File::Spec->rel2abs("$tmpdir/limit.pid");
39  my $scoreboard_file = File::Spec->rel2abs("$tmpdir/limit.scoreboard");
40
41  my $log_file = File::Spec->rel2abs('tests.log');
42
43  my $auth_user_file = File::Spec->rel2abs("$tmpdir/limit.passwd");
44  my $auth_group_file = File::Spec->rel2abs("$tmpdir/limit.group");
45
46  my $user = 'proftpd';
47  my $passwd = 'test';
48  my $home_dir = File::Spec->rel2abs($tmpdir);
49  my $uid = 500;
50  my $gid = 500;
51
52  # Make sure that, if we're running as root, that the home directory has
53  # permissions/privs set for the account we create
54  if ($< == 0) {
55    unless (chmod(0755, $home_dir)) {
56      die("Can't set perms on $home_dir to 0755: $!");
57    }
58
59    unless (chown($uid, $gid, $home_dir)) {
60      die("Can't set owner of $home_dir to $uid/$gid: $!");
61    }
62  }
63 
64  auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
65    '/bin/bash');
66  auth_group_write($auth_group_file, 'ftpd', $gid, $user);
67
68  # See http://forums.proftpd.org/smf/index.php/topic,4774.0.html
69
70  my $config = {
71    PidFile => $pid_file,
72    ScoreboardFile => $scoreboard_file,
73    SystemLog => $log_file,
74    TraceLog => $log_file,
75    Trace => 'netacl:20 dns:20',
76
77    AuthUserFile => $auth_user_file,
78    AuthGroupFile => $auth_group_file,
79    UseIPv6 => 'off',
80
81    IfModules => {
82      'mod_delay.c' => {
83        DelayEngine => 'off',
84      },
85    },
86
87    Limit => {
88      LOGIN => {
89        Deny => '127.0.0.[0-9]',
90      },
91    },
92
93  };
94
95  my ($port, $config_user, $config_group) = config_write($config_file, $config);
96
97  # Open pipes, for use between the parent and child processes.  Specifically,
98  # the child will indicate when it's done with its test by writing a message
99  # to the parent.
100  my ($rfh, $wfh);
101  unless (pipe($rfh, $wfh)) {
102    die("Can't open pipe: $!");
103  }
104
105  my $ex;
106
107  # Fork child
108  $self->handle_sigchld();
109  defined(my $pid = fork()) or die("Can't fork: $!");
110  if ($pid) {
111    eval {
112      my $client;
113
114      eval { $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port,
115        undef, 0) };
116      unless ($@) {
117        die("Connect succeeded unexpectedly");
118      }
119
120      my $conn_ex = ProFTPD::TestSuite::FTP::get_connect_exception();
121
122      my $expected = 'Connection refused';
123      $self->assert(qr/$expected/, $conn_ex,
124        test_msg("Expected '$expected', got '$conn_ex'"));
125    };
126
127    if ($@) {
128      $ex = $@;
129    }
130
131    $wfh->print("done\n");
132    $wfh->flush();
133
134  } else {
135    eval { server_wait($config_file, $rfh) };
136    if ($@) {
137      warn($@);
138      exit 1;
139    }
140
141    exit 0;
142  }
143
144  # Stop server
145  server_stop($pid_file);
146
147  $self->assert_child_ok($pid);
148
149  if ($ex) {
150    die($ex);
151  }
152
153  unlink($log_file);
154}
155
1561;
Note: See TracBrowser for help on using the repository browser.