View Javadoc
1   /*
2    * Copyright (C) 2020 Thomas Wolf <thomas.wolf@paranor.ch> and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  package org.eclipse.jgit.transport.sshd;
11  
12  import java.io.File;
13  import java.io.IOException;
14  import java.io.UncheckedIOException;
15  import java.nio.file.Files;
16  import java.util.Arrays;
17  
18  import org.eclipse.jgit.junit.ssh.SshBasicTestBase;
19  import org.eclipse.jgit.lib.Constants;
20  import org.eclipse.jgit.lib.Repository;
21  import org.eclipse.jgit.lib.StoredConfig;
22  import org.eclipse.jgit.transport.SshSessionFactory;
23  import org.eclipse.jgit.util.FS;
24  
25  public class ApacheSshProtocol2Test extends SshBasicTestBase {
26  
27  	@Override
28  	protected SshSessionFactory createSessionFactory() {
29  		return new SshdSessionFactoryBuilder()
30  				// No proxies in tests
31  				.setProxyDataFactory(null)
32  				// No ssh-agent in tests
33  				.setConnectorFactory(null)
34  				// The home directory is mocked at this point!
35  				.setHomeDirectory(FS.DETECTED.userHome())
36  				.setSshDirectory(sshDir)
37  				.build(new JGitKeyCache());
38  	}
39  
40  	@Override
41  	protected void installConfig(String... config) {
42  		File configFile = new File(sshDir, Constants.CONFIG);
43  		if (config != null) {
44  			try {
45  				Files.write(configFile.toPath(), Arrays.asList(config));
46  			} catch (IOException e) {
47  				throw new UncheckedIOException(e);
48  			}
49  		}
50  	}
51  
52  	@Override
53  	public void setUp() throws Exception {
54  		super.setUp();
55  		StoredConfig config = ((Repository) db).getConfig();
56  		config.setInt("protocol", null, "version", 2);
57  		config.save();
58  	}
59  }