Added: mina/sshd/trunk/sshd-sftp/src/test/java/org/apache/sshd/sftp/util/EchoShellFactory.java URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-sftp/src/test/java/org/apache/sshd/sftp/util/EchoShellFactory.java?rev=1434658&view=auto ============================================================================== --- mina/sshd/trunk/sshd-sftp/src/test/java/org/apache/sshd/sftp/util/EchoShellFactory.java (added) +++ mina/sshd/trunk/sshd-sftp/src/test/java/org/apache/sshd/sftp/util/EchoShellFactory.java Thu Jan 17 13:09:51 2013 @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sshd.sftp.util; + +import org.apache.sshd.common.Factory; +import org.apache.sshd.server.Command; +import org.apache.sshd.server.Environment; +import org.apache.sshd.server.ExitCallback; + +import java.io.*; + +/** + * TODO Add javadoc + * + * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> + */ +public class EchoShellFactory implements Factory<Command> { + + public Command create() { + return new EchoShell(); + } + + public static class EchoShell implements Command, Runnable { + + private InputStream in; + private OutputStream out; + private OutputStream err; + private ExitCallback callback; + private Environment environment; + private Thread thread; + + public InputStream getIn() { + return in; + } + + public OutputStream getOut() { + return out; + } + + public OutputStream getErr() { + return err; + } + + public Environment getEnvironment() { + return environment; + } + + public void setInputStream(InputStream in) { + this.in = in; + } + + public void setOutputStream(OutputStream out) { + this.out = out; + } + + public void setErrorStream(OutputStream err) { + this.err = err; + } + + public void setExitCallback(ExitCallback callback) { + this.callback = callback; + } + + public void start(Environment env) throws IOException { + environment = env; + thread = new Thread(this, "EchoShell"); + thread.start(); + } + + public void destroy() { + thread.interrupt(); + } + + public void run() { + BufferedReader r = new BufferedReader(new InputStreamReader(in)); + try { + for (;;) { + String s = r.readLine(); + if (s == null) { + return; + } + out.write((s + "\n").getBytes()); + out.flush(); + if ("exit".equals(s)) { + return; + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + callback.onExit(0); + } + } + } +}
Added: mina/sshd/trunk/sshd-sftp/src/test/java/org/apache/sshd/sftp/util/Utils.java URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-sftp/src/test/java/org/apache/sshd/sftp/util/Utils.java?rev=1434658&view=auto ============================================================================== --- mina/sshd/trunk/sshd-sftp/src/test/java/org/apache/sshd/sftp/util/Utils.java (added) +++ mina/sshd/trunk/sshd-sftp/src/test/java/org/apache/sshd/sftp/util/Utils.java Thu Jan 17 13:09:51 2013 @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sshd.sftp.util; + +import org.apache.sshd.common.keyprovider.FileKeyPairProvider; + +import java.io.File; +import java.net.ServerSocket; +import java.net.URISyntaxException; +import java.net.URL; + +public class Utils { + + public static FileKeyPairProvider createTestHostKeyProvider() { + return createTestKeyPairProvider("hostkey.pem"); + } + + public static FileKeyPairProvider createTestKeyPairProvider(String resource) { + return new FileKeyPairProvider(new String[] { getFile(resource) }); + } + + public static int getFreePort() throws Exception { + ServerSocket s = new ServerSocket(0); + try { + return s.getLocalPort(); + } finally { + s.close(); + } + } + + private static String getFile(String resource) { + URL url = Utils.class.getClassLoader().getResource(resource); + File f; + try { + f = new File(url.toURI()); + } catch(URISyntaxException e) { + f = new File(url.getPath()); + } + return f.toString(); + } + +} Added: mina/sshd/trunk/sshd-sftp/src/test/resources/hostkey.pem URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-sftp/src/test/resources/hostkey.pem?rev=1434658&view=auto ============================================================================== --- mina/sshd/trunk/sshd-sftp/src/test/resources/hostkey.pem (added) +++ mina/sshd/trunk/sshd-sftp/src/test/resources/hostkey.pem Thu Jan 17 13:09:51 2013 @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQDdfIWeSV4o68dRrKSzFd/Bk51E65UTmmSrmW0O1ohtzi6HzsDP +jXgCtlTt3FqTcfFfI92IlTr4JWqC9UK1QT1ZTeng0MkPQmv68hDANHbt5CpETZHj +W5q4OOgWhVvj5IyOC2NZHtKlJBkdsMAa15ouOOJLzBvAvbqOR/yUROsEiQIDAQAB +AoGBANG3JDW6NoP8rF/zXoeLgLCj+tfVUPSczhGFVrQkAk4mWfyRkhN0WlwHFOec +K89MpkV1ij/XPVzU4MNbQ2yod1KiDylzvweYv+EaEhASCmYNs6LS03punml42SL9 +97tOmWfVJXxlQoLiY6jHPU97vTc65k8gL+gmmrpchsW0aqmZAkEA/c8zfmKvY37T +cxcLLwzwsqqH7g2KZGTf9aRmx2ebdW+QKviJJhbdluDgl1TNNFj5vCLznFDRHiqJ +wq0wkZ39cwJBAN9l5v3kdXj21UrurNPdlV0n2GZBt2vblooQC37XHF97r2zM7Ou+ +Lg6MyfJClyguhWL9dxnGbf3btQ0l3KDstxMCQCRaiEqjAfIjWVATzeNIXDWLHXso +b1kf5cA+cwY+vdKdTy4IeUR+Y/DXdvPWDqpf0C11aCVMohdLCn5a5ikFUycCQDhV +K/BuAallJNfmY7JxN87r00fF3ojWMJnT/fIYMFFrkQrwifXQWTDWE76BSDibsosJ +u1TGksnm8zrDh2UVC/0CQFrHTiSl/3DHvWAbOJawGKg46cnlDcAhSyV8Frs8/dlP +7YGG3eqkw++lsghqmFO6mRUTKsBmiiB2wgLGhL5pyYY= +-----END RSA PRIVATE KEY----- Added: mina/sshd/trunk/sshd-sftp/src/test/resources/log4j.properties URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-sftp/src/test/resources/log4j.properties?rev=1434658&view=auto ============================================================================== --- mina/sshd/trunk/sshd-sftp/src/test/resources/log4j.properties (added) +++ mina/sshd/trunk/sshd-sftp/src/test/resources/log4j.properties Thu Jan 17 13:09:51 2013 @@ -0,0 +1,38 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# +# See the License for the specific language governing permissions and +# limitations under the License. +# +# + +# +# The logging properties used during tests.. +# +log4j.rootLogger=DEBUG, stdout +#log4j.logger.org.apache.mina=TRACE +#log4j.logger.org.apache.sshd.common.channel.Window=DEBUG + +# CONSOLE appender +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + +# File appender +log4j.appender.out=org.apache.log4j.FileAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n +log4j.appender.out.file=target/servicemix-test.log +log4j.appender.out.append=true
