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 public abstract class GitSshCheckOutCommandTckTest extends CheckOutCommandTckTest {
35 protected final GitSshServer gitSshServer;
36
37 @Rule
38 public TemporaryFolder tmpDirectory = new TemporaryFolder();
39
40 protected GitSshCheckOutCommandTckTest() throws GeneralSecurityException {
41 gitSshServer = new GitSshServer();
42 }
43
44 protected abstract String getScmProvider();
45
46
47
48
49 public String getScmUrl() throws Exception {
50 return "scm:" + getScmProvider() + ":ssh://localhost:" + gitSshServer.getPort() + "/repository";
51 }
52
53 protected void configureCredentials(ScmRepository repository, String passphrase) throws Exception {
54 ScmProviderRepositoryWithHost providerRepository =
55 ScmProviderRepositoryWithHost.class.cast(repository.getProviderRepository());
56
57 Path privateKeyFile = tmpDirectory.newFile().toPath();
58 gitSshServer.writePrivateKeyAsPkcs8(privateKeyFile, passphrase);
59 providerRepository.setPrivateKey(privateKeyFile.toString());
60 providerRepository.setPassphrase(passphrase);
61 }
62
63
64
65
66 public void initRepo() throws Exception {
67 GitScmTestUtils.initRepo("src/test/resources/repository/", getRepositoryRoot(), getWorkingDirectory());
68 gitSshServer.start(getRepositoryRoot().getParentFile().toPath());
69
70
71 configureCredentials(getScmRepository(), null);
72 }
73
74 @Override
75 public void removeRepo() throws Exception {
76 gitSshServer.stop();
77 super.removeRepo();
78 }
79
80 @Override
81 @Test
82 public void testCheckOutCommandTest() throws Exception {
83 configureCredentials(getScmRepository(), null);
84 super.testCheckOutCommandTest();
85 }
86
87 @Test
88 public void testCheckOutCommandWithPassphraseTest() throws Exception {
89
90 Assume.assumeTrue(
91 "Ignore test with passphrase for provider " + getScmProvider(), "jgit".equals(getScmProvider()));
92 configureCredentials(getScmRepository(), "mySecret");
93 super.testCheckOutCommandTest();
94 }
95 }