-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FTP: Add KeyManager and TrustManager usage test
- Loading branch information
1 parent
1c01190
commit 9e76ab6
Showing
2 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
ftp/src/test/java/akka/stream/alpakka/ftp/FtpsWithTrustAndKeyManagersStageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (C) 2016-2020 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package akka.stream.alpakka.ftp; | ||
|
||
import nl.altindag.ssl.util.PemUtils; | ||
import akka.NotUsed; | ||
import akka.stream.IOResult; | ||
import akka.stream.alpakka.ftp.javadsl.Ftps; | ||
import akka.stream.alpakka.testkit.javadsl.LogCapturingJunit4; | ||
import akka.stream.javadsl.Sink; | ||
import akka.stream.javadsl.Source; | ||
import akka.util.ByteString; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.InetAddress; | ||
import java.net.InetSocketAddress; | ||
import javax.net.ssl.KeyManager; | ||
import javax.net.ssl.TrustManager; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.function.Function; | ||
|
||
public class FtpsWithTrustAndKeyManagersStageTest extends BaseFtpSupport | ||
implements CommonFtpStageTest { | ||
private static final String PEM_PATH = "ftpd/pure-ftpd.pem"; | ||
|
||
@Rule public final LogCapturingJunit4 logCapturing = new LogCapturingJunit4(); | ||
|
||
@Test | ||
public void listFiles() throws Exception { | ||
CommonFtpStageTest.super.listFiles(); | ||
} | ||
|
||
public Source<FtpFile, NotUsed> getBrowserSource(String basePath) throws Exception { | ||
return Ftps.ls(basePath, settings()); | ||
} | ||
|
||
public Source<ByteString, CompletionStage<IOResult>> getIOSource(String path) throws Exception { | ||
return Ftps.fromPath(path, settings()); | ||
} | ||
|
||
public Sink<ByteString, CompletionStage<IOResult>> getIOSink(String path) throws Exception { | ||
return Ftps.toPath(path, settings()); | ||
} | ||
|
||
public Sink<FtpFile, CompletionStage<IOResult>> getRemoveSink() throws Exception { | ||
return Ftps.remove(settings()); | ||
} | ||
|
||
public Sink<FtpFile, CompletionStage<IOResult>> getMoveSink( | ||
Function<FtpFile, String> destinationPath) throws Exception { | ||
return Ftps.move(destinationPath, settings()); | ||
} | ||
|
||
private FtpsSettings settings() throws Exception { | ||
return FtpsSettings.create(InetAddress.getByName(HOSTNAME)) | ||
.withPort(PORT) | ||
.withCredentials(CREDENTIALS) | ||
.withBinary(false) | ||
.withPassiveMode(true) | ||
.withTrustManager(trustManager()) | ||
.withKeyManager(keyManager()); | ||
} | ||
|
||
private KeyManager keyManager() throws IOException { | ||
try (InputStream stream = classLoader().getResourceAsStream(PEM_PATH)) { | ||
return PemUtils.loadIdentityMaterial(stream); | ||
} | ||
} | ||
|
||
private TrustManager trustManager() throws IOException { | ||
try (InputStream stream = classLoader().getResourceAsStream(PEM_PATH)) { | ||
return PemUtils.loadTrustMaterial(stream); | ||
} | ||
} | ||
|
||
private ClassLoader classLoader() { | ||
return FtpsWithTrustAndKeyManagersStageTest.class.getClassLoader(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters