-
Notifications
You must be signed in to change notification settings - Fork 1.1k
GH-8581: Do not overwrite configuration of external provided SshClient #8584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,9 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.apache.sshd.client.SshClient; | ||
import org.apache.sshd.client.auth.password.PasswordIdentityProvider; | ||
import org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier; | ||
import org.apache.sshd.common.SshException; | ||
import org.apache.sshd.server.SshServer; | ||
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; | ||
|
@@ -35,10 +38,12 @@ | |
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.fail; | ||
import static org.awaitility.Awaitility.await; | ||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
/** | ||
* @author Gary Russell | ||
* @author Artem Bilan | ||
* @author Auke Zaaiman | ||
* | ||
* @since 3.0.2 | ||
*/ | ||
|
@@ -126,4 +131,25 @@ public void concurrentGetSessionDoesntCauseFailure() throws IOException { | |
} | ||
} | ||
|
||
@Test | ||
void externallyProvidedSshClientShouldNotHaveItsConfigurationOverwritten() throws IOException { | ||
try (SshServer server = SshServer.setUpDefaultServer()) { | ||
server.setPasswordAuthenticator((arg0, arg1, arg2) -> true); | ||
server.setPort(0); | ||
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser").toPath())); | ||
server.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory())); | ||
server.start(); | ||
|
||
SshClient externalClient = SshClient.setUpDefaultClient(); | ||
externalClient.setServerKeyVerifier(AcceptAllServerKeyVerifier.INSTANCE); | ||
externalClient.setPasswordIdentityProvider(PasswordIdentityProvider.wrapPasswords("pass")); | ||
|
||
DefaultSftpSessionFactory sftpSessionFactory = new DefaultSftpSessionFactory(externalClient, false); | ||
sftpSessionFactory.setHost("localhost"); | ||
sftpSessionFactory.setPort(server.getPort()); | ||
sftpSessionFactory.setUser("user"); | ||
|
||
assertDoesNotThrow(() -> sftpSessionFactory.getSession().connect()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that this test really reflects what we would expect from its name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have thought about using some mock. What you would want is something like this: @Test
void externallyProvidedSshClientShouldNotHaveItsConfigurationOverwritten() throws IOException {
SshClient externalClient = spy(SshClient.setUpDefaultClient());
DefaultSftpSessionFactory sftpSessionFactory = new DefaultSftpSessionFactory(externalClient, false);
sftpSessionFactory.setHost("localhost");
sftpSessionFactory.setUser("user");
assertThatNoException().isThrownBy(() -> sftpSessionFactory.getSession());
verify(externalClient, never()).setServerKeyVerifier(any());
verify(externalClient, never()).setPasswordIdentityProvider(any());
verify(externalClient, never()).setKeyIdentityProvider(any());
verify(externalClient, never()).setUserInteraction(any());
} But that would raise an exception:
I doubt it would be wise to mock the better part of the calls which happen in the init towards the Any suggestions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah... I see: the integration with that |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer to use assertion from AsssertJ library. See
assertThatNoException()
instead of JUnit's one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I replaced it.