Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2018-09-23 13:44:10 +0000
committerMatthias Sohn2018-11-13 18:49:26 +0000
commit0173b25415fb334490396a2fa4150db888c56947 (patch)
tree307b1fee8698d217c25049ebc2a1dea5c1a7bb9b /org.eclipse.jgit.junit
parent705691ee517900d3359868212a50d4dc7f048245 (diff)
downloadjgit-0173b25415fb334490396a2fa4150db888c56947.tar.gz
jgit-0173b25415fb334490396a2fa4150db888c56947.tar.xz
jgit-0173b25415fb334490396a2fa4150db888c56947.zip
Add more ssh tests: pushing, known_host file handling, etc.
Add support for git-receive-pack to the ssh git server and add two new tests for pushing. This actually uncovered an undocumented requirement in TransportSftp: the FTP rename operation assumes POSIX semantics, i.e., that the target is removed. This works as written only for servers that support and advertise the "posix-rename@openssh.com" FTP extension. Our little Apache MINA server does not advertise this extension. Fix the FtpChannel implementation for Jsch to handle this case in a meaningful way so that it can pass the new "push over sftp" test. Add more tests to test the behavior of server host key checking. Also refactor the tests generally to separate better the test framework from the actual tests. Bug: 520927 Change-Id: Ia4bb85e17ddacde7b36ee8c2d5d454bbfa66dfc3 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.junit')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/ssh/SshTestGitServer.java45
1 files changed, 38 insertions, 7 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/ssh/SshTestGitServer.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/ssh/SshTestGitServer.java
index 675a11589d..8d3207c43e 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/ssh/SshTestGitServer.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/ssh/SshTestGitServer.java
@@ -53,8 +53,9 @@ import java.util.Collections;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import org.apache.sshd.common.config.keys.IdentityUtils;
+import org.apache.sshd.common.config.keys.AuthorizedKeyEntry;
import org.apache.sshd.common.config.keys.KeyUtils;
+import org.apache.sshd.common.config.keys.PublicKeyEntryResolver;
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
import org.apache.sshd.common.session.Session;
@@ -65,13 +66,15 @@ import org.apache.sshd.server.shell.UnknownCommand;
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.transport.ReceivePack;
+import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.UploadPack;
/**
* A simple ssh/sftp git <em>test</em> server based on Apache MINA sshd.
* <p>
* Supports only a single repository. Authenticates only the given test user
- * against his given test public key. ssh is limited to fetching (upload-pack).
+ * against his given test public key. Supports fetch and push.
* </p>
*
* @since 5.2
@@ -112,9 +115,7 @@ public class SshTestGitServer {
@NonNull Repository repository, @NonNull byte[] hostKey)
throws IOException, GeneralSecurityException {
this.testUser = testUser;
- this.testKey = IdentityUtils
- .loadIdentities(Collections.singletonMap("A", testKey), null)
- .get("A").getPublic();
+ setTestUserPublicKey(testKey);
this.repository = repository;
server = SshServer.setUpDefaultServer();
// Set host key
@@ -156,9 +157,10 @@ public class SshTestGitServer {
.compareKeys(SshTestGitServer.this.testKey, publicKey);
});
server.setCommandFactory(command -> {
- if (command.startsWith("git-upload-pack")
- || command.startsWith("git upload-pack")) {
+ if (command.startsWith(RemoteConfig.DEFAULT_UPLOAD_PACK)) {
return new GitUploadPackCommand(command, executorService);
+ } else if (command.startsWith(RemoteConfig.DEFAULT_RECEIVE_PACK)) {
+ return new GitReceivePackCommand(command, executorService);
}
return new UnknownCommand(command);
});
@@ -186,6 +188,12 @@ public class SshTestGitServer {
server.stop(true);
}
+ public void setTestUserPublicKey(Path key)
+ throws IOException, GeneralSecurityException {
+ this.testKey = AuthorizedKeyEntry.readAuthorizedKeys(key).get(0)
+ .resolvePublicKey(PublicKeyEntryResolver.IGNORING);
+ }
+
private class GitUploadPackCommand extends AbstractCommandSupport {
protected GitUploadPackCommand(String command,
@@ -214,4 +222,27 @@ public class SshTestGitServer {
}
}
+
+ private class GitReceivePackCommand extends AbstractCommandSupport {
+
+ protected GitReceivePackCommand(String command,
+ ExecutorService executorService) {
+ super(command, executorService, false);
+ }
+
+ @Override
+ public void run() {
+ try {
+ new ReceivePack(repository).receive(getInputStream(),
+ getOutputStream(), getErrorStream());
+ onExit(0);
+ } catch (IOException e) {
+ log.warn(
+ MessageFormat.format("Could not run {0}", getCommand()),
+ e);
+ onExit(-1, e.toString());
+ }
+ }
+
+ }
}

Back to the top