1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.provider.git.command.checkout;
20
21 import java.nio.file.Path;
22 import java.security.GeneralSecurityException;
23
24 import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
25 import org.apache.maven.scm.provider.git.GitScmTestUtils;
26 import org.apache.maven.scm.provider.git.GitSshServer;
27 import org.apache.maven.scm.repository.ScmRepository;
28 import org.apache.maven.scm.tck.command.checkout.CheckOutCommandTckTest;
29 import org.junit.Assume;
30 import org.junit.Rule;
31 import org.junit.Test;
32 import org.junit.rules.TemporaryFolder;
33
34
35
36
37 public abstract class GitSshCheckOutCommandTckTest extends CheckOutCommandTckTest {
38 protected final GitSshServer gitSshServer;
39
40 @Rule
41 public TemporaryFolder tmpDirectory = new TemporaryFolder();
42
43 protected GitSshCheckOutCommandTckTest() throws GeneralSecurityException {
44 gitSshServer = new GitSshServer();
45 }
46
47 protected abstract String getScmProvider();
48
49
50 public String getScmUrl() throws Exception {
51 return "scm:" + getScmProvider() + ":ssh://localhost:" + gitSshServer.getPort() + "/repository";
52 }
53
54 protected void configureCredentials(ScmRepository repository, String passphrase) throws Exception {
55 ScmProviderRepositoryWithHost providerRepository =
56 ScmProviderRepositoryWithHost.class.cast(repository.getProviderRepository());
57
58 Path privateKeyFile = tmpDirectory.newFile().toPath();
59 gitSshServer.writePrivateKeyAsPkcs8(privateKeyFile, passphrase);
60 providerRepository.setPrivateKey(privateKeyFile.toString());
61 providerRepository.setPassphrase(passphrase);
62 }
63
64
65 public void initRepo() throws Exception {
66 GitScmTestUtils.initRepo("src/test/resources/repository/", getRepositoryRoot(), getWorkingDirectory());
67 gitSshServer.start(getRepositoryRoot().getParentFile().toPath());
68
69
70 configureCredentials(getScmRepository(), null);
71 }
72
73 @Override
74 public void removeRepo() throws Exception {
75 gitSshServer.stop();
76 super.removeRepo();
77 }
78
79 @Override
80 @Test
81 public void testCheckOutCommandTest() throws Exception {
82 configureCredentials(getScmRepository(), null);
83 super.testCheckOutCommandTest();
84 }
85
86 @Test
87 public void testCheckOutCommandWithPassphraseTest() throws Exception {
88
89 Assume.assumeTrue(
90 "Ignore test with passphrase for provider " + getScmProvider(), "jgit".equals(getScmProvider()));
91 configureCredentials(getScmRepository(), "mySecret");
92 super.testCheckOutCommandTest();
93 }
94 }