java.lang.Object
org.eclipse.jgit.junit.ssh.SshTestGitServer
A simple ssh/sftp git test server based on Apache MINA sshd.
Supports only a single repository. Authenticates only the given test user against his given test public key. Supports fetch and push.
- Since:
- 5.2
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSshTestGitServer(String testUser, Path testKey, org.eclipse.jgit.lib.Repository repository, byte[] hostKey) Creates a ssh git test server.SshTestGitServer(String testUser, Path testKey, org.eclipse.jgit.lib.Repository repository, KeyPair hostKey) Creates a ssh git test server.SshTestGitServer(String testUser, PublicKey testKey, org.eclipse.jgit.lib.Repository repository, KeyPair hostKey) Creates a ssh git test server. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHostKey(Path key, boolean inFront) Adds an additional host key to the server.voidaddHostKey(KeyPair key, boolean inFront) Adds an additional host key to the server.protected voidConfigures the authentication mechanisms of this test server.protected voidConfigures shell access for the test server.protected List<org.apache.sshd.server.subsystem.SubsystemFactory>Configures the test server's subsystems (sftp, scp).voidEnable keyboard-interactive authentication.voidEnable password authentication.org.apache.sshd.common.PropertyResolverRetrieves the server'sPropertyResolver, giving access to server properties.voidsetPreamble(String... lines) Sets the lines the server sends before its server identification in the initial protocol version exchange.voidsetTestUserPublicKey(Path key) Sets the test user's public key on the server.voidSets the test user's public key on the server.intstart()Starts the test server, listening on a random port.voidstop()Stops the test server.
-
Field Details
-
ECHO_COMMAND
Simple echo test command. Replies with the command string as passed. If of the form "echo [int] anything", takes the integer value as a delay in seconds before replying, which may be useful to test various timeout-related things.- Since:
- 5.9
- See Also:
-
testUser
-
repository
@NonNull protected final org.eclipse.jgit.lib.Repository repository -
hostKeys
-
server
protected final org.apache.sshd.server.SshServer server -
testKey
-
-
Constructor Details
-
SshTestGitServer
public SshTestGitServer(@NonNull String testUser, @NonNull Path testKey, @NonNull org.eclipse.jgit.lib.Repository repository, @NonNull byte[] hostKey) throws IOException, GeneralSecurityException Creates a ssh git test server. It serves one single repository, and accepts public-key authentication for exactly one test user.- Parameters:
testUser- user name of the test usertestKey- public key file of the test userrepository- to servehostKey- the unencrypted private key to use as host key- Throws:
IOException- if an IO error occurredGeneralSecurityException- if something went wrong
-
SshTestGitServer
public SshTestGitServer(@NonNull String testUser, @NonNull Path testKey, @NonNull org.eclipse.jgit.lib.Repository repository, @NonNull KeyPair hostKey) throws IOException, GeneralSecurityException Creates a ssh git test server. It serves one single repository, and accepts public-key authentication for exactly one test user.- Parameters:
testUser- user name of the test usertestKey- public key file of the test userrepository- to servehostKey- the unencrypted private key to use as host key- Throws:
IOException- if an IO error occurredGeneralSecurityException- if something went wrong- Since:
- 5.9
-
SshTestGitServer
public SshTestGitServer(@NonNull String testUser, @NonNull PublicKey testKey, @NonNull org.eclipse.jgit.lib.Repository repository, @NonNull KeyPair hostKey) Creates a ssh git test server. It serves one single repository, and accepts public-key authentication for exactly one test user.
-
-
Method Details
-
configureAuthentication
protected void configureAuthentication()Configures the authentication mechanisms of this test server. Invoked from the constructor. The default sets up public key authentication for the test user, and a gssapi-with-mic authenticator that pretends to support this mechanism, but that then refuses to authenticate anyone. -
configureSubsystems
Configures the test server's subsystems (sftp, scp). Invoked from the constructor. The default provides a simple SFTP setup with the root directory as the given repository's .git directory's parent. (I.e., at the directory containing the .git directory.)- Returns:
- A possibly empty collection of subsystems.
-
configureShell
protected void configureShell()Configures shell access for the test server. The default provides no shell at all. -
addHostKey
public void addHostKey(@NonNull Path key, boolean inFront) throws IOException, GeneralSecurityException Adds an additional host key to the server.- Parameters:
key- path to the private key file; should not be encryptedinFront- whether to add the new key before other existing keys- Throws:
IOException- if the file denoted by thePathkeycannot be readGeneralSecurityException- if the key contained in the file cannot be read
-
addHostKey
Adds an additional host key to the server.- Parameters:
key-KeyPairto addinFront- whether to add the new key before other existing keys- Since:
- 5.8
-
enablePasswordAuthentication
public void enablePasswordAuthentication()Enable password authentication. The server will accept the test user's name, converted to all upper-case, as password. -
enableKeyboardInteractiveAuthentication
public void enableKeyboardInteractiveAuthentication()Enable keyboard-interactive authentication. The server will accept the test user's name, converted to all upper-case, as password. -
getPropertyResolver
public org.apache.sshd.common.PropertyResolver getPropertyResolver()Retrieves the server'sPropertyResolver, giving access to server properties.- Returns:
- the
PropertyResolver - Since:
- 5.9
-
start
Starts the test server, listening on a random port.- Returns:
- the port the server listens on; test clients should connect to that port
- Throws:
IOException- if an IO error occurred
-
stop
Stops the test server.- Throws:
IOException- if an IO error occurred
-
setTestUserPublicKey
Sets the test user's public key on the server.- Parameters:
key- to set- Throws:
IOException- if the file cannot be readGeneralSecurityException- if the public key cannot be extracted from the file
-
setTestUserPublicKey
Sets the test user's public key on the server.- Parameters:
key- to set- Since:
- 5.8
-
setPreamble
Sets the lines the server sends before its server identification in the initial protocol version exchange.- Parameters:
lines- to send- Since:
- 5.5
-