diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a3dc5a..a86292f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,10 @@ jobs: sudo apt install openssh-server sudo sh -c 'echo "ChallengeResponseAuthentication no" >> /etc/ssh/sshd_config' sudo sh -c 'echo "PasswordAuthentication no" >> /etc/ssh/sshd_config' + sudo sh -c 'echo "\nMatch User usr" >> /etc/ssh/sshd_config' + sudo sh -c 'echo "\tPasswordAuthentication yes" >> /etc/ssh/sshd_config' + sudo sh -c 'echo "\nMatch User All" >> /etc/ssh/sshd_config' + sudo sh -c 'echo "\tPasswordAuthentication no" >> /etc/ssh/sshd_config' sudo systemctl enable ssh sudo systemctl start ssh @@ -44,18 +48,22 @@ jobs: sshGroup=${sshGroupRaw%:x*} 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 + + echo "adding user2ssh to group ${sshGroup}" + sudo useradd -s /bin/bash -d /home/usr2ssh -m -g ${sshGroup} -p $(echo pwd | openssl passwd -1 -stdin) usr2ssh 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 + sudo -u usr2ssh mkdir /home/usr2ssh/.ssh/ + sudo cat ~/.ssh/sftptest.pub >> /home/usr2ssh/.ssh/authorized_keys + sudo chown -R usr2ssh:${sshGroup} /home/usr2ssh/.ssh + sudo chmod go-w /home/usr2ssh + sudo chmod -R 700 /home/usr2ssh/.ssh + sudo chmod 600 /home/usr2ssh/.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: @@ -63,7 +71,7 @@ jobs: - name: Build with Maven run: mvn clean verify --batch-mode --fail-at-end ${{ inputs.mvnArgs }} - + - name: Publish Unit Test Results uses: EnricoMi/publish-unit-test-result-action@v2 if: always() @@ -71,7 +79,7 @@ jobs: junit_files: | */target/*-reports/*.xml !*/target/*-reports/failsafe-summary.xml - + - name: Archive build artifact uses: actions/upload-artifact@v4 with: diff --git a/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/SftpMultiConnectionTest.java b/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/SftpMultiConnectionTest.java new file mode 100644 index 0000000..26f3b19 --- /dev/null +++ b/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/SftpMultiConnectionTest.java @@ -0,0 +1,53 @@ +package com.axonivy.connector.sftp.test; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.axonivy.connector.sftp.service.SftpClientService; + +import ch.ivyteam.ivy.bpm.engine.client.BpmClient; +import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; +import ch.ivyteam.ivy.environment.Ivy; + + +/** + * This SftpMultiConnectionTest creates 2 sFTP connections + */ +@IvyProcessTest(enableWebServer = true) +public class SftpMultiConnectionTest { + + private static final String PREFIX = "com.axonivy.connector.sftp.server."; + + private static final String SFTP_NAME = "dummy"; + private static final String SFTP_SSH_NAME = "dummy_ssh"; + private static final String SFTP_SSH_NAME_VAR = SFTP_SSH_NAME + "."; + + @BeforeEach + public void preInit() throws Exception { + // set-up variables for sftp connector with SSH key pair + Ivy.var().set(PREFIX+SFTP_SSH_NAME_VAR+"host", "localhost"); + Ivy.var().set(PREFIX+SFTP_SSH_NAME_VAR+"username", "usr2ssh"); + Ivy.var().set(PREFIX+SFTP_SSH_NAME_VAR+"auth", "ssh"); + Ivy.var().set(PREFIX+SFTP_SSH_NAME_VAR+"password", ""); + String keyString = Files.readString(Paths.get(SftpProcessSSHTest.class.getResource("sftptest").toURI())); + Ivy.var().set(PREFIX+SFTP_SSH_NAME_VAR+"secret.sshkey", keyString); + Ivy.var().set(PREFIX+SFTP_SSH_NAME_VAR+"secret.sshpassphrase", "123456"); + } + + @Test + public void callOpenConnection(BpmClient bpmClient) throws IOException { + SftpClientService sftpClient = new SftpClientService(SFTP_NAME); + SftpClientService sftpSSHClient = new SftpClientService(SFTP_SSH_NAME); + + assertThat(sftpClient).isNotNull(); + assertThat(sftpSSHClient).isNotNull(); + sftpClient.close(); + sftpSSHClient.close(); + } +} diff --git a/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/SftpProcessSSHTest.java b/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/SftpProcessSSHTest.java index 3620703..c38256f 100644 --- a/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/SftpProcessSSHTest.java +++ b/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/SftpProcessSSHTest.java @@ -54,7 +54,7 @@ public class SftpProcessSSHTest { @BeforeAll public static void init() throws Exception { - + Ivy.var().set(PREFIX+TEST_SFTP_NAME_VAR+"username", "usr2ssh"); Ivy.var().set(PREFIX+TEST_SFTP_NAME_VAR+"auth", "ssh"); Ivy.var().set(PREFIX+TEST_SFTP_NAME_VAR+"password", ""); diff --git a/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/SftpProcessTest.java b/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/SftpProcessTest.java index e82be13..ad58ef5 100644 --- a/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/SftpProcessTest.java +++ b/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/SftpProcessTest.java @@ -7,7 +7,6 @@ import java.util.List; import org.apache.commons.io.FileUtils; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -36,7 +35,6 @@ *

*/ @IvyProcessTest(enableWebServer = true) -@Disabled public class SftpProcessTest { private static final BpmProcess TEST_HELPER_PROCESS = BpmProcess.path("Sftp/SftpHelper");