File: testmodule.t

package info (click to toggle)
libhttp-daemon-ssl-perl 1.05-01-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 824 kB
  • sloc: perl: 190; makefile: 19; sh: 2
file content (107 lines) | stat: -rw-r--r-- 2,458 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!perl -w
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl t/testmodule.t'

use HTTP::Daemon::SSL;
use HTTP::Status;
eval {require "t/ssl_settings.req";} ||
eval {require "ssl_settings.req";};

$numtests = 9;
$|=1;
$SIG{PIPE}='IGNORE';

foreach ($^O) {
    if (/MacOS/ or /VOS/ or /vmesa/ or /riscos/ or /amigaos/) {
	print "1..0 # Skipped: fork not implemented on this platform\n";
	exit;
    }
}

print "1..$numtests\n";

$test = 0;

my $server = new HTTP::Daemon::SSL(
				   LocalAddr => $SSL_SERVER_ADDR,
				   Listen => 5,
				   Timeout => 30,
				   ReuseAddr => 1,
				   SSL_verify_mode => 0x00,
				   SSL_ca_file => "certs/test-ca.pem",
				   SSL_cert_file => "certs/server-cert.pem");

if (!$server) {
    print "not ok $test\n";
    exit;
}
$SSL_SERVER_PORT = $server->sockport;
&ok("server init port=$SSL_SERVER_PORT");


print "not " if (!defined fileno($server));
&ok("server fileno");

print "not " unless ($server->url =~ m!^https:!);
&ok("server url test");


unless (fork) {
    close($server);

    my $client = new IO::Socket::INET(PeerAddr => $SSL_SERVER_ADDR,
				      PeerPort => $SSL_SERVER_PORT);

    print $client "GET / HTTP/1.0\r\n\r\n";
    (<$client> eq "HTTP/1.1 400 Bad Request\r\n") || print "not ";
    &ok("client bad connection test");
    my @ary = <$client>;
    close $client;

    $client = new IO::Socket::SSL(PeerAddr => $SSL_SERVER_ADDR,
				  PeerPort => $SSL_SERVER_PORT,
				  SSL_verify_mode => 0x01,
				  SSL_ca_file => "certs/test-ca.pem");

    $client || (print("not ok #client failure\n") && exit);
    &ok("client good connection test");

    print $client "GET /foo HTTP/1.0\r\n\r\n";

    (<$client> eq "HTTP/1.1 403 Forbidden\r\n") || print "not ";
    &ok("client permission test");
    @ary = <$client>;

    exit(0);
}


my $conn;
if (!($conn = $server->accept)) {
    # first client request is a bad request
    &ok("bad request handled");
} else {
    print "not ok $test # bad request returned a socket\n";
}

if ($conn = $server->accept) {
    &ok("valid request handled");
} else {
    print "not ok $test # valid request did not return a socket\n";
}

my $r = $conn->get_request();

unless ($r->method eq 'GET' and $r->url->path eq '/foo') {
    print "not ";
}
&ok("server method processing");

$conn->send_error(RC_FORBIDDEN);

close $conn;
wait;

sub ok {
    print "ok #$_[0] ", ++$test, "\n"; 
}