Top Description Inners Fields Constructors Methods
org.eclipse.jgit.junit.ssh

public Class SshTestGitServer

extends Object
Class Inheritance
Static Imports
org.apache.sshd.core.CoreModuleProperties.SERVER_EXTRA_IDENTIFICATION_LINES, .CoreModuleProperties.SERVER_EXTRA_IDENT_LINES_SEPARATOR

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
SshTestGitServer.EchoCommand

Simple echo command that echoes back the command string.

private static class
private class
private class

Field Summary

Modifier and TypeField and Description
public static final String
ECHO_COMMAND

Simple echo test command.

private final CloseableExecutorService
protected final List<KeyPair>
protected final Repository
protected final SshServer
protected PublicKey
protected final String

Constructor Summary

AccessConstructor and Description
public
SshTestGitServer(String
user name of the test user
testUser
,
Path
public key file of the test user
testKey
,
Repository
to serve
repository
,
byte[]
the unencrypted private key to use as host key
hostKey
)

Creates a ssh git test server.

public
SshTestGitServer(String
user name of the test user
testUser
,
Path
public key file of the test user
testKey
,
Repository
to serve
repository
,
KeyPair
the unencrypted private key to use as host key
hostKey
)

Creates a ssh git test server.

public
SshTestGitServer(String
user name of the test user
testUser
,
PublicKey
the PublicKey of the test user
testKey
,
Repository
to serve
repository
,
KeyPair
the KeyPair to use as host key
hostKey
)

Creates a ssh git test server.

Method Summary

Modifier and TypeMethod and Description
public void
addHostKey(Path
path to the private key file; should not be encrypted
key
,
boolean
whether to add the new key before other existing keys
inFront
)

Adds an additional host key to the server.

public void
addHostKey(KeyPair
KeyPair to add
key
,
boolean
whether to add the new key before other existing keys
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 List<SubsystemFactory>

Returns:

A possibly empty collection of subsystems.
configureSubsystems
()

Configures the test server's subsystems (sftp, scp).

public void
enableKeyboardInteractiveAuthentication()

Enable keyboard-interactive authentication.

public void
enablePasswordAuthentication()

Enable password authentication.

private List<UserAuthFactory>
public PropertyResolver

Returns:

the PropertyResolver
getPropertyResolver
()

Retrieves the server's PropertyResolver, giving access to server properties.

private static List<NamedFactory<Signature>>

Returns:

a list of supported signature factories
getSignatureFactories
()

Apache MINA sshd 2.6.0 has removed DSA, DSA_CERT and RSA_CERT.

private static KeyPair
readKeyPair(byte[] keyMaterial)

private static PublicKey
public void
setPreamble(String...
to send
lines
)

Sets the lines the server sends before its server identification in the initial protocol version exchange.

public void
setTestUserPublicKey(Path
to set
key
)

Sets the test user's public key on the server.

public void
setTestUserPublicKey(PublicKey
to set
key
)

Sets the test user's public key on the server.

public int

Returns:

the port the server listens on; test clients should connect to that port
start
()

Starts the test server, listening on a random port.

public void
stop()

Stops the test server.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ECHO_COMMANDback to summary
public static final String 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
executorServiceback to summary
private final CloseableExecutorService executorService
hostKeysback to summary
protected final List<KeyPair> hostKeys
Annotations
@NonNull
repositoryback to summary
protected final Repository repository
Annotations
@NonNull
serverback to summary
protected final SshServer server
testKeyback to summary
protected PublicKey testKey
Annotations
@NonNull
testUserback to summary
protected final String testUser
Annotations
@NonNull

Constructor Detail

SshTestGitServerback to summary
public SshTestGitServer(String testUser, Path testKey, Repository repository, 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:String

user name of the test user

testKey:Path

public key file of the test user

repository:Repository

to serve

hostKey:byte[]

the unencrypted private key to use as host key

Exceptions
IOException:
if an IO error occurred
GeneralSecurityException:
if something went wrong
SshTestGitServerback to summary
public SshTestGitServer(String testUser, Path testKey, Repository repository, 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:String

user name of the test user

testKey:Path

public key file of the test user

repository:Repository

to serve

hostKey:KeyPair

the unencrypted private key to use as host key

Exceptions
IOException:
if an IO error occurred
GeneralSecurityException:
if something went wrong
Since
5.9
SshTestGitServerback to summary
public SshTestGitServer(String testUser, PublicKey testKey, Repository repository, KeyPair hostKey)

Creates a ssh git test server. It serves one single repository, and accepts public-key authentication for exactly one test user.

Parameters
testUser:String

user name of the test user

testKey:PublicKey

the PublicKey of the test user

repository:Repository

to serve

hostKey:KeyPair

the KeyPair to use as host key

Since
5.9

Method Detail

addHostKeyback to summary
public void addHostKey(Path key, boolean inFront) throws IOException, GeneralSecurityException

Adds an additional host key to the server.

Parameters
key:Path

path to the private key file; should not be encrypted

inFront:boolean

whether to add the new key before other existing keys

Exceptions
IOException:
if the file denoted by the Path key cannot be read
GeneralSecurityException:
if the key contained in the file cannot be read
addHostKeyback to summary
public void addHostKey(KeyPair key, boolean inFront)

Adds an additional host key to the server.

Parameters
key:KeyPair

KeyPair to add

inFront:boolean

whether to add the new key before other existing keys

Since
5.8
configureAuthenticationback to summary
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.

configureShellback to summary
protected void configureShell()

Configures shell access for the test server. The default provides no shell at all.

configureSubsystemsback to summary
protected List<SubsystemFactory> 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:List<SubsystemFactory>

A possibly empty collection of subsystems.

Annotations
@NonNull
enableKeyboardInteractiveAuthenticationback to summary
public void enableKeyboardInteractiveAuthentication()

Enable keyboard-interactive authentication. The server will accept the test user's name, converted to all upper-case, as password.

enablePasswordAuthenticationback to summary
public void enablePasswordAuthentication()

Enable password authentication. The server will accept the test user's name, converted to all upper-case, as password.

getAuthFactoriesback to summary
private List<UserAuthFactory> getAuthFactories()
getPropertyResolverback to summary
public PropertyResolver getPropertyResolver()

Retrieves the server's PropertyResolver, giving access to server properties.

Returns:PropertyResolver

the PropertyResolver

Since
5.9
getSignatureFactoriesback to summary
private static List<NamedFactory<Signature>> getSignatureFactories()

Apache MINA sshd 2.6.0 has removed DSA, DSA_CERT and RSA_CERT. We have to set it up explicitly to still allow users to connect with DSA keys.

Returns:List<NamedFactory<Signature>>

a list of supported signature factories

Annotations
@SuppressWarnings:deprecation
readKeyPairback to summary
private static KeyPair readKeyPair(byte[] keyMaterial) throws IOException, GeneralSecurityException
readPublicKeyback to summary
private static PublicKey readPublicKey(Path key) throws IOException, GeneralSecurityException
setPreambleback to summary
public void setPreamble(String... lines)

Sets the lines the server sends before its server identification in the initial protocol version exchange.

Parameters
lines:String[]

to send

Since
5.5
setTestUserPublicKeyback to summary
public void setTestUserPublicKey(Path key) throws IOException, GeneralSecurityException

Sets the test user's public key on the server.

Parameters
key:Path

to set

Exceptions
IOException:
if the file cannot be read
GeneralSecurityException:
if the public key cannot be extracted from the file
setTestUserPublicKeyback to summary
public void setTestUserPublicKey(PublicKey key)

Sets the test user's public key on the server.

Parameters
key:PublicKey

to set

Since
5.8
startback to summary
public int start() throws IOException

Starts the test server, listening on a random port.

Returns:int

the port the server listens on; test clients should connect to that port

Exceptions
IOException:
if an IO error occurred
stopback to summary
public void stop() throws IOException

Stops the test server.

Exceptions
IOException:
if an IO error occurred
org.eclipse.jgit.junit.ssh back to summary

private Class SshTestGitServer.EchoCommand

extends AbstractCommandSupport
Class Inheritance

Simple echo command that echoes back the command string. If the first argument is a positive integer, it's taken as a delay (in seconds) before replying. Assumes UTF-8 character encoding.

Field Summary

Inherited from org.apache.sshd.server.command.AbstractCommandSupport:
cbCalledcmdRunnerexecutorService

Constructor Summary

AccessConstructor and Description
protected
EchoCommand(String command, CloseableExecutorService executorService)

Method Summary

Modifier and TypeMethod and Description
private void
doEcho(String text, OutputStream stream)

public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from org.apache.sshd.server.command.AbstractCommandSupport:
destroygetCommandgetEnvironmentgetErrorStreamgetExecutorServicegetExitCallbackgetInputStreamgetOutputStreamgetServerSessiongetSessiongetStartedCommandFutureonExitonExitsetErrorStreamsetExitCallbacksetInputStreamsetOutputStreamsetSessionstarttoString

Constructor Detail

EchoCommandback to summary
protected EchoCommand(String command, CloseableExecutorService executorService)

Method Detail

doEchoback to summary
private void doEcho(String text, OutputStream stream) throws IOException
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
org.eclipse.jgit.junit.ssh back to summary

private Class SshTestGitServer.FakeUserAuthGSS

extends UserAuthGSS
Class Inheritance

Field Summary

Inherited from org.apache.sshd.server.auth.gss.UserAuthGSS:
KRB5_MECHKRB5_NT_PRINCIPALNAME

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected Boolean
Inherited from org.apache.sshd.server.auth.gss.UserAuthGSS:
createOIDdestroy

Constructor Detail

FakeUserAuthGSSback to summary
private FakeUserAuthGSS()

Method Detail

doAuthback to summary
protected Boolean doAuth(Buffer buffer, boolean initial) throws Exception

Overrides org.apache.sshd.server.auth.gss.UserAuthGSS.doAuth.

Annotations
@Override
@Nullable
org.eclipse.jgit.junit.ssh back to summary

private Class SshTestGitServer.GitReceivePackCommand

extends AbstractCommandSupport
Class Inheritance

Field Summary

Inherited from org.apache.sshd.server.command.AbstractCommandSupport:
cbCalledcmdRunnerexecutorService

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from org.apache.sshd.server.command.AbstractCommandSupport:
destroygetCommandgetEnvironmentgetErrorStreamgetExecutorServicegetExitCallbackgetInputStreamgetOutputStreamgetServerSessiongetSessiongetStartedCommandFutureonExitonExitsetErrorStreamsetExitCallbacksetInputStreamsetOutputStreamsetSessionstarttoString

Constructor Detail

GitReceivePackCommandback to summary
protected GitReceivePackCommand(String command, CloseableExecutorService executorService)

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
org.eclipse.jgit.junit.ssh back to summary

private Class SshTestGitServer.GitUploadPackCommand

extends AbstractCommandSupport
Class Inheritance

Field Summary

Inherited from org.apache.sshd.server.command.AbstractCommandSupport:
cbCalledcmdRunnerexecutorService

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from org.apache.sshd.server.command.AbstractCommandSupport:
destroygetCommandgetEnvironmentgetErrorStreamgetExecutorServicegetExitCallbackgetInputStreamgetOutputStreamgetServerSessiongetSessiongetStartedCommandFutureonExitonExitsetErrorStreamsetExitCallbacksetInputStreamsetOutputStreamsetSessionstarttoString

Constructor Detail

GitUploadPackCommandback to summary
protected GitUploadPackCommand(String command, CloseableExecutorService executorService)

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override