Only generate SSH test keys if we run SSH tests
Change-Id: I8433af9ff2e0da89feba18285de7c1e71bb05cd7
This commit is contained in:
@@ -30,6 +30,7 @@ import com.google.gerrit.server.account.GroupCache;
|
||||
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 @@ public class AccountCreator {
|
||||
}
|
||||
}
|
||||
|
||||
KeyPair sshKey = genSshKey();
|
||||
KeyPair sshKey = null;
|
||||
if (SshMode.useSsh()) {
|
||||
sshKey = genSshKey();
|
||||
authorizedKeys.addKey(id, publicKey(sshKey, email));
|
||||
sshKeyCache.evict(username);
|
||||
}
|
||||
|
||||
accountCache.evictByUsername(username);
|
||||
byEmailCache.evict(email);
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
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 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
|
||||
@After
|
||||
public void restoreExternalIds() throws Exception {
|
||||
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 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
Reference in New Issue
Block a user