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 Danga::Socket
8 HTTP::Date HTTP::Status)) {
10 plan skip_all => "$mod missing for httpd.t" if $@;
12 use File::Temp qw/tempdir/;
15 use Socket qw(SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
16 require './t/common.perl';
18 # FIXME: too much setup
19 my $tmpdir = tempdir('pi-httpd-XXXXXX', TMPDIR => 1, CLEANUP => 1);
20 my $home = "$tmpdir/pi-home";
21 my $err = "$tmpdir/stderr.log";
22 my $out = "$tmpdir/stdout.log";
23 my $maindir = "$tmpdir/main.git";
24 my $group = 'test-httpd';
25 my $addr = $group . '@example.com';
26 my $cfgpfx = "publicinbox.$group";
27 my $httpd = 'blib/script/public-inbox-httpd';
28 my $init = 'blib/script/public-inbox-init';
31 LocalAddr => '127.0.0.1',
37 my $sock = IO::Socket::INET->new(%opts);
39 use_ok 'PublicInbox::Git';
40 use_ok 'PublicInbox::Import';
42 END { kill 'TERM', $pid if defined $pid };
44 local $ENV{HOME} = $home;
45 ok(!system($init, $group, $maindir, 'http://example.com/', $addr),
48 # ensure successful message delivery
50 my $mime = Email::MIME->new(<<EOF);
51 From: Me <me\@example.com>
52 To: You <you\@example.com>
54 Message-Id: <nntp\@example.com>
56 Date: Thu, 01 Jan 1970 06:06:06 +0000
61 my $git = PublicInbox::Git->new($maindir);
62 my $im = PublicInbox::Import->new($git, 'test', $addr);
66 ok($sock, 'sock created');
67 my $cmd = [ $httpd, "--stdout=$out", "--stderr=$err" ];
68 $pid = spawn_listener(undef, $cmd, [$sock]);
69 my $host = $sock->sockhost;
70 my $port = $sock->sockport;
71 my $conn = IO::Socket::INET->new(PeerAddr => $host,
75 ok($conn, 'connected');
76 ok($conn->write("GET / HTTP/1.0\r\n\r\n"), 'wrote data to socket');
79 ok($conn->read($buf, 4096), 'read some bytes');
80 like($buf, qr!\AHTTP/1\.[01] 404\b!, 'got 404 response');
81 is($conn->read($buf, 1), 0, "EOF");
84 is(system(qw(git clone -q --mirror),
85 "http://$host:$port/$group", "$tmpdir/clone.git"),
86 0, 'smart clone successful');
88 # ensure dumb cloning works, too:
89 is(system('git', "--git-dir=$maindir",
90 qw(config http.uploadpack false)),
91 0, 'disable http.uploadpack');
92 is(system(qw(git clone -q --mirror),
93 "http://$host:$port/$group", "$tmpdir/dumb.git"),
94 0, 'clone successful');
96 ok(kill('TERM', $pid), 'killed httpd');
100 is(system('git', "--git-dir=$tmpdir/clone.git",
101 qw(fsck --no-verbose)), 0,
102 'fsck on cloned directory successful');