Browse Source

Cleanup: message reporting for HTTP redirect handling

The addition of "tooManyRedirects" in commit 7ac1bfc ("Do
authentication re-tries on HTTP POST") was an error I didn't
catch after rebasing that change. That message had been renamed
in the earlier commit e17bfc9 ("Add support to follow HTTP
redirects") to "redirectLimitExceeded".

Also make sure we always use the TransportException(URIish, ...)
constructor; it'll prefix the message given with the sanitized URI.
Change messages to remove the explicit mention of that URI inside the
message. Adapt tests that check the expected exception message text.

For the info logging of redirects, remove a potentially present
password component in the URI to avoid leaking it into the log.

Change-Id: I517112404757a9a947e92aaace743c6541dce6aa
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
stable-4.9
Thomas Wolf 7 years ago
parent
commit
1b4daa2994
  1. 8
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
  2. 11
      org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
  3. 1
      org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
  4. 33
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java

8
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java

@ -595,9 +595,9 @@ public class SmartClientSmartServerTest extends HttpTestCase {
t.fetch(NullProgressMonitor.INSTANCE, mirror(master)); t.fetch(NullProgressMonitor.INSTANCE, mirror(master));
fail("Should have failed (too many redirects)"); fail("Should have failed (too many redirects)");
} catch (TransportException e) { } catch (TransportException e) {
String expectedMessageBegin = MessageFormat.format( String expectedMessageBegin = remoteUri.toString() + ": "
JGitText.get().redirectLimitExceeded, remoteUri, "3", + MessageFormat.format(JGitText.get().redirectLimitExceeded,
remoteUri.replace("/4/", "/1/") + '/', ""); "3", remoteUri.replace("/4/", "/1/") + '/', "");
String message = e.getMessage(); String message = e.getMessage();
if (message.length() > expectedMessageBegin.length()) { if (message.length() > expectedMessageBegin.length()) {
message = message.substring(0, expectedMessageBegin.length()); message = message.substring(0, expectedMessageBegin.length());
@ -616,7 +616,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
t.fetch(NullProgressMonitor.INSTANCE, mirror(master)); t.fetch(NullProgressMonitor.INSTANCE, mirror(master));
fail("Should have failed (redirect loop)"); fail("Should have failed (redirect loop)");
} catch (TransportException e) { } catch (TransportException e) {
assertTrue(e.getMessage().contains("redirected more than")); assertTrue(e.getMessage().contains("Redirected more than"));
} }
} }

11
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties

@ -365,7 +365,7 @@ invalidPathContainsSeparator=Invalid path (contains separator ''{0}''): {1}
invalidPathPeriodAtEndWindows=Invalid path (period at end is ignored by Windows): {0} invalidPathPeriodAtEndWindows=Invalid path (period at end is ignored by Windows): {0}
invalidPathSpaceAtEndWindows=Invalid path (space at end is ignored by Windows): {0} invalidPathSpaceAtEndWindows=Invalid path (space at end is ignored by Windows): {0}
invalidPathReservedOnWindows=Invalid path (''{0}'' is reserved on Windows): {1} invalidPathReservedOnWindows=Invalid path (''{0}'' is reserved on Windows): {1}
invalidRedirectLocation=Invalid redirect location {1} -> {2} invalidRedirectLocation=Invalid redirect location {0} -> {1}
invalidReflogRevision=Invalid reflog revision: {0} invalidReflogRevision=Invalid reflog revision: {0}
invalidRefName=Invalid ref name: {0} invalidRefName=Invalid ref name: {0}
invalidReftableBlock=Invalid reftable block invalidReftableBlock=Invalid reftable block
@ -535,11 +535,11 @@ receivePackObjectTooLarge2=Object too large ({0} bytes), rejecting the pack. Max
receivePackInvalidLimit=Illegal limit parameter value {0} receivePackInvalidLimit=Illegal limit parameter value {0}
receivePackTooLarge=Pack exceeds the limit of {0} bytes, rejecting the pack receivePackTooLarge=Pack exceeds the limit of {0} bytes, rejecting the pack
receivingObjects=Receiving objects receivingObjects=Receiving objects
redirectBlocked=URI ''{0}'' redirection blocked: redirect {1} -> {2} not allowed redirectBlocked=Redirection blocked: redirect {0} -> {1} not allowed
redirectHttp=URI ''{0}'': following HTTP redirect #{1} {2} -> {3} redirectHttp=URI ''{0}'': following HTTP redirect #{1} {2} -> {3}
redirectLimitExceeded=URI ''{0}'' redirected more than {1} times; aborted at {2} -> {3} redirectLimitExceeded=Redirected more than {0} times; aborted at {1} -> {2}
redirectLocationMissing=Invalid redirect of ''{0}'': no redirect location for {1} redirectLocationMissing=Invalid redirect: no redirect location for {0}
redirectsOff=Cannot redirect ''{0}'': http.followRedirects is false (HTTP status {1}) redirectsOff=Cannot redirect because http.followRedirects is false (HTTP status {0})
refAlreadyExists=already exists refAlreadyExists=already exists
refAlreadyExists1=Ref {0} already exists refAlreadyExists1=Ref {0} already exists
reflogEntryNotFound=Entry {0} not found in reflog for ''{1}'' reflogEntryNotFound=Entry {0} not found in reflog for ''{1}''
@ -636,7 +636,6 @@ timeIsUncertain=Time is uncertain
timerAlreadyTerminated=Timer already terminated timerAlreadyTerminated=Timer already terminated
tooManyCommands=Too many commands tooManyCommands=Too many commands
tooManyIncludeRecursions=Too many recursions; circular includes in config file(s)? tooManyIncludeRecursions=Too many recursions; circular includes in config file(s)?
tooManyRedirects=Too many redirects; stopped after {0} redirects at ''{1}''
topologicalSortRequired=Topological sort required. topologicalSortRequired=Topological sort required.
transactionAborted=transaction aborted transactionAborted=transaction aborted
transportExceptionBadRef=Empty ref: {0}: {1} transportExceptionBadRef=Empty ref: {0}: {1}

1
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java

@ -696,7 +696,6 @@ public class JGitText extends TranslationBundle {
/***/ public String timerAlreadyTerminated; /***/ public String timerAlreadyTerminated;
/***/ public String tooManyCommands; /***/ public String tooManyCommands;
/***/ public String tooManyIncludeRecursions; /***/ public String tooManyIncludeRecursions;
/***/ public String tooManyRedirects;
/***/ public String topologicalSortRequired; /***/ public String topologicalSortRequired;
/***/ public String transportExceptionBadRef; /***/ public String transportExceptionBadRef;
/***/ public String transportExceptionEmptyRef; /***/ public String transportExceptionEmptyRef;

33
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java

@ -604,7 +604,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
case HttpConnection.HTTP_FORBIDDEN: case HttpConnection.HTTP_FORBIDDEN:
throw new TransportException(uri, MessageFormat.format( throw new TransportException(uri, MessageFormat.format(
JGitText.get().serviceNotPermitted, service)); JGitText.get().serviceNotPermitted, baseUrl,
service));
case HttpConnection.HTTP_MOVED_PERM: case HttpConnection.HTTP_MOVED_PERM:
case HttpConnection.HTTP_MOVED_TEMP: case HttpConnection.HTTP_MOVED_TEMP:
@ -614,9 +615,10 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
// and in general should occur only on POST requests. But it // and in general should occur only on POST requests. But it
// doesn't hurt to accept it here as a redirect. // doesn't hurt to accept it here as a redirect.
if (http.followRedirects == HttpRedirectMode.FALSE) { if (http.followRedirects == HttpRedirectMode.FALSE) {
throw new TransportException(MessageFormat.format( throw new TransportException(uri,
JGitText.get().redirectsOff, uri, MessageFormat.format(
Integer.valueOf(status))); JGitText.get().redirectsOff,
Integer.valueOf(status)));
} }
URIish newUri = redirect(conn.getHeaderField(HDR_LOCATION), URIish newUri = redirect(conn.getHeaderField(HDR_LOCATION),
Constants.INFO_REFS, redirects++); Constants.INFO_REFS, redirects++);
@ -655,31 +657,34 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
private URIish redirect(String location, String checkFor, int redirects) private URIish redirect(String location, String checkFor, int redirects)
throws TransportException { throws TransportException {
if (location == null || location.isEmpty()) { if (location == null || location.isEmpty()) {
throw new TransportException(MessageFormat.format( throw new TransportException(uri,
JGitText.get().redirectLocationMissing, uri, baseUrl)); MessageFormat.format(JGitText.get().redirectLocationMissing,
baseUrl));
} }
if (redirects >= http.maxRedirects) { if (redirects >= http.maxRedirects) {
throw new TransportException(MessageFormat.format( throw new TransportException(uri,
JGitText.get().redirectLimitExceeded, uri, MessageFormat.format(JGitText.get().redirectLimitExceeded,
Integer.valueOf(http.maxRedirects), baseUrl, location)); Integer.valueOf(http.maxRedirects), baseUrl, location));
} }
try { try {
if (!isValidRedirect(baseUrl, location, checkFor)) { if (!isValidRedirect(baseUrl, location, checkFor)) {
throw new TransportException( throw new TransportException(uri,
MessageFormat.format(JGitText.get().redirectBlocked, MessageFormat.format(JGitText.get().redirectBlocked,
uri, baseUrl, location)); baseUrl, location));
} }
location = location.substring(0, location.indexOf(checkFor)); location = location.substring(0, location.indexOf(checkFor));
URIish result = new URIish(location); URIish result = new URIish(location);
if (LOG.isInfoEnabled()) { if (LOG.isInfoEnabled()) {
LOG.info(MessageFormat.format(JGitText.get().redirectHttp, uri, LOG.info(MessageFormat.format(JGitText.get().redirectHttp,
uri.setPass(null),
Integer.valueOf(redirects), baseUrl, result)); Integer.valueOf(redirects), baseUrl, result));
} }
return result; return result;
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new TransportException(MessageFormat.format( throw new TransportException(uri,
JGitText.get().invalidRedirectLocation, MessageFormat.format(JGitText.get().invalidRedirectLocation,
uri, baseUrl, location), e); baseUrl, location),
e);
} }
} }

Loading…
Cancel
Save