Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 909beb8

Browse files
committed
Merge branch 'mr/gitweb-snapshot'
* mr/gitweb-snapshot: gitweb: add t9501 tests for checking HTTP status codes gitweb: split test suite into library and tests gitweb: improve snapshot error handling
2 parents d34eca0 + e39e0d3 commit 909beb8

File tree

4 files changed

+154
-68
lines changed

4 files changed

+154
-68
lines changed

gitweb/gitweb.perl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5190,10 +5190,10 @@ sub git_snapshot {
51905190
die_error(400, "Invalid snapshot format parameter");
51915191
} elsif (!exists($known_snapshot_formats{$format})) {
51925192
die_error(400, "Unknown snapshot format");
5193-
} elsif (!grep($_ eq $format, @snapshot_fmts)) {
5194-
die_error(403, "Unsupported snapshot format");
51955193
} elsif ($known_snapshot_formats{$format}{'disabled'}) {
51965194
die_error(403, "Snapshot format not allowed");
5195+
} elsif (!grep($_ eq $format, @snapshot_fmts)) {
5196+
die_error(403, "Unsupported snapshot format");
51975197
}
51985198

51995199
if (!defined $hash) {

t/gitweb-lib.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2007 Jakub Narebski
4+
#
5+
6+
gitweb_init () {
7+
safe_pwd="$(perl -MPOSIX=getcwd -e 'print quotemeta(getcwd)')"
8+
cat >gitweb_config.perl <<EOF
9+
#!/usr/bin/perl
10+
11+
# gitweb configuration for tests
12+
13+
our \$version = 'current';
14+
our \$GIT = 'git';
15+
our \$projectroot = "$safe_pwd";
16+
our \$project_maxdepth = 8;
17+
our \$home_link_str = 'projects';
18+
our \$site_name = '[localhost]';
19+
our \$site_header = '';
20+
our \$site_footer = '';
21+
our \$home_text = 'indextext.html';
22+
our @stylesheets = ('file:///$TEST_DIRECTORY/../gitweb/gitweb.css');
23+
our \$logo = 'file:///$TEST_DIRECTORY/../gitweb/git-logo.png';
24+
our \$favicon = 'file:///$TEST_DIRECTORY/../gitweb/git-favicon.png';
25+
our \$projects_list = '';
26+
our \$export_ok = '';
27+
our \$strict_export = '';
28+
29+
EOF
30+
31+
cat >.git/description <<EOF
32+
$0 test repository
33+
EOF
34+
}
35+
36+
gitweb_run () {
37+
GATEWAY_INTERFACE='CGI/1.1'
38+
HTTP_ACCEPT='*/*'
39+
REQUEST_METHOD='GET'
40+
SCRIPT_NAME="$TEST_DIRECTORY/../gitweb/gitweb.perl"
41+
QUERY_STRING=""$1""
42+
PATH_INFO=""$2""
43+
export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \
44+
SCRIPT_NAME QUERY_STRING PATH_INFO
45+
46+
GITWEB_CONFIG=$(pwd)/gitweb_config.perl
47+
export GITWEB_CONFIG
48+
49+
# some of git commands write to STDERR on error, but this is not
50+
# written to web server logs, so we are not interested in that:
51+
# we are interested only in properly formatted errors/warnings
52+
rm -f gitweb.log &&
53+
perl -- "$SCRIPT_NAME" \
54+
>gitweb.output 2>gitweb.log &&
55+
if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi
56+
57+
# gitweb.log is left for debugging
58+
# gitweb.output is used to parse http output
59+
}
60+
61+
. ./test-lib.sh
62+
63+
if ! test_have_prereq PERL; then
64+
say 'skipping gitweb tests, perl not available'
65+
test_done
66+
fi
67+
68+
perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || {
69+
say 'skipping gitweb tests, perl version is too old'
70+
test_done
71+
}
72+
73+
gitweb_init

t/t9500-gitweb-standalone-no-errors.sh

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,73 +9,8 @@ This test runs gitweb (git web interface) as CGI script from
99
commandline, and checks that it would not write any errors
1010
or warnings to log.'
1111

12-
gitweb_init () {
13-
safe_pwd="$(perl -MPOSIX=getcwd -e 'print quotemeta(getcwd)')"
14-
cat >gitweb_config.perl <<EOF
15-
#!/usr/bin/perl
16-
17-
# gitweb configuration for tests
18-
19-
our \$version = "current";
20-
our \$GIT = "git";
21-
our \$projectroot = "$safe_pwd";
22-
our \$project_maxdepth = 8;
23-
our \$home_link_str = "projects";
24-
our \$site_name = "[localhost]";
25-
our \$site_header = "";
26-
our \$site_footer = "";
27-
our \$home_text = "indextext.html";
28-
our @stylesheets = ("file:///$TEST_DIRECTORY/../gitweb/gitweb.css");
29-
our \$logo = "file:///$TEST_DIRECTORY/../gitweb/git-logo.png";
30-
our \$favicon = "file:///$TEST_DIRECTORY/../gitweb/git-favicon.png";
31-
our \$projects_list = "";
32-
our \$export_ok = "";
33-
our \$strict_export = "";
3412

35-
EOF
36-
37-
cat >.git/description <<EOF
38-
$0 test repository
39-
EOF
40-
}
41-
42-
gitweb_run () {
43-
GATEWAY_INTERFACE="CGI/1.1"
44-
HTTP_ACCEPT="*/*"
45-
REQUEST_METHOD="GET"
46-
SCRIPT_NAME="$TEST_DIRECTORY/../gitweb/gitweb.perl"
47-
QUERY_STRING=""$1""
48-
PATH_INFO=""$2""
49-
export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \
50-
SCRIPT_NAME QUERY_STRING PATH_INFO
51-
52-
GITWEB_CONFIG=$(pwd)/gitweb_config.perl
53-
export GITWEB_CONFIG
54-
55-
# some of git commands write to STDERR on error, but this is not
56-
# written to web server logs, so we are not interested in that:
57-
# we are interested only in properly formatted errors/warnings
58-
rm -f gitweb.log &&
59-
perl -- "$SCRIPT_NAME" \
60-
>/dev/null 2>gitweb.log &&
61-
if grep "^[[]" gitweb.log >/dev/null 2>&1; then false; else true; fi
62-
63-
# gitweb.log is left for debugging
64-
}
65-
66-
. ./test-lib.sh
67-
68-
if ! test_have_prereq PERL; then
69-
say 'skipping gitweb tests, perl not available'
70-
test_done
71-
fi
72-
73-
perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || {
74-
say 'skipping gitweb tests, perl version is too old'
75-
test_done
76-
}
77-
78-
gitweb_init
13+
. ./gitweb-lib.sh
7914

8015
# ----------------------------------------------------------------------
8116
# no commits (empty, just initialized repository)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2009 Mark Rada
4+
#
5+
6+
test_description='gitweb as standalone script (http status tests).
7+
8+
This test runs gitweb (git web interface) as a CGI script from the
9+
commandline, and checks that it returns the expected HTTP status
10+
code and message.'
11+
12+
13+
. ./gitweb-lib.sh
14+
15+
# ----------------------------------------------------------------------
16+
# snapshot settings
17+
18+
test_commit \
19+
'SnapshotTests' \
20+
'i can has snapshot?'
21+
22+
cat >>gitweb_config.perl <<\EOF
23+
$feature{'snapshot'}{'override'} = 0;
24+
EOF
25+
26+
test_expect_success \
27+
'snapshots: tgz only default format enabled' \
28+
'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
29+
grep "Status: 200 OK" gitweb.output &&
30+
gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" &&
31+
grep "403 - Unsupported snapshot format" gitweb.output &&
32+
gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" &&
33+
grep "403 - Snapshot format not allowed" gitweb.output &&
34+
gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
35+
grep "403 - Unsupported snapshot format" gitweb.output'
36+
test_debug 'cat gitweb.output'
37+
38+
39+
cat >>gitweb_config.perl <<\EOF
40+
$feature{'snapshot'}{'default'} = ['tgz','tbz2','txz','zip'];
41+
EOF
42+
43+
test_expect_success \
44+
'snapshots: all enabled in default, use default disabled value' \
45+
'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
46+
grep "Status: 200 OK" gitweb.output &&
47+
gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" &&
48+
grep "Status: 200 OK" gitweb.output &&
49+
gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" &&
50+
grep "403 - Snapshot format not allowed" gitweb.output &&
51+
gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
52+
grep "Status: 200 OK" gitweb.output'
53+
test_debug 'cat gitweb.output'
54+
55+
56+
cat >>gitweb_config.perl <<\EOF
57+
$known_snapshot_formats{'zip'}{'disabled'} = 1;
58+
EOF
59+
60+
test_expect_success \
61+
'snapshots: zip explicitly disabled' \
62+
'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
63+
grep "403 - Snapshot format not allowed" gitweb.output'
64+
test_debug 'cat gitweb.output'
65+
66+
67+
cat >>gitweb_config.perl <<\EOF
68+
$known_snapshot_formats{'tgz'}{'disabled'} = 0;
69+
EOF
70+
71+
test_expect_success \
72+
'snapshots: tgz explicitly enabled' \
73+
'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
74+
grep "Status: 200 OK" gitweb.output'
75+
test_debug 'cat gitweb.output'
76+
77+
78+
test_done

0 commit comments

Comments
 (0)