~ubuntu-branches/ubuntu/edgy/libapache2-mod-perl2/edgy

« back to all changes in this revision

Viewing changes to t/protocol/pseudo_http.t

  • Committer: Bazaar Package Importer
  • Author(s): Andres Salomon
  • Date: 2005-08-12 01:40:38 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050812014038-gjigefs55pqx4qc8
Tags: 2.0.1-3
Grr.  Really include perl.conf file; it got lost due to diff not
wanting to add an empty file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use strict;
 
2
use warnings FATAL => 'all';
 
3
 
 
4
use Apache::Test;
 
5
use Apache::TestUtil;
 
6
use Apache::TestRequest ();
 
7
 
 
8
my $module = 'TestProtocol::pseudo_http';
 
9
 
 
10
{
 
11
    # debug
 
12
    Apache::TestRequest::module($module);
 
13
    my $hostport = Apache::TestRequest::hostport(Apache::Test::config());
 
14
    t_debug("connecting to $hostport");
 
15
}
 
16
 
 
17
my $login    = "stas";
 
18
my $passgood = "foobar";
 
19
my $passbad  = "foObaR";
 
20
 
 
21
# blocking socket bug fixed in 2.0.52
 
22
my $ok = $^O !~ /^(Open|Net)BSD$/i || need_min_apache_version('2.0.52');
 
23
 
 
24
# but not in 2.1?  hmph.
 
25
$ok = skip_reason('skipping on httpd 2.1') if have_min_apache_version('2.1');
 
26
 
 
27
plan tests => 13, need need_auth, need_access, $ok;
 
28
 
 
29
{
 
30
    # supply correct credential when prompted for such and ask the
 
31
    # server get the secret datetime information
 
32
    my $socket = Apache::TestRequest::vhost_socket($module);
 
33
    ok $socket;
 
34
 
 
35
    expect_reply($socket, "HELO",      "HELO",    "greeting");
 
36
    expect_reply($socket, "Login:",    $login,    "login");
 
37
    expect_reply($socket, "Password:", $passgood, "good password");
 
38
    expect($socket, "Welcome to TestProtocol::pseudo_http", "banner");
 
39
    expect_reply($socket, "Available commands: date quit", "date", "date");
 
40
    expect_reply($socket, qr/The time is:/,        "quit", "quit");
 
41
    expect($socket, "Goodbye", "end of transmission");
 
42
}
 
43
 
 
44
{
 
45
    # this time sending wrong credentials and hoping that the server
 
46
    # won't let us in
 
47
    my $socket = Apache::TestRequest::vhost_socket($module);
 
48
    ok $socket;
 
49
 
 
50
    expect_reply($socket, "HELO",      "HELO",   "greeting");
 
51
    expect_reply($socket, "Login:",    $login,   "login");
 
52
    t_client_log_error_is_expected();
 
53
    expect_reply($socket, "Password:", $passbad, "wrong password");
 
54
    expect($socket, "Access Denied", "end of transmission");
 
55
}
 
56
 
 
57
sub expect {
 
58
    my($socket, $expect, $action) = @_;
 
59
    chomp(my $recv = <$socket> || '');
 
60
    ok t_cmp($recv, $expect, $action);
 
61
}
 
62
 
 
63
sub expect_reply {
 
64
    my($socket, $expect, $reply, $action) = @_;
 
65
    chomp(my $recv = <$socket> || '');
 
66
    ok t_cmp($recv, $expect, $action);
 
67
    t_debug("send: $reply");
 
68
    print $socket $reply;
 
69
}
 
70