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  		SshdSessionFactory result = new SshdSessionFactory(new JGitKeyCache(),
30  				null);
31  		// The home directory is mocked at this point!
32  		result.setHomeDirectory(FS.DETECTED.userHome());
33  		result.setSshDirectory(sshDir);
34  		return result;
35  	}
36  
37  	@Override
38  	protected void installConfig(String... config) {
39  		File configFile = new File(sshDir, Constants.CONFIG);
40  		if (config != null) {
41  			try {
42  				Files.write(configFile.toPath(), Arrays.asList(config));
43  			} catch (IOException e) {
44  				throw new UncheckedIOException(e);
45  			}
46  		}
47  	}
48  
49  	@Override
50  	public void setUp() throws Exception {
51  		super.setUp();
52  		StoredConfig config = ((Repository) db).getConfig();
53  		config.setInt("protocol", null, "version", 2);
54  		config.save();
55  	}
56  }