Skip to content

Commit

Permalink
Test with Filezilla docker and external server for SSL Session reuse …
Browse files Browse the repository at this point in the history
…(with SNI) in passive mode.
  • Loading branch information
MGuich committed Jan 31, 2025
1 parent 8c1bb99 commit ae5d7a9
Show file tree
Hide file tree
Showing 10 changed files with 950 additions and 140 deletions.
138 changes: 103 additions & 35 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@ Supported protocols include Echo, Finger, FTP, NNTP, NTP, POP3(S), SMTP(S), Teln
</site>
</distributionManagement>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.32</version>
<scope>test</scope>
</dependency>
<!--<dependency>
<groupId>org.burningwave</groupId>
<artifactId>tools</artifactId>
<version>0.26.2</version>
<scope>test</scope>
</dependency>-->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bctls-debug-jdk18on</artifactId>
<version>1.79</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down Expand Up @@ -204,16 +228,47 @@ Supported protocols include Echo, Finger, FTP, NNTP, NTP, POP3(S), SMTP(S), Teln
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skipUnitTests}</skipTests>
<excludes>
<exclude>**/*FunctionalTest.java</exclude>
<exclude>**/POP3*Test.java</exclude>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*IT.java</exclude>
</excludes>
<environmentVariables>
<TRACE_CALLS>${commons.net.trace_calls}</TRACE_CALLS>
<ADD_LISTENER>${commons.net.add_listener}</ADD_LISTENER>
</environmentVariables>
</configuration>
</plugin>
<!-- Plugin Failsafe for integration-tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<!-- Lancer avant la phase verify -->
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify-tests</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- Exécute uniquement les classes commençant ou terminant par IT -->
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
Expand Down Expand Up @@ -385,41 +440,54 @@ Supported protocols include Echo, Finger, FTP, NNTP, NTP, POP3(S), SMTP(S), Teln
</configuration>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.38.1</version>
<configuration>
<images>
<image>
<name>filezilla-server</name>
<build>
<dockerFile>${project.basedir}/Dockerfile</dockerFile>
</build>
<run>
<ports>
<port>21:21</port>
</ports>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>start-docker-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-docker-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.45.1</version>
<configuration>
<images>
<image>
<name>mguichar/filezilla-server</name>
<run>
<ports>
<port>21:21</port>
<port>14148:14148</port>
<port>49152:49152</port>
<port>49153:49153</port>
<port>49154:49154</port>
<port>49155:49155</port>
<port>49156:49156</port>
<port>49157:49157</port>
<port>49158:49158</port>
<port>49159:49159</port>
<port>49160:49160</port>
</ports>
<volumes>
<bind>
<volume>target/test-classes/org/apache/commons/net/test-data:/usr/test</volume>
<volume>target/test-classes/org/apache/commons/net/filezillaserver/conf:/opt/filezilla-server/etc</volume>
</bind>
</volumes>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>start-docker-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-docker-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
Expand Down
82 changes: 2 additions & 80 deletions src/test/java/org/apache/commons/net/ftp/AbstractFtpsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import java.net.URL;
import java.time.Duration;
import java.util.Properties;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.commons.net.PrintCommandListener;
import org.apache.ftpserver.FtpServer;
Expand Down Expand Up @@ -61,7 +56,6 @@
public abstract class AbstractFtpsTest {

private static int SocketPort;
private static int FZSocketPort = -1;
private static FtpServer EmbeddedFtpServer;
protected static final boolean IMPLICIT = false;
protected static final long TEST_TIMEOUT = 10000; // individual test timeout
Expand All @@ -78,15 +72,6 @@ protected static String getTestHomeDirectory(final String defaultHome) {
return System.getProperty("test.basedir", defaultHome);
}

protected static void initFZServer(String fzPropertiesResource) throws IOException {
final URL fzPropsResource = ClassLoader.getSystemClassLoader().getResource(fzPropertiesResource);
Properties prop = new Properties();
try (InputStream in = fzPropsResource.openStream()) {
prop.load(in);
}
FZSocketPort = Integer.parseInt(prop.getProperty("filezillaserver.port"));
}

/**
* Creates and starts an embedded Apache MINA FTP Server.
*
Expand All @@ -96,8 +81,8 @@ protected static void initFZServer(String fzPropertiesResource) throws IOExcepti
* @param defaultHome default home folder
* @throws FtpException Thrown when the FTP classes cannot fulfill a request.
*/
protected synchronized static void setupServer(final boolean implicit, final String userPropertiesResource, final String serverJksResourceResource,
final String defaultHome) throws FtpException {
protected synchronized static void setupServer(final boolean implicit, final String userPropertiesResource, final String serverJksResourceResource, final String defaultHome)
throws FtpException {
if (EmbeddedFtpServer != null) {
return;
}
Expand Down Expand Up @@ -211,57 +196,6 @@ protected FTPSClient loginClient() throws SocketException, IOException {
return client;
}

protected FTPSClient loginClientToFZ() throws SocketException, IOException {
trace(">>loginClientToFZ");
assertNotEquals(FZSocketPort, -1, "initFZServer not called");
final FTPSClient client = new FTPSClient(IMPLICIT);
if (ADD_LISTENER) {
client.addProtocolCommandListener(new PrintCommandListener(System.err));
}
//
client.setControlKeepAliveReplyTimeout(null);
assertEquals(0, client.getControlKeepAliveReplyTimeoutDuration().getSeconds());
client.setControlKeepAliveReplyTimeout(Duration.ofSeconds(60));
assertEquals(60, client.getControlKeepAliveReplyTimeoutDuration().getSeconds());
//
client.setControlKeepAliveTimeout(null);
assertEquals(0, client.getControlKeepAliveTimeoutDuration().getSeconds());
client.setControlKeepAliveTimeout(Duration.ofSeconds(61));
assertEquals(61, client.getControlKeepAliveTimeoutDuration().getSeconds());
//
client.setDataTimeout(null);
assertEquals(0, client.getDataTimeout().getSeconds());
client.setDataTimeout(Duration.ofSeconds(62));
assertEquals(62, client.getDataTimeout().getSeconds());
//
client.setEndpointCheckingEnabled(endpointCheckingEnabled);
client.connect("localhost", FZSocketPort);
//
assertClientCode(client);
assertEquals(FZSocketPort, client.getRemotePort());
//
try {
// HACK: Without this sleep, the user command sometimes does not reach the ftpserver
// This only seems to affect GitHub builds, and only Java 11+
Thread.sleep(200); // 100 seems to be not always enough
} catch (final InterruptedException ignore) {
// ignore
}
assertTrue(client.login("test", "test"));
assertClientCode(client);
//
client.setFileType(FTP.BINARY_FILE_TYPE);
assertClientCode(client);
//
client.execPBSZ(0);
assertClientCode(client);
//
client.execPROT("P");
assertClientCode(client);
trace("<<loginClientToFZ");
return client;
}

protected void retrieveFile(final String pathname) throws SocketException, IOException {
final FTPSClient client = loginClient();
try {
Expand All @@ -273,16 +207,4 @@ protected void retrieveFile(final String pathname) throws SocketException, IOExc
client.disconnect();
}
}

protected void retrieveFileOnFZ(final String pathname) throws SocketException, IOException {
final FTPSClient client = loginClientToFZ();
try {
// Do it twice.
// Just testing that we are not getting an SSL error (the file MUST be present).
assertTrue(pathname, client.retrieveFile(pathname, NullOutputStream.INSTANCE));
// assertTrue(pathname, client.retrieveFile(pathname, NullOutputStream.INSTANCE));
} finally {
client.disconnect();
}
}
}
Loading

0 comments on commit ae5d7a9

Please sign in to comment.