1 # Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
7 foreach my $mod (qw(Plack::Util Plack::Builder HTTP::Date HTTP::Status)) {
9 plan skip_all => "$mod missing for httpd.t" if $@;
11 use File::Temp qw/tempdir/;
13 require './t/common.perl';
15 # FIXME: too much setup
16 my $tmpdir = tempdir('pi-httpd-XXXXXX', TMPDIR => 1, CLEANUP => 1);
17 my $home = "$tmpdir/pi-home";
18 my $err = "$tmpdir/stderr.log";
19 my $out = "$tmpdir/stdout.log";
20 my $maindir = "$tmpdir/main.git";
21 my $group = 'test-httpd';
22 my $addr = $group . '@example.com';
23 my $cfgpfx = "publicinbox.$group";
24 my $httpd = 'blib/script/public-inbox-httpd';
25 my $init = 'blib/script/public-inbox-init';
28 LocalAddr => '127.0.0.1',
34 my $sock = IO::Socket::INET->new(%opts);
36 use_ok 'PublicInbox::Git';
37 use_ok 'PublicInbox::Import';
39 END { kill 'TERM', $pid if defined $pid };
41 local $ENV{HOME} = $home;
42 ok(!system($init, $group, $maindir, 'http://example.com/', $addr),
45 # ensure successful message delivery
47 my $mime = Email::MIME->new(<<EOF);
48 From: Me <me\@example.com>
49 To: You <you\@example.com>
51 Message-Id: <nntp\@example.com>
53 Date: Thu, 01 Jan 1970 06:06:06 +0000
58 my $git = PublicInbox::Git->new($maindir);
59 my $im = PublicInbox::Import->new($git, 'test', $addr);
63 ok($sock, 'sock created');
64 my $cmd = [ $httpd, "--stdout=$out", "--stderr=$err" ];
65 $pid = spawn_listener(undef, $cmd, [$sock]);
66 my $host = $sock->sockhost;
67 my $port = $sock->sockport;
68 my $conn = IO::Socket::INET->new(PeerAddr => $host,
72 ok($conn, 'connected');
73 ok($conn->write("GET / HTTP/1.0\r\n\r\n"), 'wrote data to socket');
76 ok($conn->read($buf, 4096), 'read some bytes');
77 like($buf, qr!\AHTTP/1\.[01] 404\b!, 'got 404 response');
78 is($conn->read($buf, 1), 0, "EOF");
81 is(system(qw(git clone -q --mirror),
82 "http://$host:$port/$group", "$tmpdir/clone.git"),
83 0, 'smart clone successful');
85 # ensure dumb cloning works, too:
86 is(system('git', "--git-dir=$maindir",
87 qw(config http.uploadpack false)),
88 0, 'disable http.uploadpack');
89 is(system(qw(git clone -q --mirror),
90 "http://$host:$port/$group", "$tmpdir/dumb.git"),
91 0, 'clone successful');
93 ok(kill('TERM', $pid), 'killed httpd');
97 is(system('git', "--git-dir=$tmpdir/clone.git",
98 qw(fsck --no-verbose)), 0,
99 'fsck on cloned directory successful');