Don't generate SSH keys if not using SSH
Generating keys is expensive for DSA and RSA (about 50-200ms per key), so avoid the overhead if it's not necessary. Change-Id: I5db740b0f4311a91a9437f0c7028a8f22b0ce072
This commit is contained in:
@@ -348,6 +348,11 @@ public abstract class AbstractDaemonTest {
|
|||||||
GerritServer.Description methodDesc =
|
GerritServer.Description methodDesc =
|
||||||
GerritServer.Description.forTestMethod(description, configName);
|
GerritServer.Description.forTestMethod(description, configName);
|
||||||
|
|
||||||
|
testRequiresSsh = classDesc.useSshAnnotation() || methodDesc.useSshAnnotation();
|
||||||
|
if (!testRequiresSsh) {
|
||||||
|
baseConfig.setString("sshd", null, "listenAddress", "off");
|
||||||
|
}
|
||||||
|
|
||||||
baseConfig.setInt("receive", null, "changeUpdateThreads", 4);
|
baseConfig.setInt("receive", null, "changeUpdateThreads", 4);
|
||||||
if (classDesc.equals(methodDesc) && !classDesc.sandboxed() && !methodDesc.sandboxed()) {
|
if (classDesc.equals(methodDesc) && !classDesc.sandboxed() && !methodDesc.sandboxed()) {
|
||||||
if (commonServer == null) {
|
if (commonServer == null) {
|
||||||
@@ -388,7 +393,6 @@ public abstract class AbstractDaemonTest {
|
|||||||
adminRestSession = new RestSession(server, admin);
|
adminRestSession = new RestSession(server, admin);
|
||||||
userRestSession = new RestSession(server, user);
|
userRestSession = new RestSession(server, user);
|
||||||
|
|
||||||
testRequiresSsh = classDesc.useSshAnnotation() || methodDesc.useSshAnnotation();
|
|
||||||
if (testRequiresSsh
|
if (testRequiresSsh
|
||||||
&& SshMode.useSsh()
|
&& SshMode.useSsh()
|
||||||
&& (adminSshSession == null || userSshSession == null)) {
|
&& (adminSshSession == null || userSshSession == null)) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import com.google.gerrit.extensions.config.FactoryModule;
|
|||||||
import com.google.gerrit.lucene.LuceneIndexModule;
|
import com.google.gerrit.lucene.LuceneIndexModule;
|
||||||
import com.google.gerrit.pgm.Daemon;
|
import com.google.gerrit.pgm.Daemon;
|
||||||
import com.google.gerrit.pgm.Init;
|
import com.google.gerrit.pgm.Init;
|
||||||
|
import com.google.gerrit.pgm.init.InitSshd;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.gerrit.server.git.receive.AsyncReceiveCommits;
|
import com.google.gerrit.server.git.receive.AsyncReceiveCommits;
|
||||||
import com.google.gerrit.server.ssh.NoSshModule;
|
import com.google.gerrit.server.ssh.NoSshModule;
|
||||||
@@ -376,7 +377,10 @@ public class GerritServer implements AutoCloseable {
|
|||||||
String url = "http://" + forceEphemeralPort + "/";
|
String url = "http://" + forceEphemeralPort + "/";
|
||||||
cfg.setString("gerrit", null, "canonicalWebUrl", url);
|
cfg.setString("gerrit", null, "canonicalWebUrl", url);
|
||||||
cfg.setString("httpd", null, "listenUrl", url);
|
cfg.setString("httpd", null, "listenUrl", url);
|
||||||
|
|
||||||
|
if (cfg.getString("sshd", null, "listenAddress") == null) {
|
||||||
cfg.setString("sshd", null, "listenAddress", forceEphemeralPort);
|
cfg.setString("sshd", null, "listenAddress", forceEphemeralPort);
|
||||||
|
}
|
||||||
cfg.setBoolean("sshd", null, "testUseInsecureRandom", true);
|
cfg.setBoolean("sshd", null, "testUseInsecureRandom", true);
|
||||||
cfg.unset("cache", null, "directory");
|
cfg.unset("cache", null, "directory");
|
||||||
cfg.setString("gerrit", null, "basePath", "git");
|
cfg.setString("gerrit", null, "basePath", "git");
|
||||||
@@ -452,7 +456,10 @@ public class GerritServer implements AutoCloseable {
|
|||||||
url = cfg.getString("gerrit", null, "canonicalWebUrl");
|
url = cfg.getString("gerrit", null, "canonicalWebUrl");
|
||||||
URI uri = URI.create(url);
|
URI uri = URI.create(url);
|
||||||
|
|
||||||
|
String addr = cfg.getString("sshd", null, "listenAddress");
|
||||||
|
if (!InitSshd.isOff(addr)) {
|
||||||
sshdAddress = SocketUtil.resolve(cfg.getString("sshd", null, "listenAddress"), 0);
|
sshdAddress = SocketUtil.resolve(cfg.getString("sshd", null, "listenAddress"), 0);
|
||||||
|
}
|
||||||
httpAddress = new InetSocketAddress(uri.getHost(), uri.getPort());
|
httpAddress = new InetSocketAddress(uri.getHost(), uri.getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import java.net.InetSocketAddress;
|
|||||||
|
|
||||||
/** Initialize the {@code sshd} configuration section. */
|
/** Initialize the {@code sshd} configuration section. */
|
||||||
@Singleton
|
@Singleton
|
||||||
class InitSshd implements InitStep {
|
public class InitSshd implements InitStep {
|
||||||
private final ConsoleUI ui;
|
private final ConsoleUI ui;
|
||||||
private final SitePaths site;
|
private final SitePaths site;
|
||||||
private final Section sshd;
|
private final Section sshd;
|
||||||
@@ -73,7 +73,7 @@ class InitSshd implements InitStep {
|
|||||||
remover.remove("bc(pg|pkix|prov)-.*[.]jar");
|
remover.remove("bc(pg|pkix|prov)-.*[.]jar");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isOff(String listenHostname) {
|
public static boolean isOff(String listenHostname) {
|
||||||
return "off".equalsIgnoreCase(listenHostname)
|
return "off".equalsIgnoreCase(listenHostname)
|
||||||
|| "none".equalsIgnoreCase(listenHostname)
|
|| "none".equalsIgnoreCase(listenHostname)
|
||||||
|| "no".equalsIgnoreCase(listenHostname);
|
|| "no".equalsIgnoreCase(listenHostname);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
|||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
import com.google.gerrit.acceptance.GerritConfig;
|
import com.google.gerrit.acceptance.GerritConfig;
|
||||||
import com.google.gerrit.acceptance.NoHttpd;
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
|
import com.google.gerrit.acceptance.UseSsh;
|
||||||
import com.google.gerrit.common.RawInputUtil;
|
import com.google.gerrit.common.RawInputUtil;
|
||||||
import com.google.gerrit.extensions.client.AccountFieldName;
|
import com.google.gerrit.extensions.client.AccountFieldName;
|
||||||
import com.google.gerrit.extensions.client.AuthType;
|
import com.google.gerrit.extensions.client.AuthType;
|
||||||
@@ -32,6 +33,7 @@ import com.google.gerrit.server.config.AnonymousCowardNameProvider;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@NoHttpd
|
@NoHttpd
|
||||||
|
@UseSsh
|
||||||
public class ServerInfoIT extends AbstractDaemonTest {
|
public class ServerInfoIT extends AbstractDaemonTest {
|
||||||
private static final byte[] JS_PLUGIN_CONTENT =
|
private static final byte[] JS_PLUGIN_CONTENT =
|
||||||
"Gerrit.install(function(self){});\n".getBytes(UTF_8);
|
"Gerrit.install(function(self){});\n".getBytes(UTF_8);
|
||||||
|
|||||||
Reference in New Issue
Block a user