SshSession: Allow session to be explicitly opened
Change-Id: I827d00c0cb81aefd931a895c20f4bacc9ba9c126
This commit is contained in:
parent
c4c35b64af
commit
cf31c84e8a
@ -14,18 +14,19 @@
|
||||
|
||||
package com.google.gerrit.acceptance;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Scanner;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import com.jcraft.jsch.ChannelExec;
|
||||
import com.jcraft.jsch.JSch;
|
||||
import com.jcraft.jsch.JSchException;
|
||||
import com.jcraft.jsch.Session;
|
||||
|
||||
public class SshSession {
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SshSession {
|
||||
private final InetSocketAddress addr;
|
||||
private final TestAccount account;
|
||||
private Session session;
|
||||
@ -36,6 +37,10 @@ public class SshSession {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public void open() throws JSchException {
|
||||
getSession();
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public String exec(String command) throws JSchException, IOException {
|
||||
ChannelExec channel = (ChannelExec) getSession().openChannel("exec");
|
||||
@ -86,6 +91,7 @@ public class SshSession {
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
checkState(session != null, "session must be opened");
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append("ssh://");
|
||||
b.append(session.getUserName());
|
||||
|
@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.acceptance.rest.change;
|
||||
|
||||
import static com.google.gerrit.acceptance.GitUtil.cloneProject;
|
||||
import static com.google.gerrit.acceptance.GitUtil.createProject;
|
||||
import static com.google.gerrit.acceptance.GitUtil.initSsh;
|
||||
import static com.google.gerrit.common.data.Permission.LABEL;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@ -63,8 +62,7 @@ public class ChangeOwnerIT extends AbstractDaemonTest {
|
||||
sessionOwner = new RestSession(server, user);
|
||||
SshSession sshSession = new SshSession(server, user);
|
||||
initSsh(user);
|
||||
// need to initialize intern session
|
||||
createProject(sshSession, "foo");
|
||||
sshSession.open();
|
||||
git = cloneProject(sshSession.getUrl() + "/" + project.get());
|
||||
sshSession.close();
|
||||
user2 = accounts.user2();
|
||||
|
Loading…
Reference in New Issue
Block a user