michael-o commented on code in PR #155:
URL: https://github.com/apache/maven-scm/pull/155#discussion_r926884705


##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/pom.xml:
##########
@@ -48,8 +48,8 @@
       <artifactId>maven-scm-provider-git-commons</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-interactivity-api</artifactId>
+      <groupId>org.codehaus.plexus</groupId>

Review Comment:
   Retain order please



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/java/org/apache/maven/scm/provider/git/jgit/command/checkout/JGitSshCheckOutCommandTckTest.java:
##########
@@ -0,0 +1,149 @@
+package org.apache.maven.scm.provider.git.jgit.command.checkout;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.security.GeneralSecurityException;
+import java.security.PublicKey;
+import java.util.function.Consumer;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
+import 
org.apache.maven.scm.provider.git.command.checkout.GitSshCheckOutCommandTckTest;
+import org.apache.maven.scm.provider.git.jgit.JGitTestScmProvider;
+import 
org.apache.maven.scm.provider.git.jgit.command.ScmProviderAwareSshdSessionFactory;
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.sshd.common.config.keys.PublicKeyEntry;
+import org.eclipse.jgit.annotations.NonNull;
+import org.eclipse.jgit.internal.transport.sshd.OpenSshServerKeyDatabase;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.sshd.ServerKeyDatabase;
+import org.eclipse.jgit.util.FileUtils;
+import org.junit.Test;
+import org.slf4j.Logger;
+
+/** @author <a href="mailto:[email protected]";>Mark Struberg</a> */
+public class JGitSshCheckOutCommandTckTest
+    extends GitSshCheckOutCommandTckTest
+{
+
+    public JGitSshCheckOutCommandTckTest() throws GeneralSecurityException, 
IOException
+    {
+        super();
+    }
+
+    @Override
+    protected String getScmProvider()
+    {
+        return "jgit";
+    }
+
+    @Override
+    public void initRepo() throws Exception
+    {
+        super.initRepo();
+        JGitTestScmProvider provider = (JGitTestScmProvider) 
getScmManager().getProviderByRepository( getScmRepository() );
+        // accept all hosts
+        provider.registerCheckOutCommandCallback( new 
Consumer<JGitCheckOutCommand>()
+        {
+            @Override
+            public void accept( JGitCheckOutCommand command )
+            {
+                command.setSshSessionFactorySupplier( 
AcceptAllHostsSshdSessionFactory::new );
+            }
+
+        } );
+    }
+
+    private static final class AcceptAllHostsSshdSessionFactory extends 
ScmProviderAwareSshdSessionFactory
+    {
+        public AcceptAllHostsSshdSessionFactory( GitScmProviderRepository 
repo, Logger logger )
+        {
+            super( repo, logger );
+        }
+
+        @Override
+        protected ServerKeyDatabase createServerKeyDatabase( File homeDir, 
File sshDir )
+        {
+            return new OpenSshServerKeyDatabase( false, null )
+            {
+                @Override
+                public boolean accept( @NonNull String connectAddress,
+                        @NonNull InetSocketAddress remoteAddress,
+                        @NonNull PublicKey serverKey,
+                        @NonNull Configuration config, CredentialsProvider 
provider )
+                {
+                    return true;
+                }
+            };
+        }
+    }
+
+    @Override
+    protected void deleteDirectory( File directory )
+        throws IOException
+    {
+        if ( directory.exists() )
+        {
+            FileUtils.delete( directory, FileUtils.RECURSIVE | FileUtils.RETRY 
);
+        }
+    }
+
+    @Test
+    public void testCheckOutCommandTestWithOpenSSHPrivateKey()
+        throws Exception
+    {
+        configureKeypairFromResource( getScmRepository(), "sample_rsa", 
"mySecret");
+        super.testCheckOutCommandTest();
+    }
+
+    private void configureKeypairFromResource( ScmRepository repository, 
String resourceName, String passphrase )
+        throws IOException, GeneralSecurityException
+    {
+        // accept public key
+        try ( InputStream publicKeyInputStream = 
this.getClass().getResourceAsStream( "/ssh-keypairs/" + resourceName + ".pub"))

Review Comment:
   spaces missing



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/checkout/GitSshCheckOutCommandTckTest.java:
##########
@@ -0,0 +1,190 @@
+package org.apache.maven.scm.provider.git.command.checkout;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.nio.file.FileSystem;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.security.GeneralSecurityException;
+import java.security.KeyPair;
+import java.security.PublicKey;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
+import org.apache.maven.scm.provider.git.GitScmTestUtils;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.scm.tck.command.checkout.CheckOutCommandTckTest;
+import org.apache.sshd.common.config.keys.KeyUtils;
+import 
org.apache.sshd.common.config.keys.writer.openssh.OpenSSHKeyEncryptionContext;
+import 
org.apache.sshd.common.config.keys.writer.openssh.OpenSSHKeyPairResourceWriter;
+import org.apache.sshd.git.GitLocationResolver;
+import org.apache.sshd.git.pack.GitPackCommandFactory;
+import org.apache.sshd.server.SshServer;
+import org.apache.sshd.server.auth.pubkey.KeySetPublickeyAuthenticator;
+import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
+import org.apache.sshd.server.session.ServerSession;
+import org.apache.sshd.util.test.CommonTestSupportUtils;
+import org.apache.sshd.util.test.CoreTestSupportUtils;
+import org.bouncycastle.openssl.PKCS8Generator;
+import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
+import org.bouncycastle.openssl.jcajce.JcaPKCS8Generator;
+import org.bouncycastle.util.io.pem.PemObject;
+import org.junit.Assume;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ *
+ */
+public abstract class GitSshCheckOutCommandTckTest
+    extends CheckOutCommandTckTest
+{
+    protected final SshServer sshServer;
+    protected final KeyPair keyPair;
+    protected final List<PublicKey> acceptedPublicKeys;
+
+    @Rule
+    public TemporaryFolder tmpDirectory = new TemporaryFolder();
+
+    protected GitSshCheckOutCommandTckTest() throws GeneralSecurityException
+    {
+         sshServer = CoreTestSupportUtils.setupTestServer( getClass() );
+         keyPair = CommonTestSupportUtils.generateKeyPair( 
KeyUtils.RSA_ALGORITHM, 2048 );
+         acceptedPublicKeys = new ArrayList<>();
+         acceptedPublicKeys.add( keyPair.getPublic() );
+         PublickeyAuthenticator authenticator = new 
KeySetPublickeyAuthenticator( "onlykey",
+                  acceptedPublicKeys );
+         sshServer.setPublickeyAuthenticator( authenticator );
+    }
+
+    void writePrivateKeyAsPkcs8( Path file, String passphrase )
+            throws IOException, GeneralSecurityException
+    {
+        // encryption only optional
+        if ( passphrase != null )
+        {
+            // encryption with format outlined in 
https://dnaeon.github.io/openssh-private-key-binary-format/
+            OpenSSHKeyPairResourceWriter writer = new 
OpenSSHKeyPairResourceWriter();
+            OpenSSHKeyEncryptionContext context = new 
OpenSSHKeyEncryptionContext();
+            context.setCipherType( "192" );
+            context.setPassword( passphrase );
+            try ( OutputStream output = Files.newOutputStream( file ) )
+            {
+                writer.writePrivateKey( keyPair, "comment", context, output );
+            }
+        }
+        else 
+        {
+            // wrap unencrypted private key as regular PKCS8 private key
+            PKCS8Generator pkcs8Generator = new JcaPKCS8Generator( 
keyPair.getPrivate(), null );
+            PemObject pemObject = pkcs8Generator.generate();
+            
+            try ( Writer writer = Files.newBufferedWriter( file );
+                            JcaPEMWriter pw = new JcaPEMWriter( writer ) )
+            {
+                pw.writeObject( pemObject );
+            }

Review Comment:
   I am confused and what if you use the abover without a passowrd? I mean it 
is a setter on the context, therefore, optional...



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/checkout/GitSshCheckOutCommandTckTest.java:
##########
@@ -0,0 +1,190 @@
+package org.apache.maven.scm.provider.git.command.checkout;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.nio.file.FileSystem;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.security.GeneralSecurityException;
+import java.security.KeyPair;
+import java.security.PublicKey;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
+import org.apache.maven.scm.provider.git.GitScmTestUtils;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.scm.tck.command.checkout.CheckOutCommandTckTest;
+import org.apache.sshd.common.config.keys.KeyUtils;
+import 
org.apache.sshd.common.config.keys.writer.openssh.OpenSSHKeyEncryptionContext;
+import 
org.apache.sshd.common.config.keys.writer.openssh.OpenSSHKeyPairResourceWriter;
+import org.apache.sshd.git.GitLocationResolver;
+import org.apache.sshd.git.pack.GitPackCommandFactory;
+import org.apache.sshd.server.SshServer;
+import org.apache.sshd.server.auth.pubkey.KeySetPublickeyAuthenticator;
+import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
+import org.apache.sshd.server.session.ServerSession;
+import org.apache.sshd.util.test.CommonTestSupportUtils;
+import org.apache.sshd.util.test.CoreTestSupportUtils;
+import org.bouncycastle.openssl.PKCS8Generator;
+import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
+import org.bouncycastle.openssl.jcajce.JcaPKCS8Generator;
+import org.bouncycastle.util.io.pem.PemObject;
+import org.junit.Assume;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ *
+ */
+public abstract class GitSshCheckOutCommandTckTest
+    extends CheckOutCommandTckTest
+{
+    protected final SshServer sshServer;
+    protected final KeyPair keyPair;
+    protected final List<PublicKey> acceptedPublicKeys;
+
+    @Rule
+    public TemporaryFolder tmpDirectory = new TemporaryFolder();
+
+    protected GitSshCheckOutCommandTckTest() throws GeneralSecurityException
+    {
+         sshServer = CoreTestSupportUtils.setupTestServer( getClass() );
+         keyPair = CommonTestSupportUtils.generateKeyPair( 
KeyUtils.RSA_ALGORITHM, 2048 );
+         acceptedPublicKeys = new ArrayList<>();
+         acceptedPublicKeys.add( keyPair.getPublic() );
+         PublickeyAuthenticator authenticator = new 
KeySetPublickeyAuthenticator( "onlykey",
+                  acceptedPublicKeys );
+         sshServer.setPublickeyAuthenticator( authenticator );
+    }
+
+    void writePrivateKeyAsPkcs8( Path file, String passphrase )
+            throws IOException, GeneralSecurityException
+    {
+        // encryption only optional
+        if ( passphrase != null )
+        {
+            // encryption with format outlined in 
https://dnaeon.github.io/openssh-private-key-binary-format/
+            OpenSSHKeyPairResourceWriter writer = new 
OpenSSHKeyPairResourceWriter();
+            OpenSSHKeyEncryptionContext context = new 
OpenSSHKeyEncryptionContext();
+            context.setCipherType( "192" );
+            context.setPassword( passphrase );
+            try ( OutputStream output = Files.newOutputStream( file ) )
+            {
+                writer.writePrivateKey( keyPair, "comment", context, output );
+            }
+        }
+        else 
+        {
+            // wrap unencrypted private key as regular PKCS8 private key
+            PKCS8Generator pkcs8Generator = new JcaPKCS8Generator( 
keyPair.getPrivate(), null );
+            PemObject pemObject = pkcs8Generator.generate();
+            
+            try ( Writer writer = Files.newBufferedWriter( file );
+                            JcaPEMWriter pw = new JcaPEMWriter( writer ) )
+            {
+                pw.writeObject( pemObject );
+            }
+        }
+
+        if ( file.getFileSystem().supportedFileAttributeViews().contains( 
"posix" ) )
+        {
+            // must only be readable/writeable by me
+            Files.setPosixFilePermissions( file, 
PosixFilePermissions.fromString( "rwx------" ) );
+        }
+    }
+
+    protected abstract String getScmProvider();
+
+    /** {@inheritDoc} */
+    public String getScmUrl()
+        throws Exception
+    {
+        return "scm:" + getScmProvider() + ":ssh://localhost:" + 
sshServer.getPort() + "/repository";
+    }
+
+    public void configureCredentials( ScmRepository repository, String 
passphrase ) 
+        throws Exception
+    {
+        ScmProviderRepositoryWithHost providerRepository = 
+             ScmProviderRepositoryWithHost.class.cast( 
repository.getProviderRepository() );
+        // store as file
+        Path privateKeyFile = tmpDirectory.newFile().toPath();
+        writePrivateKeyAsPkcs8( privateKeyFile, passphrase );
+        providerRepository.setPrivateKey( privateKeyFile.toString() );
+        if ( passphrase != null )
+        {
+            providerRepository.setPassphrase( passphrase );

Review Comment:
   Why test, set it right away, if it is internally, `null` then the result 
will be the same, no?



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/java/org/apache/maven/scm/provider/git/jgit/command/checkout/JGitSshCheckOutCommandTckTest.java:
##########
@@ -0,0 +1,149 @@
+package org.apache.maven.scm.provider.git.jgit.command.checkout;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.security.GeneralSecurityException;
+import java.security.PublicKey;
+import java.util.function.Consumer;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
+import 
org.apache.maven.scm.provider.git.command.checkout.GitSshCheckOutCommandTckTest;
+import org.apache.maven.scm.provider.git.jgit.JGitTestScmProvider;
+import 
org.apache.maven.scm.provider.git.jgit.command.ScmProviderAwareSshdSessionFactory;
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.sshd.common.config.keys.PublicKeyEntry;
+import org.eclipse.jgit.annotations.NonNull;
+import org.eclipse.jgit.internal.transport.sshd.OpenSshServerKeyDatabase;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.sshd.ServerKeyDatabase;
+import org.eclipse.jgit.util.FileUtils;
+import org.junit.Test;
+import org.slf4j.Logger;
+
+/** @author <a href="mailto:[email protected]";>Mark Struberg</a> */
+public class JGitSshCheckOutCommandTckTest
+    extends GitSshCheckOutCommandTckTest
+{
+
+    public JGitSshCheckOutCommandTckTest() throws GeneralSecurityException, 
IOException
+    {
+        super();
+    }
+
+    @Override
+    protected String getScmProvider()
+    {
+        return "jgit";
+    }
+
+    @Override
+    public void initRepo() throws Exception
+    {
+        super.initRepo();
+        JGitTestScmProvider provider = (JGitTestScmProvider) 
getScmManager().getProviderByRepository( getScmRepository() );
+        // accept all hosts
+        provider.registerCheckOutCommandCallback( new 
Consumer<JGitCheckOutCommand>()
+        {
+            @Override
+            public void accept( JGitCheckOutCommand command )
+            {
+                command.setSshSessionFactorySupplier( 
AcceptAllHostsSshdSessionFactory::new );
+            }
+
+        } );
+    }
+
+    private static final class AcceptAllHostsSshdSessionFactory extends 
ScmProviderAwareSshdSessionFactory
+    {
+        public AcceptAllHostsSshdSessionFactory( GitScmProviderRepository 
repo, Logger logger )
+        {
+            super( repo, logger );
+        }
+
+        @Override
+        protected ServerKeyDatabase createServerKeyDatabase( File homeDir, 
File sshDir )
+        {
+            return new OpenSshServerKeyDatabase( false, null )
+            {
+                @Override
+                public boolean accept( @NonNull String connectAddress,
+                        @NonNull InetSocketAddress remoteAddress,
+                        @NonNull PublicKey serverKey,
+                        @NonNull Configuration config, CredentialsProvider 
provider )
+                {
+                    return true;
+                }
+            };
+        }
+    }
+
+    @Override
+    protected void deleteDirectory( File directory )
+        throws IOException
+    {
+        if ( directory.exists() )
+        {
+            FileUtils.delete( directory, FileUtils.RECURSIVE | FileUtils.RETRY 
);
+        }
+    }
+
+    @Test
+    public void testCheckOutCommandTestWithOpenSSHPrivateKey()
+        throws Exception
+    {
+        configureKeypairFromResource( getScmRepository(), "sample_rsa", 
"mySecret");
+        super.testCheckOutCommandTest();
+    }
+
+    private void configureKeypairFromResource( ScmRepository repository, 
String resourceName, String passphrase )
+        throws IOException, GeneralSecurityException
+    {
+        // accept public key
+        try ( InputStream publicKeyInputStream = 
this.getClass().getResourceAsStream( "/ssh-keypairs/" + resourceName + ".pub"))
+        {
+            PublicKey publicKey = PublicKeyEntry.parsePublicKeyEntry( 
IOUtils.toString( publicKeyInputStream, StandardCharsets.US_ASCII ) 
).resolvePublicKey( null, null, null );
+            acceptedPublicKeys.add( publicKey );
+        }
+        Path privateKeyFile = Files.createTempFile( "privateKey", null );
+        // private key into tmp file
+        try ( InputStream privateKeyInputStream = 
this.getClass().getResourceAsStream( "/ssh-keypairs/" + resourceName ))
+        {
+            Files.copy( privateKeyInputStream, privateKeyFile, 
StandardCopyOption.REPLACE_EXISTING );
+        }
+        // configure provider repository with private key details
+        ScmProviderRepositoryWithHost providerRepository = 
+                        ScmProviderRepositoryWithHost.class.cast( 
repository.getProviderRepository() );
+        if ( passphrase != null )

Review Comment:
   Why test, set it right away, if it is internally, `null` then the result 
will be the same, no?



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/test/java/org/apache/maven/scm/provider/git/jgit/command/checkout/JGitSshCheckOutCommandTckTest.java:
##########
@@ -0,0 +1,149 @@
+package org.apache.maven.scm.provider.git.jgit.command.checkout;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.security.GeneralSecurityException;
+import java.security.PublicKey;
+import java.util.function.Consumer;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
+import 
org.apache.maven.scm.provider.git.command.checkout.GitSshCheckOutCommandTckTest;
+import org.apache.maven.scm.provider.git.jgit.JGitTestScmProvider;
+import 
org.apache.maven.scm.provider.git.jgit.command.ScmProviderAwareSshdSessionFactory;
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.sshd.common.config.keys.PublicKeyEntry;
+import org.eclipse.jgit.annotations.NonNull;
+import org.eclipse.jgit.internal.transport.sshd.OpenSshServerKeyDatabase;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.sshd.ServerKeyDatabase;
+import org.eclipse.jgit.util.FileUtils;
+import org.junit.Test;
+import org.slf4j.Logger;
+
+/** @author <a href="mailto:[email protected]";>Mark Struberg</a> */
+public class JGitSshCheckOutCommandTckTest
+    extends GitSshCheckOutCommandTckTest
+{
+
+    public JGitSshCheckOutCommandTckTest() throws GeneralSecurityException, 
IOException
+    {
+        super();
+    }
+
+    @Override
+    protected String getScmProvider()
+    {
+        return "jgit";
+    }
+
+    @Override
+    public void initRepo() throws Exception
+    {
+        super.initRepo();
+        JGitTestScmProvider provider = (JGitTestScmProvider) 
getScmManager().getProviderByRepository( getScmRepository() );
+        // accept all hosts
+        provider.registerCheckOutCommandCallback( new 
Consumer<JGitCheckOutCommand>()
+        {
+            @Override
+            public void accept( JGitCheckOutCommand command )
+            {
+                command.setSshSessionFactorySupplier( 
AcceptAllHostsSshdSessionFactory::new );
+            }
+
+        } );
+    }
+
+    private static final class AcceptAllHostsSshdSessionFactory extends 
ScmProviderAwareSshdSessionFactory
+    {
+        public AcceptAllHostsSshdSessionFactory( GitScmProviderRepository 
repo, Logger logger )
+        {
+            super( repo, logger );
+        }
+
+        @Override
+        protected ServerKeyDatabase createServerKeyDatabase( File homeDir, 
File sshDir )
+        {
+            return new OpenSshServerKeyDatabase( false, null )
+            {
+                @Override
+                public boolean accept( @NonNull String connectAddress,
+                        @NonNull InetSocketAddress remoteAddress,
+                        @NonNull PublicKey serverKey,
+                        @NonNull Configuration config, CredentialsProvider 
provider )
+                {
+                    return true;
+                }
+            };
+        }
+    }
+
+    @Override
+    protected void deleteDirectory( File directory )
+        throws IOException
+    {
+        if ( directory.exists() )
+        {
+            FileUtils.delete( directory, FileUtils.RECURSIVE | FileUtils.RETRY 
);
+        }
+    }
+
+    @Test
+    public void testCheckOutCommandTestWithOpenSSHPrivateKey()
+        throws Exception
+    {
+        configureKeypairFromResource( getScmRepository(), "sample_rsa", 
"mySecret");
+        super.testCheckOutCommandTest();
+    }
+
+    private void configureKeypairFromResource( ScmRepository repository, 
String resourceName, String passphrase )
+        throws IOException, GeneralSecurityException
+    {
+        // accept public key
+        try ( InputStream publicKeyInputStream = 
this.getClass().getResourceAsStream( "/ssh-keypairs/" + resourceName + ".pub"))
+        {
+            PublicKey publicKey = PublicKeyEntry.parsePublicKeyEntry( 
IOUtils.toString( publicKeyInputStream, StandardCharsets.US_ASCII ) 
).resolvePublicKey( null, null, null );
+            acceptedPublicKeys.add( publicKey );
+        }
+        Path privateKeyFile = Files.createTempFile( "privateKey", null );
+        // private key into tmp file
+        try ( InputStream privateKeyInputStream = 
this.getClass().getResourceAsStream( "/ssh-keypairs/" + resourceName ))

Review Comment:
   spaces missing



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to