Package org.eclipse.jgit.junit.ssh
Class SshTestHarness
- java.lang.Object
-
- org.eclipse.jgit.junit.LocalDiskRepositoryTestCase
-
- org.eclipse.jgit.junit.RepositoryTestCase
-
- org.eclipse.jgit.junit.ssh.SshTestHarness
-
- Direct Known Subclasses:
SshTestBase
public abstract class SshTestHarness extends RepositoryTestCase
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 viacopyTestResource(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 inSshTestBase.KEY_RESOURCES.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classSshTestHarness.LogEntryprotected static classSshTestHarness.TestCredentialsProvider
-
Field Summary
Fields Modifier and Type Field Description private SshSessionFactoryfactoryprivate java.io.FilehomeDirprotected java.io.FileknownHostsprotected java.io.FileprivateKey1protected java.io.FileprivateKey2protected java.io.FilepublicKey1protected SshTestGitServerserverprotected java.io.FilesshDirprotected static java.lang.StringTEST_USERprotected inttestPort-
Fields inherited from class org.eclipse.jgit.junit.RepositoryTestCase
db, trash
-
Fields inherited from class org.eclipse.jgit.junit.LocalDiskRepositoryTestCase
ASSUME_UNCHANGED, author, committer, CONTENT, CONTENT_ID, LENGTH, mockSystemReader, MOD_TIME, SMUDGE
-
-
Constructor Summary
Constructors Constructor Description SshTestHarness()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.io.FilecloneWith(java.lang.String uri, java.io.File to, CredentialsProvider provider, java.lang.String... config)protected voidcopyTestResource(java.lang.Class<?> loader, java.lang.String resourceName, java.io.File to)Copies a test data file contained in the test bundle to the given file, usingClass.getResourceAsStream(String)to get the test resource.protected voidcopyTestResource(java.lang.String resourceName, java.io.File to)Copies a test data file contained in the test bundle to the given file.private static byte[]createHostKey(java.io.OutputStream publicKey)private static java.io.FilecreateKeyPair(java.io.File privateKeyFile)protected static java.lang.StringcreateKnownHostsFile(java.io.File file, java.lang.String host, int port, java.io.File 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 SshSessionFactorycreateSessionFactory()protected SshSessionFactorygetSessionFactory()protected booleanhasHostKey(java.lang.String host, int port, java.lang.String keyPart, java.util.List<java.lang.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.protected abstract voidinstallConfig(java.lang.String... config)protected voidpushTo(java.io.File localClone)protected voidpushTo(CredentialsProvider provider, java.io.File localClone)voidsetUp()Setup testvoidshutdownServer()-
Methods inherited from class org.eclipse.jgit.junit.RepositoryTestCase
assertEqualsFile, check, checkFile, checkoutBranch, commitFile, copyFile, createBranch, createEntry, createEntry, createEntry, deleteTrashFile, fsTick, indexState, lookup, read, resetIndex, slashify, writeLink, writeTrashFile, writeTrashFile, writeTrashFiles
-
Methods inherited from class org.eclipse.jgit.junit.LocalDiskRepositoryTestCase
addRepoToClose, createBareRepository, createRepository, createRepository, createTempDirectory, createTempFile, createUniqueTestGitDir, createWorkRepository, getCeilings, getTemporaryDirectory, indexState, read, recursiveDelete, runHook, tearDown, tick, write, write
-
-
-
-
Field Detail
-
TEST_USER
protected static final java.lang.String TEST_USER
- See Also:
- Constant Field Values
-
sshDir
protected java.io.File sshDir
-
privateKey1
protected java.io.File privateKey1
-
privateKey2
protected java.io.File privateKey2
-
publicKey1
protected java.io.File publicKey1
-
server
protected SshTestGitServer server
-
factory
private SshSessionFactory factory
-
testPort
protected int testPort
-
knownHosts
protected java.io.File knownHosts
-
homeDir
private java.io.File homeDir
-
-
Method Detail
-
setUp
public void setUp() throws java.lang.ExceptionDescription copied from class:RepositoryTestCaseSetup test- Overrides:
setUpin classRepositoryTestCase- Throws:
java.lang.Exception
-
createKeyPair
private static java.io.File createKeyPair(java.io.File privateKeyFile) throws java.lang.Exception- Throws:
java.lang.Exception
-
createHostKey
private static byte[] createHostKey(java.io.OutputStream publicKey) throws java.lang.Exception- Throws:
java.lang.Exception
-
createKnownHostsFile
protected static java.lang.String createKnownHostsFile(java.io.File file, java.lang.String host, int port, java.io.File publicKey) throws java.io.IOExceptionCreates a new known_hosts file with one entry for the given host and port taken from the given public key file.- Parameters:
file- to write the known_hosts file tohost- for the entryport- for the entrypublicKey- to use- Returns:
- the public-key part of the line
- Throws:
java.io.IOException
-
hasHostKey
protected boolean hasHostKey(java.lang.String host, int port, java.lang.String keyPart, java.util.List<java.lang.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- to look forport- to look forkeyPart- to look forlines- to look in- Returns:
trueif found,falseotherwise
-
shutdownServer
public void shutdownServer() throws java.lang.Exception- Throws:
java.lang.Exception
-
createSessionFactory
protected abstract SshSessionFactory createSessionFactory()
-
getSessionFactory
protected SshSessionFactory getSessionFactory()
-
installConfig
protected abstract void installConfig(java.lang.String... config)
-
copyTestResource
protected void copyTestResource(java.lang.String resourceName, java.io.File to) throws java.io.IOExceptionCopies a test data file contained in the test bundle to the given file. Equivalent tocopyTestResource(Class, String, File)withSshTestHarness.classas first parameter.- Parameters:
resourceName- of the test resource to copyto- file to copy the resource to- Throws:
java.io.IOException- if the resource cannot be copied
-
copyTestResource
protected void copyTestResource(java.lang.Class<?> loader, java.lang.String resourceName, java.io.File to) throws java.io.IOExceptionCopies a test data file contained in the test bundle to the given file, usingClass.getResourceAsStream(String)to get the test resource.- Parameters:
loader-Classto use to load the resourceresourceName- of the test resource to copyto- file to copy the resource to- Throws:
java.io.IOException- if the resource cannot be copied
-
cloneWith
protected java.io.File cloneWith(java.lang.String uri, java.io.File to, CredentialsProvider provider, java.lang.String... config) throws java.lang.Exception- Throws:
java.lang.Exception
-
pushTo
protected void pushTo(java.io.File localClone) throws java.lang.Exception- Throws:
java.lang.Exception
-
pushTo
protected void pushTo(CredentialsProvider provider, java.io.File localClone) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-