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

public abstract Class SshTestHarness

extends RepositoryTestCase
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.junit.ssh.SshBasicTestBase
Static Imports
org.junit.Assert.assertEquals, .Assert.assertFalse, .Assert.assertNotEquals, .Assert.assertNotNull, .Assert.assertTrue

Root class for ssh tests. Sets up the ssh test server. A set of pre-computed keys for testing is provided in the bundle and can be used in test cases via copyTestResource(String, File). These test key files names have four components, separated by a single underscore: "id", the algorithm, the bits (if variable), and the password if the private key is encrypted. For instance "id_ecdsa_384_testpass" is an encrypted ECDSA-384 key. The passphrase to decrypt is "testpass". The key "id_ecdsa_384" is the same but unencrypted. All keys were generated and encrypted via ssh-keygen. Note that DSA and ec25519 have no "bits" component. Available keys are listed in SshTestBase#KEY_RESOURCES.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
protected static class

Field Summary

Modifier and TypeField and Description
private SshSessionFactory
protected File
protected File
protected File
protected File
protected File
protected SshTestGitServer
protected File
protected static final String
protected int
Inherited from org.eclipse.jgit.junit.RepositoryTestCase:
dbtrash

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected File
cloneWith(String uri, File to, CredentialsProvider provider, String... config)

protected void
copyTestResource(String
of the test resource to copy
resourceName
,
File
file to copy the resource to
to
)

Copies a test data file contained in the test bundle to the given file.

protected void
copyTestResource(Class<?>
Class to use to load the resource
loader
,
String
of the test resource to copy
resourceName
,
File
file to copy the resource to
to
)

Copies a test data file contained in the test bundle to the given file, using Class#getResourceAsStream(String) to get the test resource.

private static File
createKeyPair(KeyPair newKey, File privateKeyFile)

protected static String

Returns:

the public-key part of the line
createKnownHostsFile
(File
to write the known_hosts file to
file
,
String
for the entry
host
,
int
for the entry
port
,
File
to use
publicKey
)

Creates a new known_hosts file with one entry for the given host and port taken from the given public key file.

protected abstract SshSessionFactory
protected SshSessionFactory
protected boolean

Returns:

true if found, false otherwise
hasHostKey
(String
to look for
host
,
int
to look for
port
,
String
to look for
keyPart
,
List<String>
to look in
lines
)

Checks whether there is a line for the given host and port that also matches the given key part in the list of lines.

protected abstract void
installConfig(String... config)

protected void
pushTo(File localClone)

protected void
pushTo(CredentialsProvider provider, File localClone)

public void
public void
private static void
write(BufferedWriter out, byte[] bytes, int lineLength)

Inherited from org.eclipse.jgit.junit.RepositoryTestCase:
assertEqualsFilecheckcheckFilecheckoutBranchcommitFilecopyFilecreateBranchcreateEntrycreateEntrycreateEntrycreateGitLinkdeleteTrashFilefsTickgetRefsindexStatelookupreadresetIndexslashifytearDownwriteLinkwriteTrashFilewriteTrashFilewriteTrashFiles

Field Detail

factoryback to summary
private SshSessionFactory factory
knownHostsback to summary
protected File knownHosts
privateKey1back to summary
protected File privateKey1
privateKey2back to summary
protected File privateKey2
publicKey1back to summary
protected File publicKey1
publicKey2back to summary
protected File publicKey2
Since
5.10
serverback to summary
protected SshTestGitServer server
sshDirback to summary
protected File sshDir
TEST_USERback to summary
protected static final String TEST_USER
testPortback to summary
protected int testPort

Constructor Detail

SshTestHarnessback to summary
public SshTestHarness()

Method Detail

cloneWithback to summary
protected File cloneWith(String uri, File to, CredentialsProvider provider, String... config) throws Exception
copyTestResourceback to summary
protected void copyTestResource(String resourceName, File to) throws IOException

Copies a test data file contained in the test bundle to the given file. Equivalent to copyTestResource(Class, String, File) with SshTestHarness.class as first parameter.

Parameters
resourceName:String

of the test resource to copy

to:File

file to copy the resource to

Exceptions
IOException:
if the resource cannot be copied
copyTestResourceback to summary
protected void copyTestResource(Class<?> loader, String resourceName, File to) throws IOException

Copies a test data file contained in the test bundle to the given file, using Class#getResourceAsStream(String) to get the test resource.

Parameters
loader:Class<?>

Class to use to load the resource

resourceName:String

of the test resource to copy

to:File

file to copy the resource to

Exceptions
IOException:
if the resource cannot be copied
createKeyPairback to summary
private static File createKeyPair(KeyPair newKey, File privateKeyFile) throws Exception
createKnownHostsFileback to summary
protected static String createKnownHostsFile(File file, String host, int port, File publicKey) throws IOException

Creates a new known_hosts file with one entry for the given host and port taken from the given public key file.

Parameters
file:File

to write the known_hosts file to

host:String

for the entry

port:int

for the entry

publicKey:File

to use

Returns:String

the public-key part of the line

Exceptions
IOException:
if an IO error occurred
createSessionFactoryback to summary
protected abstract SshSessionFactory createSessionFactory()
getSessionFactoryback to summary
protected SshSessionFactory getSessionFactory()
hasHostKeyback to summary
protected boolean hasHostKey(String host, int port, String keyPart, List<String> lines)

Checks whether there is a line for the given host and port that also matches the given key part in the list of lines.

Parameters
host:String

to look for

port:int

to look for

keyPart:String

to look for

lines:List<String>

to look in

Returns:boolean

true if found, false otherwise

installConfigback to summary
protected abstract void installConfig(String... config)
pushToback to summary
protected void pushTo(File localClone) throws Exception
pushToback to summary
protected void pushTo(CredentialsProvider provider, File localClone) throws Exception
setUpback to summary
public void setUp() throws Exception

Overrides org.eclipse.jgit.junit.RepositoryTestCase.setUp.

Doc from org.eclipse.jgit.junit.LocalDiskRepositoryTestCase.setUp.

Setup test

Annotations
@Override
Exceptions
Exception:
if an error occurred
shutdownServerback to summary
public void shutdownServer() throws Exception
Annotations
@After
writeback to summary
private static void write(BufferedWriter out, byte[] bytes, int lineLength) throws IOException
org.eclipse.jgit.junit.ssh back to summary

protected Class SshTestHarness.LogEntry

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private List<CredentialItem>
private URIish

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public List<CredentialItem>
public URIish
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

itemsback to summary
private List<CredentialItem> items
uriback to summary
private URIish uri

Constructor Detail

LogEntryback to summary
public LogEntry(URIish uri, List<CredentialItem> items)

Method Detail

getItemsback to summary
public List<CredentialItem> getItems()
getURIishback to summary
public URIish getURIish()
org.eclipse.jgit.junit.ssh back to summary

protected Class SshTestHarness.TestCredentialsProvider

extends CredentialsProvider
Class Inheritance

Field Summary

Modifier and TypeField and Description
private List<SshTestHarness.LogEntry>
private final Iterator<String>
private final List<String>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
get(URIish
the URI of the remote resource that needs authentication.
uri
,
CredentialItem...
the items the application requires to complete authentication.
items
)

Implements abstract org.eclipse.jgit.transport.CredentialsProvider.get.

Ask for the credential items to be populated.

public List<SshTestHarness.LogEntry>
public boolean
isInteractive()

Implements abstract org.eclipse.jgit.transport.CredentialsProvider.isInteractive.

Check if the provider is interactive with the end-user.

private void
public boolean
supports(CredentialItem...
the items the application requires to complete authentication.
items
)

Implements abstract org.eclipse.jgit.transport.CredentialsProvider.supports.

Check if the provider can supply the necessary org.eclipse.jgit.transport.CredentialItems.

Inherited from org.eclipse.jgit.transport.CredentialsProvider:
getgetDefaultisAnyNullresetsetDefault

Field Detail

logback to summary
private List<SshTestHarness.LogEntry> log
stringsback to summary
private final Iterator<String> strings
stringStoreback to summary
private final List<String> stringStore

Constructor Detail

TestCredentialsProviderback to summary
public TestCredentialsProvider(String... strings)

Method Detail

getback to summary
public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem

Implements abstract org.eclipse.jgit.transport.CredentialsProvider.get.

Doc from org.eclipse.jgit.transport.CredentialsProvider.get.

Ask for the credential items to be populated.

Parameters
uri:URIish

the URI of the remote resource that needs authentication.

items:CredentialItem[]

the items the application requires to complete authentication.

Returns:boolean

true if the request was successful and values were supplied; false if the user canceled the request and did not supply all requested values.

Annotations
@Override
Exceptions
UnsupportedCredentialItem:
if one of the items supplied is not supported.
getLogback to summary
public List<SshTestHarness.LogEntry> getLog()
isInteractiveback to summary
public boolean isInteractive()

Implements abstract org.eclipse.jgit.transport.CredentialsProvider.isInteractive.

Doc from org.eclipse.jgit.transport.CredentialsProvider.isInteractive.

Check if the provider is interactive with the end-user. An interactive provider may try to open a dialog box, or prompt for input on the terminal, and will wait for a user response. A non-interactive provider will either populate CredentialItems, or fail.

Returns:boolean

true if the provider is interactive with the end-user.

Annotations
@Override
logItemsback to summary
private void logItems(URIish uri, CredentialItem... items)
supportsback to summary
public boolean supports(CredentialItem... items)

Implements abstract org.eclipse.jgit.transport.CredentialsProvider.supports.

Doc from org.eclipse.jgit.transport.CredentialsProvider.supports.

Check if the provider can supply the necessary org.eclipse.jgit.transport.CredentialItems.

Parameters
items:CredentialItem[]

the items the application requires to complete authentication.

Returns:boolean

true if this org.eclipse.jgit.transport.CredentialsProvider supports all of the items supplied.

Annotations
@Override