mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-14 20:42:21 +00:00
[JENKINS-23507] Make FilePath.installIfNecessaryFrom follow redirects (#2331)
This commit is contained in:
1 parent
782804f38e
commit
0c16c8576b
2 files changed
+82
-6
No files matched your search
@@ -38,9 +38,11 @@ import java.io.OutputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.net.ConnectException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLStreamHandler;
|
||||
import java.net.URLStreamHandlerFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -637,6 +639,28 @@ public class FilePathTest {
|
||||
assertTrue(log, log.contains("504 Gateway Timeout"));
|
||||
}
|
||||
|
||||
@Issue("JENKINS-23507")
|
||||
@Test public void installIfNecessaryFollowsRedirects() throws Exception{
|
||||
File tmp = temp.getRoot();
|
||||
final FilePath d = new FilePath(tmp);
|
||||
FilePath.UrlFactory urlFactory = mock(FilePath.UrlFactory.class);
|
||||
d.setUrlFactory(urlFactory);
|
||||
final HttpURLConnection con = mock(HttpURLConnection.class);
|
||||
final HttpURLConnection con2 = mock(HttpURLConnection.class);
|
||||
final URL url = someUrlToZipFile(con);
|
||||
when(con.getResponseCode()).thenReturn(HttpURLConnection.HTTP_MOVED_TEMP);
|
||||
URL url2 = someUrlToZipFile(con2);
|
||||
String someUrl = url2.toExternalForm();
|
||||
when(con.getHeaderField("Location")).thenReturn(someUrl);
|
||||
when(urlFactory.newURL(someUrl)).thenReturn(url2);
|
||||
when(con2.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
|
||||
when(con2.getInputStream()).thenReturn(someZippedContent());
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
String message = "going ahead";
|
||||
assertTrue(d.installIfNecessaryFrom(url, new StreamTaskListener(baos), message));
|
||||
}
|
||||
|
||||
private URL someUrlToZipFile(final URLConnection con) throws IOException {
|
||||
|
||||
final URLStreamHandler urlHandler = new URLStreamHandler() {
|
||||
|
||||
Reference in new issue
Block a user