summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/gitblit/tests/JschConfigTestSessionFactory.java
blob: 5d24b4017e7c9e22f1833f4750da0c8438d29ecb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.gitblit.tests;

import java.security.KeyPair;

import org.eclipse.jgit.transport.JschConfigSessionFactory;
import org.eclipse.jgit.transport.OpenSshConfig;
import org.eclipse.jgit.util.FS;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;

public class JschConfigTestSessionFactory extends JschConfigSessionFactory {

	final KeyPair keyPair;

	public JschConfigTestSessionFactory(KeyPair keyPair) {
		this.keyPair = keyPair;
	}

    @Override
    protected void configure(OpenSshConfig.Host host, Session session) {
        session.setConfig("StrictHostKeyChecking", "no");
    }

    @Override
	protected JSch getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException {
    	JSch jsch = super.getJSch(hc, fs);
//    	jsch.removeAllIdentity();
//    	jsch.addIdentity("unittest", keyPair.getPrivate().getEncoded(), keyPair.getPublic().getEncoded(), null);
    	return jsch;
    }
}