This is an automated email from the ASF dual-hosted git repository.

twolf pushed a commit to branch dev_3.0
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit a1b2a10e33c9cc7b1b7e497c1b9a4adab4212a61
Merge: a0d5e02dc f411cadb6
Author: Thomas Wolf <tw...@apache.org>
AuthorDate: Mon Apr 28 21:53:23 2025 +0200

    Merge branch 'master' into 3.0.0

 pom.xml                                            |   4 +-
 .../apache/sshd/client/session/ClientSession.java  | 104 +++++++++++++++++++--
 .../sshd/client/session/ClientSessionTest.java     |  64 +++++++++++++
 .../sshd/common/forward/PortForwardingTest.java    |  25 +++--
 4 files changed, 180 insertions(+), 17 deletions(-)

diff --cc pom.xml
index b05fcad83,d1a2fa62b..65fd7bc24
--- a/pom.xml
+++ b/pom.xml
@@@ -119,8 -118,8 +119,8 @@@
          <maven.archiver.version>3.6.3</maven.archiver.version>
          <plexus.archiver.version>4.10.0</plexus.archiver.version>
          <!-- See https://pmd.github.io/ for available latest version -->
-         <pmd.version>7.12.0</pmd.version>
+         <pmd.version>7.13.0</pmd.version>
 -
 +        <japicmp.version>0.23.1</japicmp.version>
          <sshd.tests.timeout.factor>1.0</sshd.tests.timeout.factor>
          <sshd.tests.rerun.count>2</sshd.tests.rerun.count>
  
diff --cc 
sshd-core/src/test/java/org/apache/sshd/client/session/ClientSessionTest.java
index c643f83c4,98885e4a6..211f87c8d
--- 
a/sshd-core/src/test/java/org/apache/sshd/client/session/ClientSessionTest.java
+++ 
b/sshd-core/src/test/java/org/apache/sshd/client/session/ClientSessionTest.java
@@@ -235,12 -236,77 +237,74 @@@ class ClientSessionTest extends BaseTes
          assertEquals(Integer.toString(expectedErrorCode), actualErrorMessage, 
"Mismatched captured error code");
      }
  
+     @Test
+     void executeCommandMethodWithConfigurableTimeout() throws Exception {
+         String expectedCommand = getCurrentTestName() + "-CMD";
+         String expectedResponse = getCurrentTestName() + "-RSP";
+         Duration timeout = Duration.ofMillis(10000L);
+         sshd.setCommandFactory((session, command) -> new 
CommandExecutionHelper(command) {
+             private boolean cmdProcessed;
+ 
+             @Override
+             protected boolean handleCommandLine(String command) throws 
Exception {
+                 assertEquals(expectedCommand, command, "Mismatched incoming 
command");
+                 assertFalse(cmdProcessed, "Duplicated command call");
+                 OutputStream stdout = getOutputStream();
+                 Thread.sleep(500L);
+                 
stdout.write(expectedResponse.getBytes(StandardCharsets.US_ASCII));
+                 stdout.flush();
+                 cmdProcessed = true;
+                 return false;
+             }
+         });
+ 
+         try (ClientSession session = client.connect(getCurrentTestName(), 
TEST_LOCALHOST, port)
 -                .verify(CONNECT_TIMEOUT)
 -                .getSession()) {
++                .verify(CONNECT_TIMEOUT).getSession()) {
+             session.addPasswordIdentity(getCurrentTestName());
+             session.auth().verify(AUTH_TIMEOUT);
+ 
+             // NOTE !!! The LF is only because we are using a buffered reader 
on the server end to read the command
+             String actualResponse = 
session.executeRemoteCommand(expectedCommand + "\n", timeout);
+             assertEquals(expectedResponse, actualResponse, "Mismatched 
command response");
+         }
+     }
+ 
+     @Test
+     void exceptionThrownOnExecuteCommandTimeout() throws Exception {
+         String expectedCommand = getCurrentTestName() + "-CMD";
+         Duration timeout = Duration.ofMillis(500L);
+ 
+         sshd.setCommandFactory((session, command) -> new 
CommandExecutionHelper(command) {
+             private boolean cmdProcessed;
+ 
+             @Override
+             protected boolean handleCommandLine(String command) throws 
Exception {
+                 assertEquals(expectedCommand, command, "Mismatched incoming 
command");
+                 assertFalse(cmdProcessed, "Duplicated command call");
+                 Thread.sleep(timeout.plusMillis(200L).toMillis());
+                 OutputStream stdout = getOutputStream();
+                 stdout.write(command.getBytes(StandardCharsets.US_ASCII));
+                 stdout.flush();
+                 cmdProcessed = true;
+                 return false;
+             }
+         });
+ 
+         try (ClientSession session = client.connect(getCurrentTestName(), 
TEST_LOCALHOST, port)
 -                .verify(CONNECT_TIMEOUT)
 -                .getSession()) {
++                .verify(CONNECT_TIMEOUT).getSession()) {
+             session.addPasswordIdentity(getCurrentTestName());
+             session.auth().verify(AUTH_TIMEOUT);
+ 
 -            assertThrows(SocketTimeoutException.class, () -> {
 -                session.executeRemoteCommand(expectedCommand + "\n", timeout);
 -            });
++            assertThrows(SocketTimeoutException.class, () -> 
session.executeRemoteCommand(expectedCommand + "\n", timeout));
+         }
+     }
+ 
 -    // see SSHD-859
 +    // see SSHD-859 and GH-728
      @Test
      void connectionContextPropagation() throws Exception {
 -        AttributeRepository expected = AttributeRepository.ofKeyValuePair(
 -                new AttributeKey<String>(), getCurrentTestName());
 +        String myName = getCurrentTestName();
 +        AttributeKey<String> myAttribute = new AttributeKey<String>();
 +        AttributeRepository expected = 
AttributeRepository.ofKeyValuePair(myAttribute, myName);
          AtomicInteger creationCount = new AtomicInteger(0);
          SessionListener listener = new SessionListener() {
              @Override

Reply via email to