-
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
Conversation
…ovided SshClient Fixes spring-projects#8581
@@ -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; |
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.
Error: eckstyle] [ERROR] /home/runner/work/spring-integration/spring-integration/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/session/SftpSessionFactoryTests.java:41:47: Using a static member import should be avoided - org.junit.jupiter.api.Assertions.assertDoesNotThrow. [AvoidStaticImport]
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.
sftpSessionFactory.setPort(server.getPort()); | ||
sftpSessionFactory.setUser("user"); | ||
|
||
assertDoesNotThrow(() -> sftpSessionFactory.getSession().connect()); |
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.
I'm not sure that this test really reflects what we would expect from its name.
I don't even think that we need to test against the real server and make connections.
There is probably just enough to verify against some mock that its method calls don't happen or so.
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.
I have thought about using some mock.
But the init code does start a connection and tries to authenticate.
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:
java.lang.IllegalStateException: failed to create SFTP Session
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:292)
...
Caused by: org.apache.sshd.common.SshException: No more authentication methods available
...
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.initClientSession(DefaultSftpSessionFactory.java:319)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:282)
... 89 more
Caused by: org.apache.sshd.common.SshException: No more authentication methods available
at org.apache.sshd.client.session.ClientUserAuthService.tryNext(ClientUserAuthService.java:379)
I doubt it would be wise to mock the better part of the calls which happen in the init towards the SshClient
.
Any suggestions?
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.
Yeah... I see: the integration with that SshClient
API is very heavy, therefore it is probably better to exchange a performance of the test in favor of clear code and direct calls instead of our error-prone mocks.
So, never mind then and thank you for your thoughts!
Please, consider to fix an assert in favor of assertThatNoException()
- and we are good to merge this.
…ovided SshClient replace JUnit assertDoesNotThrow by AssertJ assertThatNoException in test
Fixes #8581
Moved configuring an internal provided
SshClient
to a separate method, which only will execute ifisInnerClient
istrue
.Added a test proving an external configured
SshClient
can connect to aSshServer
.