Skip to content
Closed
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
9 changes: 5 additions & 4 deletions examples/sftp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ repositories {
}

dependencies {
testImplementation 'com.jcraft:jsch:0.1.55'
testImplementation 'com.github.mwiede:jsch:0.2.24'
testImplementation 'org.testcontainers:testcontainers'
testImplementation 'org.assertj:assertj-core:3.26.3'
testImplementation 'ch.qos.logback:logback-classic:1.3.14'
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.0'
testImplementation 'org.assertj:assertj-core:3.27.3'
testImplementation 'ch.qos.logback:logback-classic:1.5.17'
testImplementation 'org.junit.jupiter:junit-jupiter:5.12.1'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
Comment on lines +12 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not update dependencies

}

test {
Expand Down
13 changes: 11 additions & 2 deletions examples/sftp/src/test/java/org/example/SftpContainerTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.example;

import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.HostKey;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import org.junit.jupiter.api.Test;
Expand All @@ -10,6 +11,7 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -19,19 +21,26 @@ class SftpContainerTest {
@Test
void test() throws Exception {
try (
GenericContainer<?> sftp = new GenericContainer<>("atmoz/sftp:alpine-3.7")
GenericContainer<?> sftp = new GenericContainer<>("jmcombs/sftp:alpine")
.withCopyFileToContainer(
MountableFile.forClasspathResource("testcontainers/", 0777),
"/home/foo/upload/testcontainers"
)
.withCopyFileToContainer(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you create an additional test, please?

MountableFile.forClasspathResource("./ssh_host_ed25519_key", 0400),
"/etc/ssh/ssh_host_ed25519_key"
)
.withExposedPorts(22)
.withCommand("foo:pass:::upload")
) {
sftp.start();
JSch jsch = new JSch();
Session jschSession = jsch.getSession("foo", sftp.getHost(), sftp.getMappedPort(22));
jschSession.setPassword("pass");
jschSession.setConfig("StrictHostKeyChecking", "no");
// hostKeyString is string starting with AAAA from file known_hosts or ssh_host_*_key.pub
String hostKeyString = "AAAAC3NzaC1lZDI1NTE5AAAAINaBuegbLGHOgpXCePq80uY79Xw716jWXAwWjRdFYi53";
HostKey hostKey = new HostKey(sftp.getHost(), Base64.getDecoder().decode(hostKeyString));
jschSession.getHostKeyRepository().add(hostKey, null);
jschSession.connect();
ChannelSftp channel = (ChannelSftp) jschSession.openChannel("sftp");
channel.connect();
Expand Down
7 changes: 7 additions & 0 deletions examples/sftp/src/test/resources/ssh_host_ed25519_key
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACDWgbnoGyxhzoKVwnj6vNLmO/V8O9eo1lwMFo0XRWIudwAAAJixm9bFsZvW
xQAAAAtzc2gtZWQyNTUxOQAAACDWgbnoGyxhzoKVwnj6vNLmO/V8O9eo1lwMFo0XRWIudw
AAAEDUMj/yjokN6yVDNM85skqB2LrPXgyH4FyztT3r3uKBDNaBuegbLGHOgpXCePq80uY7
9Xw716jWXAwWjRdFYi53AAAAD2FhQDIzLTA3MTUzLTAwOQECAwQFBg==
-----END OPENSSH PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINaBuegbLGHOgpXCePq80uY79Xw716jWXAwWjRdFYi53 someone@localhost
Loading