git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/6] gitweb.perl : added ability to "git archive" just certain paths (files or subdirs, not whole repo) via gitweb interface
@ 2016-03-11 13:24 Jim Klimov
  2016-03-11 13:24 ` [PATCH 2/6] gitweb.perl : added ability to debug requests coming through gitweb interface by adding an option to request URL (also requires server-side envvar "GITWEB_MAY_DEBUG=yes") Jim Klimov
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Jim Klimov @ 2016-03-11 13:24 UTC (permalink / raw)
  To: git; +Cc: Jim Klimov

---
 gitweb/gitweb.perl | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 05d7910..030d429 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -7328,6 +7328,15 @@ sub git_snapshot {
 		die_error(403, "Unsupported snapshot format");
 	}
 
+	if (!defined($hash)) {
+		$hash="";
+		if ( $file_name && $file_name =~ /^([^:]*):(.*)$/ ) {
+			$hash = "$1";
+			$file_name = "$2";
+		}
+		if ( $hash eq "") { $hash = "HEAD"; }
+		printf STDERR "Defaulted hash to '$hash' ('h=' URL argument was missing)\n";
+	}
 	my $type = git_get_type("$hash^{}");
 	if (!$type) {
 		die_error(404, 'Object does not exist');
@@ -7345,6 +7354,14 @@ sub git_snapshot {
 		git_cmd(), 'archive',
 		"--format=$known_snapshot_formats{$format}{'format'}",
 		"--prefix=$prefix/", $hash);
+	if ($file_name) {
+		# To fetch several pathnames use space-separation, e.g.
+		# "...git-web?p=proj.git;a=snapshot;f=file1%20file2
+		# To fetch pathnames with spaces, escape them, e.g.
+		# "...git-web?p=proj.git;a=snapshot;f=file\%20name
+		$cmd .= " " . $file_name;
+	}
+
 	if (exists $known_snapshot_formats{$format}{'compressor'}) {
 		$cmd .= ' | ' . quote_command(@{$known_snapshot_formats{$format}{'compressor'}});
 	}
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/6] gitweb.perl : added ability to debug requests coming through gitweb interface by adding an option to request URL (also requires server-side envvar "GITWEB_MAY_DEBUG=yes")
  2016-03-11 13:24 [PATCH 1/6] gitweb.perl : added ability to "git archive" just certain paths (files or subdirs, not whole repo) via gitweb interface Jim Klimov
@ 2016-03-11 13:24 ` Jim Klimov
  2016-03-11 13:24 ` [PATCH 3/6] gitweb.perl : added ability to DEBUG progression through "git archive" Jim Klimov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jim Klimov @ 2016-03-11 13:24 UTC (permalink / raw)
  To: git; +Cc: Jim Klimov

---
 gitweb/gitweb.perl | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 030d429..c715472 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -74,6 +74,11 @@ sub evaluate_uri {
 	our $home_link = $my_uri || "/";
 }
 
+# Request parameters
+our ($action, $project, $DEBUG, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
+     $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
+     $searchtext, $search_regexp, $project_filter);
+
 # core git executable to use
 # this can just be "git" if your webserver has a sensible PATH
 our $GIT = "++GIT_BINDIR++/git";
@@ -803,6 +808,7 @@ our %input_params = ();
 our @cgi_param_mapping = (
 	project => "p",
 	action => "a",
+	debug => "debug",
 	file_name => "f",
 	file_parent => "fp",
 	hash => "h",
@@ -1033,9 +1039,6 @@ sub evaluate_path_info {
 	}
 }
 
-our ($action, $project, $file_name, $file_parent, $hash, $hash_parent, $hash_base,
-     $hash_parent_base, @extra_options, $page, $searchtype, $search_use_regexp,
-     $searchtext, $search_regexp, $project_filter);
 sub evaluate_and_validate_params {
 	our $action = $input_params{'action'};
 	if (defined $action) {
@@ -1053,6 +1056,23 @@ sub evaluate_and_validate_params {
 		}
 	}
 
+	our $DEBUG = $input_params{'debug'};
+	if (defined $DEBUG) {
+		if ( $DEBUG =~ /^([Yy][Ee][Ss]|[Oo][Nn]|1|[Tt][Rr][Uu][Ee])$/ ) {
+			if ( defined($ENV{'GITWEB_MAY_DEBUG'}) && $ENV{'GITWEB_MAY_DEBUG'} eq "yes" ) {
+				$DEBUG = 1; #true
+			} else {
+				printf STDERR "Invalid action parameter: DEBUG=$DEBUG was requested but server-side GITWEB_MAY_DEBUG=yes is not set\n";
+				die_error(403, "Invalid action parameter: DEBUG was requested but server-side GITWEB_MAY_DEBUG=yes is not set");
+				$DEBUG = 0; #false
+			}
+		} else {
+			$DEBUG = 0; #false
+		}
+	} else {
+		$DEBUG = 0;	# false
+	}
+
 	our $project_filter = $input_params{'project_filter'};
 	if (defined $project_filter) {
 		if (!is_valid_pathname($project_filter)) {
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/6] gitweb.perl : added ability to DEBUG progression through "git archive"
  2016-03-11 13:24 [PATCH 1/6] gitweb.perl : added ability to "git archive" just certain paths (files or subdirs, not whole repo) via gitweb interface Jim Klimov
  2016-03-11 13:24 ` [PATCH 2/6] gitweb.perl : added ability to debug requests coming through gitweb interface by adding an option to request URL (also requires server-side envvar "GITWEB_MAY_DEBUG=yes") Jim Klimov
@ 2016-03-11 13:24 ` Jim Klimov
  2016-03-11 13:24 ` [PATCH 4/6] gitweb.perl support for snapshots with lists of specified files is now tested Jim Klimov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jim Klimov @ 2016-03-11 13:24 UTC (permalink / raw)
  To: git; +Cc: Jim Klimov

---
 gitweb/gitweb.perl | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index c715472..fc5b62d 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -891,6 +891,7 @@ sub evaluate_query_params {
 # now read PATH_INFO and update the parameter list for missing parameters
 sub evaluate_path_info {
 	return if defined $input_params{'project'};
+	printf STDERR "path_info='$path_info'\n" if $DEBUG;
 	return if !$path_info;
 	$path_info =~ s,^/+,,;
 	return if !$path_info;
@@ -7336,6 +7337,24 @@ sub git_snapshot {
 	if (!@snapshot_fmts) {
 		die_error(403, "Snapshots not allowed");
 	}
+
+	if ($DEBUG) {
+		my $v; my $i;
+		printf STDERR "path_info='".$path_info."'\n";
+		printf STDERR "input_params: { ";
+		foreach $i (keys (%input_params)) {
+			$v = $input_params{$i};
+			if (defined ($v)) {
+				if ($i eq "extra_options" ) {
+					printf STDERR "  '$i' => [".@{$v}."] ; ";
+				} else {
+				printf STDERR "  '$i' => '$v' ; ";
+				}
+			}
+		}
+		printf STDERR "} \n";
+	}
+
 	# default to first supported snapshot format
 	$format ||= $snapshot_fmts[0];
 	if ($format !~ m/^[a-z0-9]+$/) {
@@ -7367,6 +7386,13 @@ sub git_snapshot {
 	my ($name, $prefix) = snapshot_name($project, $hash);
 	my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
 
+	if ($DEBUG) {
+		# name of the tarball to generate
+		if (defined $filename)  { printf STDERR "filename='$filename'\n"; }
+		# value of the 'f=' URL parameter
+		if (defined $file_name) { printf STDERR "file_name='$file_name'\n"; }
+	}
+
 	my %co = parse_commit($hash);
 	exit_if_unmodified_since($co{'committer_epoch'}) if %co;
 
@@ -7398,12 +7424,15 @@ sub git_snapshot {
 		%co ? (-last_modified => $latest_date{'rfc2822'}) : (),
 		-status => '200 OK');
 
+	printf STDERR "Starting git-archive: $cmd\n" if $DEBUG;
 	open my $fd, "-|", $cmd
 		or die_error(500, "Execute git-archive failed");
+	printf STDERR "Started git-archive...\n" if $DEBUG;
 	binmode STDOUT, ':raw';
 	print <$fd>;
 	binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
 	close $fd;
+	printf STDERR "Finished posting output of git-archive...\n" if $DEBUG;
 }
 
 sub git_log_generic {
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/6] gitweb.perl support for snapshots with lists of specified files is now tested
  2016-03-11 13:24 [PATCH 1/6] gitweb.perl : added ability to "git archive" just certain paths (files or subdirs, not whole repo) via gitweb interface Jim Klimov
  2016-03-11 13:24 ` [PATCH 2/6] gitweb.perl : added ability to debug requests coming through gitweb interface by adding an option to request URL (also requires server-side envvar "GITWEB_MAY_DEBUG=yes") Jim Klimov
  2016-03-11 13:24 ` [PATCH 3/6] gitweb.perl : added ability to DEBUG progression through "git archive" Jim Klimov
@ 2016-03-11 13:24 ` Jim Klimov
  2016-03-11 13:24 ` [PATCH 5/6] gitweb.perl changed (and tested) to return HTTP-404 when missing objects are requested via snapshot Jim Klimov
  2016-03-11 13:24 ` [PATCH 6/6] gitweb.perl : the optional DEBUG functionality is now unit-tested Jim Klimov
  4 siblings, 0 replies; 6+ messages in thread
From: Jim Klimov @ 2016-03-11 13:24 UTC (permalink / raw)
  To: git; +Cc: Jim Klimov

---
 t/t9502-gitweb-standalone-parse-output.sh | 156 ++++++++++++++++++++++++++++--
 1 file changed, 148 insertions(+), 8 deletions(-)

diff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh
index 0796a43..11a116f 100755
--- a/t/t9502-gitweb-standalone-parse-output.sh
+++ b/t/t9502-gitweb-standalone-parse-output.sh
@@ -27,25 +27,46 @@ $known_snapshot_formats{'tar'} = {
 $feature{'snapshot'}{'default'} = ['tar'];
 EOF
 
-# Call check_snapshot with the arguments "<basename> [<prefix>]"
+# Call list_snapshot with the argument "<basename>"
 #
 # This will check that gitweb HTTP header contains proposed filename
-# as <basename> with '.tar' suffix added, and that generated tarfile
-# (gitweb message body) has <prefix> as prefix for al files in tarfile
+# as <basename> with '.tar' suffix added, and lists its content to
+# stdout of this routine (in "tar test" default listing format)
 #
-# <prefix> default to <basename>
-check_snapshot () {
-	basename=$1
-	prefix=${2:-"$1"}
+# <prefix> defaults to <basename>
+#
+list_snapshot () {
+	basename="`echo "$1" | sed 's,\/,\.,g'`"
 	echo "basename=$basename"
 	grep "filename=.*$basename.tar" gitweb.headers >/dev/null 2>&1 &&
-	"$TAR" tf gitweb.body >file_list &&
+	"$TAR" tf gitweb.body >file_list
+}
+
+#
+# Call check_snapshot with the arguments "<basename> [<prefix>]"
+#
+# This uses list_snapshot() above to list the tarfile <basename>.tar received
+# from gitweb, and that this generated tarfile (gitweb message body) has
+# <prefix> prepended as prefix for all objects in the tarfile
+# The tarfile listing is exchanged via the "file_list" temporary file
+#
+# <prefix> defaults to <basename>
+#
+check_snapshot () {
+	basename="$1"
+	prefix=${2:-"$1"}
+	list_snapshot "$basename" &&
 	! grep -v -e "^$prefix$" -e "^$prefix/" -e "^pax_global_header$" file_list
 }
 
+# Note: the "xx/test" branch only contains file "foo"; others land in "master"
+# Call test_commit with the arguments "<message> [<file> [<contents> [<tag>]]]"
 test_expect_success setup '
 	test_commit first foo &&
+	mkdir -p dir1 && test_commit bar dir1/second bar second &&
 	git branch xx/test &&
+	mkdir -p dir2 && test_commit pif dir2/third pif third &&
+	test_commit wow dir2/"fourth file" wow wow &&
 	FULL_ID=$(git rev-parse --verify HEAD) &&
 	SHORT_ID=$(git rev-parse --verify --short=7 HEAD)
 '
@@ -112,6 +133,125 @@ test_expect_success 'snapshot: hierarchical branch name (xx/test)' '
 '
 test_debug 'cat gitweb.headers'
 
+test_expect_success 'snapshot sanity: have expected content in xx/test branch - do not have /first file in full snapshot' '
+	rm -f gitweb.body file_list &&
+	BRANCH=xx/test &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar" &&
+	ID=$(git rev-parse --verify --short=7 "$BRANCH") &&
+	list_snapshot ".git-$BRANCH-$ID" &&
+	! grep "first" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in master branch - only those under subdir dir2/ and not others' '
+	rm -f gitweb.body file_list &&
+	BRANCH=master &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2" &&
+	ID=$(git rev-parse --verify --short=7 "$BRANCH") &&
+	list_snapshot ".git-$BRANCH-$ID" &&
+	! grep "foo" file_list &&
+	! grep "dir1/second" file_list &&
+	grep "dir2/third" file_list &&
+	grep "dir2/fourth file" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in master branch - subdir name is required in requested nested path (bad path - empty output)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=master &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=third" &&
+	[ ! -s gitweb.body ]
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in master branch - correct subdir name is required in requested nested path (bad path - empty output)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=master &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir1/third" &&
+	[ ! -s gitweb.body ]
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in master branch - can request filenames with spaces (backslash + HTML-escape)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=master &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2/fourth\%20file" &&
+	ID=$(git rev-parse --verify --short=7 "$BRANCH") &&
+	list_snapshot ".git-$BRANCH-$ID" &&
+	! grep "foo" file_list &&
+	! grep "dir1/second" file_list &&
+	! grep "dir2/third" file_list &&
+	grep "dir2/fourth file" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in master branch - can request list of filenames separated by HTML-escaped spaces' '
+	rm -f gitweb.body file_list &&
+	BRANCH=master &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir1/second%20dir2/third" &&
+	ID=$(git rev-parse --verify --short=7 "$BRANCH") &&
+	list_snapshot ".git-$BRANCH-$ID" &&
+	! grep "foo" file_list &&
+	grep "dir1/second" file_list &&
+	grep "dir2/third" file_list &&
+	! grep "dir2/fourth file" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in master branch - can request list of filenames separated by HTML-escaped spaces including a filename with spaces (backslash + HTML-escape)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=master &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=foo%20dir2/fourth\%20file%20dir1/second" &&
+	ID=$(git rev-parse --verify --short=7 "$BRANCH") &&
+	list_snapshot ".git-$BRANCH-$ID" &&
+	grep "foo" file_list &&
+	grep "dir1/second" file_list &&
+	! grep "dir2/third" file_list &&
+	grep "dir2/fourth file" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have only expected content in refs/tags/second full tag' '
+	rm -f gitweb.body file_list &&
+	BRANCH=second &&
+	gitweb_run "p=.git;a=snapshot;h=refs/tags/$BRANCH;sf=tar;f=dir1/second" &&
+	list_snapshot ".git-$BRANCH" &&
+	! grep "foo" file_list &&
+	grep "dir1/second" file_list &&
+	! grep "dir2/third" file_list &&
+	! grep "dir2/fourth file" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
+test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for only absent subdir dir2/ fails (empty output)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=xx/test &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2" &&
+        [ ! -s "gitweb.body" ]
+'
+test_debug 'cat gitweb.headers'
+
+test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for file /foo and absent subdir dir2/ also fails (empty output)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=xx/test &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2%20foo" &&
+        [ ! -s "gitweb.body" ]
+'
+test_debug 'cat gitweb.headers'
+
+test_expect_success 'snapshot certain objects: have expected content in xx/test branch - have /foo file (and only it)' '
+	rm -f gitweb.body file_list &&
+	BRANCH=xx/test &&
+	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=foo" &&
+	ID=$(git rev-parse --verify --short=7 "$BRANCH") &&
+	list_snapshot ".git-$BRANCH-$ID" &&
+	grep "foo" file_list &&
+	! grep "dir1/second" file_list &&
+	! grep "dir2/third" file_list &&
+	! grep "dir2/fourth file" file_list
+'
+test_debug 'cat gitweb.headers && cat file_list'
+
 # ----------------------------------------------------------------------
 # forks of projects
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/6] gitweb.perl changed (and tested) to return HTTP-404 when missing objects are requested via snapshot
  2016-03-11 13:24 [PATCH 1/6] gitweb.perl : added ability to "git archive" just certain paths (files or subdirs, not whole repo) via gitweb interface Jim Klimov
                   ` (2 preceding siblings ...)
  2016-03-11 13:24 ` [PATCH 4/6] gitweb.perl support for snapshots with lists of specified files is now tested Jim Klimov
@ 2016-03-11 13:24 ` Jim Klimov
  2016-03-11 13:24 ` [PATCH 6/6] gitweb.perl : the optional DEBUG functionality is now unit-tested Jim Klimov
  4 siblings, 0 replies; 6+ messages in thread
From: Jim Klimov @ 2016-03-11 13:24 UTC (permalink / raw)
  To: git; +Cc: Jim Klimov

---
 gitweb/gitweb.perl                        | 62 +++++++++++++++++++++++++------
 t/t9502-gitweb-standalone-parse-output.sh | 24 ++++++------
 2 files changed, 63 insertions(+), 23 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index fc5b62d..2369ae3 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -7418,20 +7418,60 @@ sub git_snapshot {
 		%latest_date = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
 	}
 
-	print $cgi->header(
-		-type => $known_snapshot_formats{$format}{'type'},
-		-content_disposition => 'inline; filename="' . $filename . '"',
-		%co ? (-last_modified => $latest_date{'rfc2822'}) : (),
-		-status => '200 OK');
-
 	printf STDERR "Starting git-archive: $cmd\n" if $DEBUG;
-	open my $fd, "-|", $cmd
-		or die_error(500, "Execute git-archive failed");
+	my $fd;
+	if ( ! open $fd, "-|", $cmd ) {
+		print $cgi->header(-status => '500 Execute git-archive failed');
+		die_error(500, "Execute git-archive failed");
+		return;
+	}
 	printf STDERR "Started git-archive...\n" if $DEBUG;
-	binmode STDOUT, ':raw';
-	print <$fd>;
-	binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
+	my $tempByte;
+	my $readSize = read ($fd, $tempByte, 1);
+	my $retCode = 200;
+	if ( defined $readSize ) {
+		if ( $readSize > 0 ) {
+			print $cgi->header(
+				-type => $known_snapshot_formats{$format}{'type'},
+				-content_disposition => 'inline; filename="' . $filename . '"',
+				%co ? (-last_modified => $latest_date{'rfc2822'}) : (),
+				-status => '200 OK' );
+			binmode STDOUT, ':raw';
+			print $tempByte;
+			if ( ! print <$fd> ) {
+				$retCode = 503;
+			}
+			binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
+		} else {
+			$retCode = 404;
+		}
+	} else {
+		$readSize = -1;
+		$retCode = 500;
+	}
+
 	close $fd;
+	my $retError = "" ;
+	if ( ($? >> 8) != 0 ) {
+		$retCode = 500;
+		if ( $readSize == 0 ) {
+			# We had empty but not failed read - re-inspect stderr
+			$retError = `$cmd 2>&1`;
+			if ( $retError =~ /did not match any/ ) {
+				$retCode = 404;
+			}
+		}
+	}
+	if ( $retError ne "" ) {
+		$retError = "<br/><pre>$retError</pre><br/>";
+	}
+
+	if ( $retCode == 404 ) {
+		die_error(404, "Not Found - maybe requested objects absent in git path?" . "$retError");
+	} elsif ( $retCode == 500 ) {
+		die_error(500, "Failed to transmit output from git-archive" . "$retError");
+	}
+
 	printf STDERR "Finished posting output of git-archive...\n" if $DEBUG;
 }
 
diff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh
index 11a116f..a2ae5c4 100755
--- a/t/t9502-gitweb-standalone-parse-output.sh
+++ b/t/t9502-gitweb-standalone-parse-output.sh
@@ -156,21 +156,21 @@ test_expect_success 'snapshot certain objects: have expected content in master b
 '
 test_debug 'cat gitweb.headers && cat file_list'
 
-test_expect_success 'snapshot certain objects: have expected content in master branch - subdir name is required in requested nested path (bad path - empty output)' '
+test_expect_success 'snapshot certain objects: have expected content in master branch - subdir name is required in requested nested path (bad path - empty output and/or HTTP-404)' '
 	rm -f gitweb.body file_list &&
 	BRANCH=master &&
 	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=third" &&
-	[ ! -s gitweb.body ]
+	[ ! -s gitweb.body -o -n "`head -1 gitweb.headers | egrep "^Status: 404 "`" ]
 '
-test_debug 'cat gitweb.headers && cat file_list'
+test_debug 'cat gitweb.headers && ls -la gitweb.body file_list || true'
 
-test_expect_success 'snapshot certain objects: have expected content in master branch - correct subdir name is required in requested nested path (bad path - empty output)' '
+test_expect_success 'snapshot certain objects: have expected content in master branch - correct subdir name is required in requested nested path (bad path - empty output and/or HTTP-404)' '
 	rm -f gitweb.body file_list &&
 	BRANCH=master &&
 	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir1/third" &&
-	[ ! -s gitweb.body ]
+	[ ! -s gitweb.body -o -n "`head -1 gitweb.headers | egrep "^Status: 404 "`" ]
 '
-test_debug 'cat gitweb.headers && cat file_list'
+test_debug 'cat gitweb.headers && ls -la gitweb.body file_list || true'
 
 test_expect_success 'snapshot certain objects: have expected content in master branch - can request filenames with spaces (backslash + HTML-escape)' '
 	rm -f gitweb.body file_list &&
@@ -223,21 +223,21 @@ test_expect_success 'snapshot certain objects: have only expected content in ref
 '
 test_debug 'cat gitweb.headers && cat file_list'
 
-test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for only absent subdir dir2/ fails (empty output)' '
+test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for only absent subdir dir2/ fails (empty output and/or HTTP-404)' '
 	rm -f gitweb.body file_list &&
 	BRANCH=xx/test &&
 	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2" &&
-        [ ! -s "gitweb.body" ]
+	[ ! -s gitweb.body -o -n "`head -1 gitweb.headers | egrep "^Status: 404 "`" ]
 '
-test_debug 'cat gitweb.headers'
+test_debug 'cat gitweb.headers && ls -la gitweb.body file_list || true'
 
-test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for file /foo and absent subdir dir2/ also fails (empty output)' '
+test_expect_success 'snapshot certain objects: have expected content in xx/test branch - request for file /foo and absent subdir dir2/ also fails (empty output and/or HTTP-404)' '
 	rm -f gitweb.body file_list &&
 	BRANCH=xx/test &&
 	gitweb_run "p=.git;a=snapshot;h=$BRANCH;sf=tar;f=dir2%20foo" &&
-        [ ! -s "gitweb.body" ]
+	[ ! -s gitweb.body -o -n "`head -1 gitweb.headers | egrep "^Status: 404 "`" ]
 '
-test_debug 'cat gitweb.headers'
+test_debug 'cat gitweb.headers && ls -la gitweb.body file_list || true'
 
 test_expect_success 'snapshot certain objects: have expected content in xx/test branch - have /foo file (and only it)' '
 	rm -f gitweb.body file_list &&
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 6/6] gitweb.perl : the optional DEBUG functionality is now unit-tested
  2016-03-11 13:24 [PATCH 1/6] gitweb.perl : added ability to "git archive" just certain paths (files or subdirs, not whole repo) via gitweb interface Jim Klimov
                   ` (3 preceding siblings ...)
  2016-03-11 13:24 ` [PATCH 5/6] gitweb.perl changed (and tested) to return HTTP-404 when missing objects are requested via snapshot Jim Klimov
@ 2016-03-11 13:24 ` Jim Klimov
  4 siblings, 0 replies; 6+ messages in thread
From: Jim Klimov @ 2016-03-11 13:24 UTC (permalink / raw)
  To: git; +Cc: Jim Klimov

---
 t/t9502-gitweb-standalone-parse-output.sh | 35 +++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/t/t9502-gitweb-standalone-parse-output.sh b/t/t9502-gitweb-standalone-parse-output.sh
index a2ae5c4..4f1ddbf 100755
--- a/t/t9502-gitweb-standalone-parse-output.sh
+++ b/t/t9502-gitweb-standalone-parse-output.sh
@@ -253,6 +253,41 @@ test_expect_success 'snapshot certain objects: have expected content in xx/test
 test_debug 'cat gitweb.headers && cat file_list'
 
 # ----------------------------------------------------------------------
+# optional debugging in log, if allowed on server and requested by user
+
+test_expect_success 'snapshot: debugging logged as forbidden when not defined in server environment' '
+	rm -f gitweb.body gitweb.log gitweb.headers gitweb.output &&
+	gitweb_run "p=.git;a=snapshot;h=master;sf=tar;debug=yes" &&
+	grep "GITWEB_MAY_DEBUG=yes is not set" < gitweb.log >/dev/null
+'
+test_debug 'cat gitweb.headers gitweb.log'
+
+test_expect_success 'snapshot: debugging logged as forbidden when not allowed in server environment' '
+	rm -f gitweb.body gitweb.log gitweb.headers gitweb.output &&
+	GITWEB_MAY_DEBUG=xxx && export GITWEB_MAY_DEBUG &&
+	gitweb_run "p=.git;a=snapshot;h=master;sf=tar;debug=yes" &&
+	grep "GITWEB_MAY_DEBUG=yes is not set" < gitweb.log >/dev/null
+'
+test_debug 'cat gitweb.headers gitweb.log'
+
+test_expect_success 'snapshot: debugging present when allowed in server environment' '
+	rm -f gitweb.body gitweb.log gitweb.headers gitweb.output &&
+	GITWEB_MAY_DEBUG=yes && export GITWEB_MAY_DEBUG &&
+	gitweb_run "p=.git;a=snapshot;h=master;sf=tar;debug=yes" &&
+	! grep "GITWEB_MAY_DEBUG=yes is not set" < gitweb.log >/dev/null &&
+	grep "git-archive" < gitweb.log >/dev/null
+'
+test_debug 'cat gitweb.headers gitweb.log'
+
+test_expect_success 'snapshot: debugging absent when not allowed in server environment' '
+	rm -f gitweb.body gitweb.log gitweb.headers gitweb.output &&
+	GITWEB_MAY_DEBUG=xxx && export GITWEB_MAY_DEBUG &&
+	gitweb_run "p=.git;a=snapshot;h=master;sf=tar;debug=yes" &&
+	! grep "git-archive" < gitweb.log >/dev/null
+'
+test_debug 'cat gitweb.headers gitweb.log'
+
+# ----------------------------------------------------------------------
 # forks of projects
 
 test_expect_success 'forks: setup' '
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-03-11 13:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-11 13:24 [PATCH 1/6] gitweb.perl : added ability to "git archive" just certain paths (files or subdirs, not whole repo) via gitweb interface Jim Klimov
2016-03-11 13:24 ` [PATCH 2/6] gitweb.perl : added ability to debug requests coming through gitweb interface by adding an option to request URL (also requires server-side envvar "GITWEB_MAY_DEBUG=yes") Jim Klimov
2016-03-11 13:24 ` [PATCH 3/6] gitweb.perl : added ability to DEBUG progression through "git archive" Jim Klimov
2016-03-11 13:24 ` [PATCH 4/6] gitweb.perl support for snapshots with lists of specified files is now tested Jim Klimov
2016-03-11 13:24 ` [PATCH 5/6] gitweb.perl changed (and tested) to return HTTP-404 when missing objects are requested via snapshot Jim Klimov
2016-03-11 13:24 ` [PATCH 6/6] gitweb.perl : the optional DEBUG functionality is now unit-tested Jim Klimov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).