Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for newest sshd libraries #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>

<artifactId>fake-sftp-server-rule</artifactId>
<version>2.1.0-SNAPSHOT</version>
<version>2.2.0</version>
<packaging>jar</packaging>

<name>Fake SFTP Server Rule</name>
Expand Down Expand Up @@ -44,7 +44,12 @@
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
<version>[1,2)</version>
<version>[2.6,)</version>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-sftp</artifactId>
<version>[2.6,)</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -60,7 +65,7 @@
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>[0.1.54]</version>
<version>[0.1.55]</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.github.stefanbirkner.fakesftpserver.rule;

import org.apache.sshd.common.file.FileSystemFactory;
import org.apache.sshd.common.session.SessionContext;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
import org.apache.sshd.sftp.server.SftpSubsystemFactory;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
Expand Down Expand Up @@ -434,7 +436,7 @@ private SshServer startServer(
* In order to use the file system for multiple channels/sessions we
* have to use a file system wrapper whose close() does nothing.
*/
server.setFileSystemFactory(session -> new DoNotClose(fileSystem));
server.setFileSystemFactory(new DoNotCloseFileSystemFactory(fileSystem));
server.start();
this.server = server;
return server;
Expand Down Expand Up @@ -470,6 +472,24 @@ private void verifyThatTestIsRunning(
);
}

private static class DoNotCloseFileSystemFactory implements FileSystemFactory{

final FileSystem fileSystem;
DoNotCloseFileSystemFactory(FileSystem fileSystem){
this.fileSystem = fileSystem;
}

@Override
public Path getUserHomeDir(SessionContext sessionContext) throws IOException {
return null;
}

@Override
public FileSystem createFileSystem(SessionContext sessionContext) throws IOException {
return new DoNotClose(fileSystem);
}
}

private static class DoNotClose extends FileSystem {
final FileSystem fileSystem;

Expand Down