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

embedded-sftp-server #20

Open
silkentrance opened this issue Aug 18, 2018 · 0 comments
Open

embedded-sftp-server #20

silkentrance opened this issue Aug 18, 2018 · 0 comments

Comments

@silkentrance
Copy link
Member

silkentrance commented Aug 18, 2018

Feature Request

Summary

For testing purposes, we need an EmbeddedSftpServer.

Description

The EmbeddedSftpServer will be based on the Apache Mina project. It will support only a fraction of what Apache Mina provides, considering that we, for now, only need to make sure that our components under test cut will be able to transfer the files via either Spring SFTP integration or just using JSch directly.

We need to wrap Apache Mina SSHD so that only the SFTP relevant parts of the interface are being exposed.

For access restricted scenarios, the EmbeddedSftpServer should support readonly, write-only, and arbitrary access configurations and interfaces thereof.

The system should also allow the user to clean up between test cases or to prepare the "remote" with (existing) fixtures.

  • For read-only scenarios, the fixtures must be transferred up front, or the sftp server instance must be configured so that it will point to the correct location in the filesystem, i.e. where the fixtures exist.

  • For write-only scenarios, the user must be able to retrieve the data from the "remote" in order to assert whether the transferred data matches the expected data.

  • Arbitrary access scenarios represent the combination of the above.

There will be both a shared library that can be used stand alone and also an env-provider for the junit-env-extension.

Server port, dynamically assigned via the SocketUtils, and host, which should always be localhost, need to be exposed by these interfaces. The user can then configure his or her cut accordingly.

Provisioning Demarcation

For the purpose of demarcation and subsequently parameter injection we will introduce the SftpEnvProvided annotation. The annotation can only be used on @BeforeAll annotated (static) method parameters.

The annotation will allow the user to have multiple instances of the EmbeddedSftpServer, all configured differently, again allowing the user to run multiple different test scenarios, e.g.

@BeforeAll
public [static] void setUp(@SftpEnvProvided(id=""[, rootDirectory="..."][, defaultAccessMode=RW|RO|WO|DENY][, ...]) sftpServer) {}

where the optional rootDirectory can point to either a directory in the filesystem or a class path resource which is a directory.

Verification

For the purpose of verification, the user can switch the embedded sftp server instance's mode to an arbitrary access mode, in order to be able to fetch data from the server, e.g.

@Test
public void testSomething() throws Exception {

   sftpServer.wo(); // enable write-only mode
   cut.doSomething();

   sftpServer.rw(); // enable rw mode
   InputStream toVerify = sftpServer.get(PATH);
   ...
}

or when running a failure scenario, where the remote will reject all connection attempts

@Test
public void testSomethingFailing() throws Exception {

   sftpServer.denyAll();
   cut.doSomething();
   ...
}

Integrating the mina server with class path resources might be a little bit difficult, though, since it uses its own VirtualFileSystem abstraction.

And so on.

All server instances will be reset to their default modes before each test is run.

Integration with file-assertions

Since all data resides locally in either a user specific root folder or a standard temporary root folder, the sftp server interface must provide for a getter for the root directory, returning a Path object, That way, file-assertions can be used to test whether a file exists or whether its content matches the expected content.

Simulating Delivery PickUp and Rejection Scenarios

Currently out of scope.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

1 participant