Browse Source

bz-62499 Revert the change which caused regression in "get" task. Plus introduce a test case to reproduce the issue and verify the fix

master
Jaikiran Pai 7 years ago
parent
commit
9e39514034
2 changed files with 32 additions and 18 deletions
  1. +23
    -18
      src/main/org/apache/tools/ant/taskdefs/Get.java
  2. +9
    -0
      src/tests/antunit/taskdefs/get-test.xml

+ 23
- 18
src/main/org/apache/tools/ant/taskdefs/Get.java View File

@@ -669,29 +669,34 @@ public class Get extends Task {


private boolean redirectionAllowed(final URL aSource, final URL aDest) {
if (aSource.getProtocol().equals(aDest.getProtocol())
&& (HTTP.equals(aSource.getProtocol()) || HTTPS.equals(aDest.getProtocol()))) {
redirections++;
if (redirections > REDIRECT_LIMIT) {
final String message = "More than " + REDIRECT_LIMIT
+ " times redirected, giving up";
if (ignoreErrors) {
log(message, logLevel);
return false;
}
if (!(aSource.getProtocol().equals(aDest.getProtocol()) || (HTTP
.equals(aSource.getProtocol()) && HTTPS.equals(aDest
.getProtocol())))) {
final String message = "Redirection detected from "
+ aSource.getProtocol() + " to " + aDest.getProtocol()
+ ". Protocol switch unsafe, not allowed.";
if (ignoreErrors) {
log(message, logLevel);
return false;
} else {
throw new BuildException(message);
}
return true;
}

final String message = "Redirection detected from "
+ aSource.getProtocol() + " to " + aDest.getProtocol()
+ ". Protocol switch unsafe, not allowed.";
if (ignoreErrors) {
log(message, logLevel);
return false;
redirections++;
if (redirections > REDIRECT_LIMIT) {
final String message = "More than " + REDIRECT_LIMIT
+ " times redirected, giving up";
if (ignoreErrors) {
log(message, logLevel);
return false;
} else {
throw new BuildException(message);
}
}
throw new BuildException(message);


return true;
}

private URLConnection openConnection(final URL aSource) throws IOException {


+ 9
- 0
src/tests/antunit/taskdefs/get-test.xml View File

@@ -122,4 +122,13 @@
</au:assertTrue>
<au:assertLogContains text="local.cgi moved to http" />
</target>

<target name="testHttpToHttpsRedirect" description="Tests that a resource that's redirected
from HTTP to HTTPS works without an error. See bugzilla-62499 for details">
<get src="${location}/http-to-https.txt" dest="${output}/http-to-https-redirect.tmp"/>
<au:assertFileExists file="${output}/http-to-https-redirect.tmp"/>
<au:assertTrue>
<resourcecontains resource="${output}/http-to-https-redirect.tmp" substring="hello world"/>
</au:assertTrue>
</target>
</project>

Loading…
Cancel
Save