// Path: src/main/java/com/asolutions/scmsshd/SCuMD.java
// public class SCuMD extends SshServer {
// 
// 	/**
// 	 * @param args
// 	 */
// 	public static void main(String[] args) {
// 		if (args.length != 1) {
// 			System.err.println("Usage: SCuMD pathToConfigFile");
// 			return;
// 		}
// 		new FileSystemXmlApplicationContext(args[0]);
// 	}
// 
// 	public SCuMD() {
// 		if (SecurityUtils.isBouncyCastleRegistered()) {
// 			setKeyExchangeFactories(Arrays.<NamedFactory<KeyExchange>> asList(new DHG14.Factory(), new DHG1.Factory()));
// 			setRandomFactory(new SingletonRandomFactory(new BouncyCastleRandom.Factory()));
// 		} else {
// 			setKeyExchangeFactories(Arrays.<NamedFactory<KeyExchange>> asList(new DHG1.Factory()));
// 			setRandomFactory(new SingletonRandomFactory(new JceRandom.Factory()));
// 		}
// 		setUserAuthFactories(Arrays.<NamedFactory<UserAuth>>asList(
//                 new UserAuthPassword.Factory(),
//                 new UserAuthPublicKey.Factory()
//                 ));
// 		setCipherFactories(Arrays.<NamedFactory<Cipher>> asList(new AES128CBC.Factory(), 
// 				new TripleDESCBC.Factory(),
// 				new BlowfishCBC.Factory(), 
// 				new AES192CBC.Factory(),
// 				new AES256CBC.Factory()));
// 		setCompressionFactories(Arrays.<NamedFactory<Compression>> asList(new CompressionNone.Factory()));
// 
// 		setMacFactories(Arrays.<NamedFactory<Mac>> asList(new HMACMD5.Factory(), 
// 														  new HMACSHA1.Factory(),
// 														  new HMACMD596.Factory(), 
// 														  new HMACSHA196.Factory()));
// 
//         setChannelFactories(Arrays.<NamedFactory<ServerChannel>>asList(
//                 new ChannelSession.Factory()));
// 		setSignatureFactories(Arrays.<NamedFactory<Signature>> asList(new SignatureDSA.Factory(), new SignatureRSA.Factory()));
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/authenticators/AlwaysPassPublicKeyAuthenticator.java
// public class AlwaysPassPublicKeyAuthenticator implements PublickeyAuthenticator {
// 
// 	public boolean hasKey(String username, PublicKey key, ServerSession session) {
// 		return true;
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/authorizors/AlwaysPassProjectAuthorizer.java
// public class AlwaysPassProjectAuthorizer implements IProjectAuthorizer {
// 
// 	public AuthorizationLevel userIsAuthorizedForProject(String username,
// 			String project) throws UnparsableProjectException {
// 		return AuthorizationLevel.AUTH_LEVEL_READ_WRITE;
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/commands/factories/GitCommandFactory.java
// public class GitCommandFactory extends CommandFactoryBase {
// 	protected final Logger log = LoggerFactory.getLogger(getClass());
// 	public GitCommandFactory() {
// 		setBadCommandFilter(new GitBadCommandFilter());
// 		setScmCommandFactory(new GitSCMCommandFactory());
// 	}
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/commands/factories/GitSCMCommandFactory.java
// public class GitSCMCommandFactory implements ISCMCommandFactory {
// 
// 	public static final String REPOSITORY_BASE = "repositoryBase";
// 
// 	public Command create(FilteredCommand filteredCommand,
// 			IProjectAuthorizer projectAuthorizer,
// 			IPathToProjectNameConverter pathToProjectNameConverter,
// 			Properties configuration) {
// 		SCMCommand retVal = new SCMCommand(filteredCommand, projectAuthorizer, new GitSCMCommandHandler(), pathToProjectNameConverter, configuration);
// 		return retVal;
// 	}
// 
// }
// 
// Path: src/exttest/java/com/asolutions/scmsshd/test/integration/util/ConstantProjectNameConverter.java
// public class ConstantProjectNameConverter implements
// 		IPathToProjectNameConverter {
// 
// 	public ConstantProjectNameConverter() {
// 	}
// 
// 	public String convert(String toParse) throws UnparsableProjectException {
// 		return "constant";
// 	}
// 
// }


import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
import org.junit.Test;
import org.spearce.jgit.lib.Repository;
import org.spearce.jgit.transport.FetchResult;
import com.asolutions.scmsshd.SCuMD;
import com.asolutions.scmsshd.authenticators.AlwaysPassPublicKeyAuthenticator;
import com.asolutions.scmsshd.authorizors.AlwaysPassProjectAuthorizer;
import com.asolutions.scmsshd.commands.factories.GitCommandFactory;
import com.asolutions.scmsshd.commands.factories.GitSCMCommandFactory;
import com.asolutions.scmsshd.test.integration.util.ConstantProjectNameConverter;
package com.asolutions.scmsshd.test.integration;






public class FetchTest extends IntegrationTestCase {
	
	@Test
	public void testFetchLocal() throws Exception {
		File gitDir = new File(".git");
		String remoteName = "origin";
		
		Repository db = createCloneToRepo();
		addRemoteConfigForLocalGitDirectory(db, gitDir, remoteName);
		FetchResult r = cloneFromRemote(db, remoteName);
		assert(r.getTrackingRefUpdates().size() > 0);
	}
	
	@Test
	public void testFetchFromScumd() throws Exception {
		final SCuMD sshd = new SCuMD();
		try{
			int serverPort = generatePort();
			System.out.println("Running on port: " + serverPort);
			sshd.setPort(serverPort);
			sshd.setKeyPairProvider(new FileKeyPairProvider(new String[] { "src/main/resources/ssh_host_rsa_key", 
																		   "src/main/resources/ssh_host_dsa_key" }));
			sshd.setPublickeyAuthenticator(new AlwaysPassPublicKeyAuthenticator());
			
// Path: src/main/java/com/asolutions/scmsshd/SCuMD.java
// public class SCuMD extends SshServer {
// 
// 	/**
// 	 * @param args
// 	 */
// 	public static void main(String[] args) {
// 		if (args.length != 1) {
// 			System.err.println("Usage: SCuMD pathToConfigFile");
// 			return;
// 		}
// 		new FileSystemXmlApplicationContext(args[0]);
// 	}
// 
// 	public SCuMD() {
// 		if (SecurityUtils.isBouncyCastleRegistered()) {
// 			setKeyExchangeFactories(Arrays.<NamedFactory<KeyExchange>> asList(new DHG14.Factory(), new DHG1.Factory()));
// 			setRandomFactory(new SingletonRandomFactory(new BouncyCastleRandom.Factory()));
// 		} else {
// 			setKeyExchangeFactories(Arrays.<NamedFactory<KeyExchange>> asList(new DHG1.Factory()));
// 			setRandomFactory(new SingletonRandomFactory(new JceRandom.Factory()));
// 		}
// 		setUserAuthFactories(Arrays.<NamedFactory<UserAuth>>asList(
//                 new UserAuthPassword.Factory(),
//                 new UserAuthPublicKey.Factory()
//                 ));
// 		setCipherFactories(Arrays.<NamedFactory<Cipher>> asList(new AES128CBC.Factory(), 
// 				new TripleDESCBC.Factory(),
// 				new BlowfishCBC.Factory(), 
// 				new AES192CBC.Factory(),
// 				new AES256CBC.Factory()));
// 		setCompressionFactories(Arrays.<NamedFactory<Compression>> asList(new CompressionNone.Factory()));
// 
// 		setMacFactories(Arrays.<NamedFactory<Mac>> asList(new HMACMD5.Factory(), 
// 														  new HMACSHA1.Factory(),
// 														  new HMACMD596.Factory(), 
// 														  new HMACSHA196.Factory()));
// 
//         setChannelFactories(Arrays.<NamedFactory<ServerChannel>>asList(
//                 new ChannelSession.Factory()));
// 		setSignatureFactories(Arrays.<NamedFactory<Signature>> asList(new SignatureDSA.Factory(), new SignatureRSA.Factory()));
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/authenticators/AlwaysPassPublicKeyAuthenticator.java
// public class AlwaysPassPublicKeyAuthenticator implements PublickeyAuthenticator {
// 
// 	public boolean hasKey(String username, PublicKey key, ServerSession session) {
// 		return true;
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/authorizors/AlwaysPassProjectAuthorizer.java
// public class AlwaysPassProjectAuthorizer implements IProjectAuthorizer {
// 
// 	public AuthorizationLevel userIsAuthorizedForProject(String username,
// 			String project) throws UnparsableProjectException {
// 		return AuthorizationLevel.AUTH_LEVEL_READ_WRITE;
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/commands/factories/GitCommandFactory.java
// public class GitCommandFactory extends CommandFactoryBase {
// 	protected final Logger log = LoggerFactory.getLogger(getClass());
// 	public GitCommandFactory() {
// 		setBadCommandFilter(new GitBadCommandFilter());
// 		setScmCommandFactory(new GitSCMCommandFactory());
// 	}
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/commands/factories/GitSCMCommandFactory.java
// public class GitSCMCommandFactory implements ISCMCommandFactory {
// 
// 	public static final String REPOSITORY_BASE = "repositoryBase";
// 
// 	public Command create(FilteredCommand filteredCommand,
// 			IProjectAuthorizer projectAuthorizer,
// 			IPathToProjectNameConverter pathToProjectNameConverter,
// 			Properties configuration) {
// 		SCMCommand retVal = new SCMCommand(filteredCommand, projectAuthorizer, new GitSCMCommandHandler(), pathToProjectNameConverter, configuration);
// 		return retVal;
// 	}
// 
// }
// 
// Path: src/exttest/java/com/asolutions/scmsshd/test/integration/util/ConstantProjectNameConverter.java
// public class ConstantProjectNameConverter implements
// 		IPathToProjectNameConverter {
// 
// 	public ConstantProjectNameConverter() {
// 	}
// 
// 	public String convert(String toParse) throws UnparsableProjectException {
// 		return "constant";
// 	}
// 
// }


// Path: src/exttest/java/com/asolutions/scmsshd/test/integration/FetchTest.java
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
import org.junit.Test;
import org.spearce.jgit.lib.Repository;
import org.spearce.jgit.transport.FetchResult;
import com.asolutions.scmsshd.SCuMD;
import com.asolutions.scmsshd.authenticators.AlwaysPassPublicKeyAuthenticator;
import com.asolutions.scmsshd.authorizors.AlwaysPassProjectAuthorizer;
import com.asolutions.scmsshd.commands.factories.GitCommandFactory;
import com.asolutions.scmsshd.commands.factories.GitSCMCommandFactory;
import com.asolutions.scmsshd.test.integration.util.ConstantProjectNameConverter;

package com.asolutions.scmsshd.test.integration;






public class FetchTest extends IntegrationTestCase {
	
	@Test
	public void testFetchLocal() throws Exception {
		File gitDir = new File(".git");
		String remoteName = "origin";
		
		Repository db = createCloneToRepo();
		addRemoteConfigForLocalGitDirectory(db, gitDir, remoteName);
		FetchResult r = cloneFromRemote(db, remoteName);
		assert(r.getTrackingRefUpdates().size() > 0);
	}
	
	@Test
	public void testFetchFromScumd() throws Exception {
		final SCuMD sshd = new SCuMD();
		try{
			int serverPort = generatePort();
			System.out.println("Running on port: " + serverPort);
			sshd.setPort(serverPort);
			sshd.setKeyPairProvider(new FileKeyPairProvider(new String[] { "src/main/resources/ssh_host_rsa_key", 
																		   "src/main/resources/ssh_host_dsa_key" }));
			sshd.setPublickeyAuthenticator(new AlwaysPassPublicKeyAuthenticator());
			
			GitCommandFactory factory = new GitCommandFactory();