# Copyright (C) 2016 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+#
+# Integration test for public-inbox-httpd and (git) repobrowse
+# since we may use some special APIs not available in other servers
use strict;
use warnings;
use Test::More;
-my $test = require './t/repobrowse_common_git.perl';
-foreach my $mod (qw(Danga::Socket HTTP::Parser::XS HTTP::Date HTTP::Status)) {
+foreach my $mod (qw(Danga::Socket HTTP::Parser::XS HTTP::Date HTTP::Status
+ Plack::Test::ExternalServer)) {
eval "require $mod";
- plan skip_all => "$mod missing for repobrowse_git_fallback.t" if $@;
+ plan skip_all => "$mod missing for repobrowse_git_httpd.t" if $@;
}
+my $test = require './t/repobrowse_common_git.perl';
+$Plack::Test::Impl = 'ExternalServer';
use File::Temp qw/tempdir/;
use Cwd qw/getcwd/;
use IO::Socket;
use Fcntl qw(F_SETFD);
use POSIX qw(dup2);
-my $tmpdir = tempdir('repobrowse_git_fallback-XXXXXX', TMPDIR => 1, CLEANUP => 1);
+my $tmpdir = tempdir('repobrowse_git_httpd-XXXXXX', TMPDIR => 1, CLEANUP => 1);
my $err = "$tmpdir/stderr.log";
my $out = "$tmpdir/stdout.log";
my $httpd = 'blib/script/public-inbox-httpd';
Listen => 1024,
);
my $sock = IO::Socket::INET->new(%opts);
+my $host = $sock->sockhost;
+my $port = $sock->sockport;
+my $uri = "http://$host:$port/";
my $pid;
END { kill 'TERM', $pid if defined $pid };
my $spawn_httpd = sub {
$spawn_httpd->();
-{
- my $host = $sock->sockhost;
- my $port = $sock->sockport;
- my $url = "http://$host:$port/test.git";
+{ # git clone tests
+ my $url = $uri . 'test.git';
is(system(qw(git clone -q --mirror), $url, "$tmpdir/smart.git"),
0, 'smart clone successful');
is(system('git', "--git-dir=$tmpdir/smart.git", 'fsck'), 0, 'fsck OK');
-
is(system('git', "--git-dir=$test->{git_dir}",
qw(config http.uploadpack 0)), 0, 'disabled smart HTTP');
is(system('git', "--git-dir=$test->{git_dir}",
qw(update-server-info)), 0, 'enable dumb HTTP');
is(system(qw(git clone -q --mirror), $url, "$tmpdir/dumb.git"),
0, 'dumb clone successful');
- is(system('git', "--git-dir=$tmpdir/dumb.git", 'fsck'), 0, 'fsck dumb OK');
+ is(system('git', "--git-dir=$tmpdir/dumb.git", 'fsck'),
+ 0, 'fsck dumb OK');
+}
+test_psgi(uri => $uri, client => sub {
+ my ($cb) = @_;
+ my $res = $cb->(GET($uri . 'test.git/info/refs'));
+ is(200, $res->code, 'got info/refs');
+
+ $res = $cb->(GET($uri . 'best.git/info/refs'));
+ is(404, $res->code, 'bad request fails');
+
+ $res = $cb->(GET($uri . 'test.git/patch'));
+ is(200, $res->code, 'got patch');
+ is('text/plain; charset=UTF-8', $res->header('Content-Type'),
+ 'got proper content-type with patch');
+
+ # ignore signature from git-format-patch:
+ my ($patch, undef) = split(/\n-- \n/s, $res->content);
+ my ($exp, undef) = split(/\n-- \n/s,
+ `cd "$test->{git_dir}" && \
+ git format-patch -1 -M --stdout HEAD`);
+ is($patch, $exp, 'patch content matches expected');
+});
+
+{
# allow reading description file
my %conn = ( PeerAddr => $host, PeerPort => $port, Proto => 'tcp',
Type => SOCK_STREAM);