Only generate SSH test keys if we run SSH tests
Change-Id: I8433af9ff2e0da89feba18285de7c1e71bb05cd7
diff --git a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AccountCreator.java b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AccountCreator.java
index 114ef6a..b271f8a 100644
--- a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AccountCreator.java
+++ b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/AccountCreator.java
@@ -30,6 +30,7 @@
import com.google.gerrit.server.account.VersionedAuthorizedKeys;
import com.google.gerrit.server.index.account.AccountIndexer;
import com.google.gerrit.server.ssh.SshKeyCache;
+import com.google.gerrit.testutil.SshMode;
import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -112,9 +113,12 @@
}
}
- KeyPair sshKey = genSshKey();
- authorizedKeys.addKey(id, publicKey(sshKey, email));
- sshKeyCache.evict(username);
+ KeyPair sshKey = null;
+ if (SshMode.useSsh()) {
+ sshKey = genSshKey();
+ authorizedKeys.addKey(id, publicKey(sshKey, email));
+ sshKeyCache.evict(username);
+ }
accountCache.evictByUsername(username);
byEmailCache.evict(email);
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java
index fb1e517..0e96226 100644
--- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java
+++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/accounts/AccountIT.java
@@ -39,6 +39,7 @@
import com.google.gerrit.acceptance.AccountCreator;
import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.acceptance.TestAccount;
+import com.google.gerrit.acceptance.UseSsh;
import com.google.gerrit.common.data.Permission;
import com.google.gerrit.extensions.api.accounts.EmailInput;
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
@@ -122,9 +123,14 @@
@After
public void restoreExternalIds() throws Exception {
- db.accountExternalIds().delete(getExternalIds(admin));
- db.accountExternalIds().delete(getExternalIds(user));
- db.accountExternalIds().insert(savedExternalIds);
+ if (savedExternalIds != null) {
+ // savedExternalIds is null when we don't run SSH tests and the assume in
+ // @Before in AbstractDaemonTest prevents this class' @Before method from
+ // being executed.
+ db.accountExternalIds().delete(getExternalIds(admin));
+ db.accountExternalIds().delete(getExternalIds(user));
+ db.accountExternalIds().insert(savedExternalIds);
+ }
accountCache.evict(admin.getId());
accountCache.evict(user.getId());
}
@@ -666,7 +672,9 @@
}
@Test
+ @UseSsh
public void sshKeys() throws Exception {
+ //
// The test account should initially have exactly one ssh key
List<SshKeyInfo> info = gApi.accounts().self().listSshKeys();
assertThat(info).hasSize(1);