Skip to content

Commit

Permalink
update jsch to com.github.mwiede:jsch:0.2.19
Browse files Browse the repository at this point in the history
  • Loading branch information
anh-bolt committed Aug 14, 2024
1 parent 739ade0 commit 5759c47
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 112 deletions.
80 changes: 38 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ jobs:

- name: Install and start SFTP
run: |
sudo apt install sshpass
sudo apt install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh
sudo sh -c 'echo "PubkeyAcceptedAlgorithms +ssh-rsa" >> /etc/ssh/sshd_config'
sudo systemctl restart ssh
sudo cat /etc/ssh/sshd_config
sudo sh -c 'echo "ChallengeResponseAuthentication no" >> /etc/ssh/sshd_config'
sudo sh -c 'echo "PasswordAuthentication no" >> /etc/ssh/sshd_config'
sudo systemctl try-reload-or-restart ssh
- name: Create a test user account
run: |
Expand All @@ -46,17 +47,17 @@ jobs:
echo "adding user to group ${sshGroup}"
sudo useradd -s /bin/bash -d /home/usr -m -g ${sshGroup} -p $(echo pwd | openssl passwd -1 -stdin) usr
sudo -u usr ssh-keygen -t rsa -N "123456" -f /home/usr/.ssh/sftptest
sudo -u usr sh -c 'cat /home/usr/.ssh/sftptest.pub >> /home/usr/.ssh/authorized_keys'
sudo chmod -R 600 /home/usr/.ssh/
sudo chmod 700 /home/usr/.ssh/authorized_keys
sudo cat /home/usr/.ssh/sftptest.pub
sudo cat /home/usr/.ssh/authorized_keys
sudo cp /home/usr/.ssh/sftptest ${GITHUB_WORKSPACE}/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/sftptest
sudo ssh-keygen -p -P "123456" -N "123456" -m pem -f ${GITHUB_WORKSPACE}/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/sftptest
sudo chown "$(whoami)" ${GITHUB_WORKSPACE}/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/sftptest
ssh-keygen -t rsa -b 4096 -N "123456" -f ~/.ssh/sftptest
chmod -R 700 ~/.ssh/sftptest
chmod 600 ~/.ssh/sftptest.pub
sudo -u usr mkdir /home/usr/.ssh/
sudo cat ~/.ssh/sftptest.pub >> /home/usr/.ssh/authorized_keys
sudo chown -R usr:${sshGroup} /home/usr/.ssh
sudo chmod -R 700 /home/usr/.ssh
sudo chmod 664 /home/usr/.ssh/authorized_keys
cp ~/.ssh/sftptest ${GITHUB_WORKSPACE}/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/sftptest
- name: Setup Maven
uses: stCarolas/setup-maven@v5
with:
Expand All @@ -65,34 +66,29 @@ jobs:
- name: Build with Maven
run: mvn clean verify --batch-mode --fail-at-end ${{ inputs.mvnArgs }}

- name: Print out log
run: |
sudo journalctl -u ssh
sudo cat /var/log/auth.log
# - name: Publish Unit Test Results
# uses: EnricoMi/publish-unit-test-result-action@v2
# if: always()
# with:
# junit_files: |
# */target/*-reports/*.xml
# !*/target/*-reports/failsafe-summary.xml
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
junit_files: |
*/target/*-reports/*.xml
!*/target/*-reports/failsafe-summary.xml
# - name: Archive build artifact
# uses: actions/upload-artifact@v4
# with:
# path: |
# */target/*.iar
# */target/*-[0-9]*.jar
# *product/target/*.zip
- name: Archive build artifact
uses: actions/upload-artifact@v4
with:
path: |
*/target/*.iar
*/target/*-[0-9]*.jar
*product/target/*.zip
# - name: Archive test reports
# uses: actions/upload-artifact@v4
# if: failure()
# with:
# name: test-reports
# retention-days: 5
# path: |
# */target/testEngineOut.log
# */target/selenide/*
# */target/ivyEngine/deploy/*/*.deploymentLog
- name: Archive test reports
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-reports
retention-days: 5
path: |
*/target/testEngineOut.log
*/target/selenide/*
*/target/ivyEngine/deploy/*/*.deploymentLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Locale;

import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;

Expand All @@ -23,9 +21,8 @@
import ch.ivyteam.ivy.bpm.engine.client.element.BpmProcess;
import ch.ivyteam.ivy.bpm.engine.client.sub.SubProcessCallResult;
import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest;
import ch.ivyteam.ivy.cm.ContentObjectValue;
import ch.ivyteam.ivy.cm.IContentObject;
import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.scripting.objects.File;


/**
Expand All @@ -52,17 +49,20 @@ public class SftpProcessSSHTest {
private static final long TEST_FILE_SIZE = 207569L;


@Test
@Order(1)
public void callOpenConnection(BpmClient bpmClient) throws Exception {
@BeforeAll
public static void init() throws Exception {
String prefix = "com_axonivy_connector_sftp_server_";
Ivy.var().set(prefix+"auth", "ssh");
Ivy.var().set(prefix+"password", "");

String keyString = Files.readString(Paths.get(getClass().getResource("sftptest").toURI()));
String keyString = Files.readString(Paths.get(SftpProcessSSHTest.class.getResource("sftptest").toURI()));
Ivy.var().set(prefix+"secret_sshkey", keyString);
Ivy.var().set(prefix+"secret_sshpassphrase", "123456");

}

@Test
@Order(1)
public void callOpenConnection(BpmClient bpmClient) throws Exception {
BpmElement startable = TEST_HELPER_PROCESS.elementName("openConnection()");

SubProcessCallResult result = bpmClient.start()
Expand All @@ -71,74 +71,74 @@ public void callOpenConnection(BpmClient bpmClient) throws Exception {
.subResult();

SftpClientService sftpClient = result.param("sftpClient", SftpClientService.class);
// assertThat(sftpClient).isNotNull();
assertThat(sftpClient).isNotNull();
if (sftpClient != null) {
sftpClient.close();
}
}

// @Test
// @Order(2)
// public void callUploadFile(BpmClient bpmClient) {
// InputStream fileToBeUploaded = getClass().getResourceAsStream(TEST_FILE_NAME);
@Test
@Order(2)
public void callUploadFile(BpmClient bpmClient) {
InputStream fileToBeUploaded = getClass().getResourceAsStream(TEST_FILE_NAME);

// BpmElement startable = TEST_UPLOAD_FILE_PROCESS.elementName("uploadFile(InputStream,String)");
BpmElement startable = TEST_UPLOAD_FILE_PROCESS.elementName("uploadFile(InputStream,String)");

// SubProcessCallResult result = bpmClient.start()
// .subProcess(startable)
// .execute(fileToBeUploaded, TEST_FILE_NAME) // Callable sub process input arguments
// .subResult();
SubProcessCallResult result = bpmClient.start()
.subProcess(startable)
.execute(fileToBeUploaded, TEST_FILE_NAME) // Callable sub process input arguments
.subResult();

// Boolean isSuccess = result.param("isSuccess", Boolean.class);
// assertThat(isSuccess).isTrue();
// }
Boolean isSuccess = result.param("isSuccess", Boolean.class);
assertThat(isSuccess).isTrue();
}

// @Test
// @Order(3)
// public void callUploadIvyFile(BpmClient bpmClient) throws IOException {
// InputStream fileToBeUploaded = getClass().getResourceAsStream(TEST_FILE_NAME);
// java.io.File javaFile = new java.io.File(TEST_FILE_NAME);
// FileUtils.copyInputStreamToFile(fileToBeUploaded, javaFile);
@Test
@Order(3)
public void callUploadIvyFile(BpmClient bpmClient) throws IOException {
InputStream fileToBeUploaded = getClass().getResourceAsStream(TEST_FILE_NAME);
java.io.File javaFile = new java.io.File(TEST_FILE_NAME);
FileUtils.copyInputStreamToFile(fileToBeUploaded, javaFile);

// File ivyFile = new File(TEST_FILE_NAME, true);
// FileUtils.moveFile(javaFile, ivyFile.getJavaFile());
File ivyFile = new File(TEST_FILE_NAME, true);
FileUtils.moveFile(javaFile, ivyFile.getJavaFile());

// BpmElement startable = TEST_UPLOAD_FILE_PROCESS.elementName("uploadFile(File)");
BpmElement startable = TEST_UPLOAD_FILE_PROCESS.elementName("uploadFile(File)");

// SubProcessCallResult result = bpmClient.start()
// .subProcess(startable)
// .execute(ivyFile) // Callable sub process input arguments
// .subResult();
SubProcessCallResult result = bpmClient.start()
.subProcess(startable)
.execute(ivyFile) // Callable sub process input arguments
.subResult();

// Boolean isSuccess = result.param("isSuccess", Boolean.class);
// assertThat(isSuccess).isTrue();
// }
Boolean isSuccess = result.param("isSuccess", Boolean.class);
assertThat(isSuccess).isTrue();
}

// @Test
// @Order(4)
// public void callListAllFiles(BpmClient bpmClient) {
// BpmElement startable = TEST_DOWNLOAD_FILE_PROCESS.elementName("listAllFiles(String)");
@Test
@Order(4)
public void callListAllFiles(BpmClient bpmClient) {
BpmElement startable = TEST_DOWNLOAD_FILE_PROCESS.elementName("listAllFiles(String)");

// SubProcessCallResult result = bpmClient.start()
// .subProcess(startable)
// .execute(".") // Callable sub process input arguments
// .subResult();
// List<FileData> listFiles = result.param("listFiles", List.class);
// assertThat(listFiles.size()).isGreaterThanOrEqualTo(1);
// assertThat(listFiles).anyMatch(f -> f.getName().equals(TEST_FILE_NAME));
// }
SubProcessCallResult result = bpmClient.start()
.subProcess(startable)
.execute(".") // Callable sub process input arguments
.subResult();
List<FileData> listFiles = result.param("listFiles", List.class);
assertThat(listFiles.size()).isGreaterThanOrEqualTo(1);
assertThat(listFiles).anyMatch(f -> f.getName().equals(TEST_FILE_NAME));
}

// @Test
// @Order(5)
// public void callDownloadFile(BpmClient bpmClient) {
// BpmElement startable = TEST_DOWNLOAD_FILE_PROCESS.elementName("downloadFile(String)");
@Test
@Order(5)
public void callDownloadFile(BpmClient bpmClient) {
BpmElement startable = TEST_DOWNLOAD_FILE_PROCESS.elementName("downloadFile(String)");

// SubProcessCallResult result = bpmClient.start()
// .subProcess(startable)
// .execute(TEST_FILE_NAME) // Callable sub process input arguments
// .subResult();
// java.io.File downloadedFile = result.param("toFile", java.io.File.class);
// assertThat(downloadedFile.length()).isEqualTo(TEST_FILE_SIZE);
// assertThat(downloadedFile.getName()).isEqualTo(TEST_FILE_NAME);
// }
SubProcessCallResult result = bpmClient.start()
.subProcess(startable)
.execute(TEST_FILE_NAME) // Callable sub process input arguments
.subResult();
java.io.File downloadedFile = result.param("toFile", java.io.File.class);
assertThat(downloadedFile.length()).isEqualTo(TEST_FILE_SIZE);
assertThat(downloadedFile.getName()).isEqualTo(TEST_FILE_NAME);
}
}
9 changes: 4 additions & 5 deletions sftp-connector/config/variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ Variables:
username: 'usr'

# Auth type to the SFPT server: password OR ssh
auth: 'password'
auth: 'ssh'

# The password to the SFTP server
# [password]
password: pwd
password: ''

# The ssh key string to SFTP server
# [secret private key]
secret_sshkey: ''

secret.sshkey: ''
# The ssh key passphrase
secret_sshpassphrase: ''
secret.sshpassphrase: ''
4 changes: 2 additions & 2 deletions sftp-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</properties>
<dependencies>
<dependency>
<groupId>com.jcraft</groupId>
<groupId>com.github.mwiede</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
<version>0.2.19</version>
</dependency>
</dependencies>
<pluginRepositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -56,13 +57,15 @@ public class SftpClientService implements AutoCloseable {
*/
public SftpClientService(String host, int port, String username, String authType, String password, String keyString, String passphrase) throws IOException {
System.out.println(keyString);
System.out.println(passphrase);
try {
JSch jsch = new JSch();

session = jsch.getSession(username, host, port);
if (StringUtils.isEmpty(authType) || PASSWORD.equalsIgnoreCase(authType)) {
session.setPassword(password);
} else {
session.setConfig("PreferredAuthentications", "publickey");
jsch.addIdentity(null, keyString.getBytes(), null, passphrase.getBytes());
}

Expand Down

0 comments on commit 5759c47

Please sign in to comment.