[JENKINS-69032] Plugin manager update site URL can be saved empty (#6886)

Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
Co-authored-by: James Nord <jtnord@users.noreply.github.com>
Co-authored-by: Alexander Brandes <mc.cache@web.de>
Co-authored-by: Basil Crow <me@basilcrow.com>
This commit is contained in:
authored and GitHub committed 2022-10-03 20:20:14 +01:00
1 parent 175a6ee6b3
commit 0cb9e0233e
6 files changed
+62 -1

No files matched your search

@@ -72,6 +72,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
@@ -1945,6 +1946,35 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
return FormValidation.ok();
}
@Restricted(NoExternalUse.class)
@RequirePOST public FormValidation doCheckUpdateSiteUrl(StaplerRequest request, @QueryParameter String value) {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
if (StringUtils.isNotBlank(value)) {
try {
value += ((value.contains("?")) ? "&" : "?") + "version=" + Jenkins.VERSION + "&uctest";
URL url = new URL(value);
// Connect to the URL
HttpURLConnection conn = (HttpURLConnection) ProxyConfiguration.open(url);
conn.setRequestMethod("HEAD");
conn.setConnectTimeout(5000);
if (100 <= conn.getResponseCode() && conn.getResponseCode() <= 399) {
return FormValidation.ok();
} else {
LOGGER.log(Level.FINE, "Obtained a non OK ({0}) response from the update center",
new Object[]{conn.getResponseCode(), url});
return FormValidation.error(Messages.PluginManager_connectionFailed());
}
} catch (IOException e) {
LOGGER.log(Level.FINE, "Failed to check update site", e);
return FormValidation.error(Messages.PluginManager_connectionFailed());
}
} else {
return FormValidation.error(Messages.PluginManager_emptyUpdateSiteUrl());
}
}
@Restricted(NoExternalUse.class)
@RequirePOST public HttpResponse doCheckUpdatesServer() throws IOException {
Jenkins.get().checkPermission(Jenkins.SYSTEM_READ);