Class SshTestHarness

  • Direct Known Subclasses:
    SshBasicTestBase

    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 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.
    • Field Detail

      • sshDir

        protected java.io.File sshDir
      • privateKey1

        protected java.io.File privateKey1
      • privateKey2

        protected java.io.File privateKey2
      • publicKey1

        protected java.io.File publicKey1
      • publicKey2

        protected java.io.File publicKey2
      • testPort

        protected int testPort
      • knownHosts

        protected java.io.File knownHosts
      • homeDir

        private java.io.File homeDir
    • Constructor Detail

      • SshTestHarness

        public SshTestHarness()
    • Method Detail

      • createKeyPair

        private static java.io.File createKeyPair​(java.security.KeyPair newKey,
                                                  java.io.File privateKeyFile)
                                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • write

        private static void write​(java.io.BufferedWriter out,
                                  byte[] bytes,
                                  int lineLength)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • createKnownHostsFile

        protected static java.lang.String createKnownHostsFile​(java.io.File file,
                                                               java.lang.String host,
                                                               int port,
                                                               java.io.File publicKey)
                                                        throws java.io.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 - to write the known_hosts file to
        host - for the entry
        port - for the entry
        publicKey - 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 for
        port - to look for
        keyPart - to look for
        lines - to look in
        Returns:
        true if found, false otherwise
      • shutdownServer

        public void shutdownServer()
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • installConfig

        protected abstract void installConfig​(java.lang.String... config)
      • copyTestResource

        protected void copyTestResource​(java.lang.String resourceName,
                                        java.io.File to)
                                 throws java.io.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 - of the test resource to copy
        to - 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.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 to use to load the resource
        resourceName - of the test resource to copy
        to - 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