Skip to content

Commit

Permalink
apacheGH-298: Start service in AbstractServerSession
Browse files Browse the repository at this point in the history
Services need to be started. In particular, the connection service
starts its heartbeat, if configured, when started. It was already
noticed in commit e74e204 that the server-side did not start services,
but at that time the effect was not recognized because tests were too
unstable back then. A test for server-side heartbeats was also missing.
  • Loading branch information
tomaswolf committed Dec 26, 2022
1 parent 1091686 commit dc9fa68
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void startService(String name, Buffer buffer) throws Exception {

throw new SshException(SshConstants.SSH2_DISCONNECT_SERVICE_NOT_AVAILABLE, "Unknown service: " + name);
}
currentService.set(service, factory.getName(), false);
currentService.set(service, factory.getName(), true);
}

@Override
Expand Down
24 changes: 24 additions & 0 deletions sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.sshd.client.SshClient;
Expand All @@ -56,9 +57,11 @@
import org.apache.sshd.common.channel.WindowClosedException;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.kex.KexProposalOption;
import org.apache.sshd.common.session.ReservedSessionMessagesHandler;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.session.SessionContext;
import org.apache.sshd.common.session.SessionDisconnectHandler;
import org.apache.sshd.common.session.SessionHeartbeatController.HeartbeatType;
import org.apache.sshd.common.session.SessionListener;
import org.apache.sshd.common.session.helpers.AbstractConnectionService;
import org.apache.sshd.common.session.helpers.AbstractSession;
Expand All @@ -68,6 +71,7 @@
import org.apache.sshd.common.util.MapEntryUtils;
import org.apache.sshd.common.util.MapEntryUtils.NavigableMapBuilder;
import org.apache.sshd.common.util.OsUtils;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.core.CoreModuleProperties;
import org.apache.sshd.deprecated.ClientUserAuthServiceOld;
import org.apache.sshd.server.auth.keyboard.InteractiveChallenge;
Expand Down Expand Up @@ -691,6 +695,26 @@ public void channelStateChanged(Channel channel, String hint) {
}
}

@Test
public void testServerHeartbeat() throws Exception {
sshd.setSessionHeartbeat(HeartbeatType.IGNORE, Duration.ofMillis(500));
sshd.start();
AtomicLong ignoreMessageCount = new AtomicLong(0);
client.setReservedSessionMessagesHandler(new ReservedSessionMessagesHandler() {

@Override
public void handleIgnoreMessage(Session session, Buffer buffer) throws Exception {
ignoreMessageCount.incrementAndGet();
}
});
client.start();
try (ClientSession s = createTestClientSession(sshd)) {
Thread.sleep(2000);
}
long ignoreMessages = ignoreMessageCount.get();
assertTrue("Epected some ignore messages (server-side heartbeat)", ignoreMessages > 0 && ignoreMessages <= 5);
}

@Test
public void testEnvironmentVariablesPropagationToServer() throws Exception {
AtomicReference<Environment> envHolder = new AtomicReference<>(null);
Expand Down

0 comments on commit dc9fa68

Please sign in to comment.