public class SshTestGitServer
extends java.lang.Object
Supports only a single repository. Authenticates only the given test user against his given test public key. Supports fetch and push.
Modifier and Type | Class and Description |
---|---|
private static class |
SshTestGitServer.FakeUserAuthGSS |
private class |
SshTestGitServer.GitReceivePackCommand |
private class |
SshTestGitServer.GitUploadPackCommand |
Modifier and Type | Field and Description |
---|---|
private org.apache.sshd.common.util.threads.CloseableExecutorService |
executorService |
protected java.util.List<java.security.KeyPair> |
hostKeys |
protected Repository |
repository |
protected org.apache.sshd.server.SshServer |
server |
protected java.security.PublicKey |
testKey |
protected java.lang.String |
testUser |
Constructor and Description |
---|
SshTestGitServer(java.lang.String testUser,
java.nio.file.Path testKey,
Repository repository,
byte[] hostKey)
Creates a ssh git test server.
|
Modifier and Type | Method and Description |
---|---|
void |
addHostKey(java.nio.file.Path key,
boolean inFront)
Adds an additional host key to the server.
|
protected void |
configureAuthentication()
Configures the authentication mechanisms of this test server.
|
protected void |
configureShell()
Configures shell access for the test server.
|
protected java.util.List<org.apache.sshd.common.NamedFactory<org.apache.sshd.server.command.Command>> |
configureSubsystems()
Configures the test server's subsystems (sftp, scp).
|
void |
enableKeyboardInteractiveAuthentication()
Enable keyboard-interactive authentication.
|
void |
enablePasswordAuthentication()
Enable password authentication.
|
private java.util.List<org.apache.sshd.common.NamedFactory<org.apache.sshd.server.auth.UserAuth>> |
getAuthFactories() |
void |
setPreamble(java.lang.String... lines)
Sets the lines the server sends before its server identification in the
initial protocol version exchange.
|
void |
setTestUserPublicKey(java.nio.file.Path key)
Sets the test user's public key on the server.
|
int |
start()
Starts the test server, listening on a random port.
|
void |
stop()
Stops the test server.
|
@NonNull protected final java.lang.String testUser
@NonNull protected final Repository repository
@NonNull protected final java.util.List<java.security.KeyPair> hostKeys
protected final org.apache.sshd.server.SshServer server
@NonNull protected java.security.PublicKey testKey
private final org.apache.sshd.common.util.threads.CloseableExecutorService executorService
public SshTestGitServer(@NonNull java.lang.String testUser, @NonNull java.nio.file.Path testKey, @NonNull Repository repository, @NonNull byte[] hostKey) throws java.io.IOException, java.security.GeneralSecurityException
testUser
- user name of the test usertestKey
- private key file of the test user; the server will
only user the public key from itrepository
- to servehostKey
- the unencrypted private key to use as host keyjava.io.IOException
java.security.GeneralSecurityException
private java.util.List<org.apache.sshd.common.NamedFactory<org.apache.sshd.server.auth.UserAuth>> getAuthFactories()
protected void configureAuthentication()
@NonNull protected java.util.List<org.apache.sshd.common.NamedFactory<org.apache.sshd.server.command.Command>> configureSubsystems()
protected void configureShell()
public void addHostKey(@NonNull java.nio.file.Path key, boolean inFront) throws java.io.IOException, java.security.GeneralSecurityException
key
- path to the private key file; should not be encryptedinFront
- whether to add the new key before other existing keysjava.io.IOException
- if the file denoted by the Path
key
cannot be
readjava.security.GeneralSecurityException
- if the key contained in the file cannot be readpublic void enablePasswordAuthentication()
public void enableKeyboardInteractiveAuthentication()
public int start() throws java.io.IOException
java.io.IOException
public void stop() throws java.io.IOException
java.io.IOException
public void setTestUserPublicKey(java.nio.file.Path key) throws java.io.IOException, java.security.GeneralSecurityException
key
- to setjava.io.IOException
- if the file cannot be readjava.security.GeneralSecurityException
- if the public key cannot be extracted from the filepublic void setPreamble(java.lang.String... lines)
lines
- to send