You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2019/01/30 12:41:11 UTC
[mina-sshd] 02/03: Slightly stricter code in AsyncAuth related tests
This is an automated email from the ASF dual-hosted git repository.
lgoldstein pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git
commit 16083e60b88469994f3d40303fddb3c83855e2b8
Author: Lyor Goldstein <lg...@apache.org>
AuthorDate: Tue Jan 29 13:46:32 2019 +0200
Slightly stricter code in AsyncAuth related tests
---
.../sshd/server/auth/AsyncAuthInteractiveTest.java | 32 ++++++++++---------
.../org/apache/sshd/server/auth/AsyncAuthTest.java | 36 ++++++++++++----------
.../apache/sshd/server/auth/AsyncAuthTestBase.java | 5 ++-
3 files changed, 39 insertions(+), 34 deletions(-)
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/auth/AsyncAuthInteractiveTest.java b/sshd-core/src/test/java/org/apache/sshd/server/auth/AsyncAuthInteractiveTest.java
index 40e86c8..c5b31ff 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/auth/AsyncAuthInteractiveTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/auth/AsyncAuthInteractiveTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.sshd.server.auth;
+import org.apache.sshd.common.channel.Channel;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
@@ -39,10 +40,7 @@ public class AsyncAuthInteractiveTest extends AsyncAuthTestBase {
@Override
protected boolean authenticate() throws Exception {
JSch jsch = new JSch();
- Session session;
- ChannelShell channel;
-
- session = jsch.getSession("whatever", "localhost", port);
+ Session session = jsch.getSession("whatever", "localhost", port);
session.setUserInfo(new UserInfo() {
@Override
public String getPassphrase() {
@@ -77,7 +75,8 @@ public class AsyncAuthInteractiveTest extends AsyncAuthTestBase {
try {
session.connect();
} catch (JSchException e) {
- switch (e.getMessage()) {
+ String reason = e.getMessage();
+ switch (reason) {
case "Auth cancel":
case "Auth fail":
return false;
@@ -85,19 +84,22 @@ public class AsyncAuthInteractiveTest extends AsyncAuthTestBase {
throw e;
}
}
- channel = (ChannelShell) session.openChannel("shell");
- channel.connect();
try {
- channel.disconnect();
- } catch (Exception ignore) {
- // ignore
- }
+ ChannelShell channel = (ChannelShell) session.openChannel(Channel.CHANNEL_SHELL);
+ channel.connect();
- try {
- session.disconnect();
- } catch (Exception ignore) {
- // ignore
+ try {
+ channel.disconnect();
+ } catch (Exception ignore) {
+ // ignore
+ }
+ } finally {
+ try {
+ session.disconnect();
+ } catch (Exception ignore) {
+ // ignore
+ }
}
return true;
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/auth/AsyncAuthTest.java b/sshd-core/src/test/java/org/apache/sshd/server/auth/AsyncAuthTest.java
index 70530db..2ca0000 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/auth/AsyncAuthTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/auth/AsyncAuthTest.java
@@ -18,6 +18,9 @@
*/
package org.apache.sshd.server.auth;
+import java.util.Objects;
+
+import org.apache.sshd.common.channel.Channel;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
@@ -32,7 +35,6 @@ import com.jcraft.jsch.UserInfo;
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class AsyncAuthTest extends AsyncAuthTestBase {
-
public AsyncAuthTest() {
super();
}
@@ -40,10 +42,7 @@ public class AsyncAuthTest extends AsyncAuthTestBase {
@Override
protected boolean authenticate() throws Exception {
JSch jsch = new JSch();
- Session session;
- ChannelShell channel;
-
- session = jsch.getSession("whatever", "localhost", port);
+ Session session = jsch.getSession("whatever", "localhost", port);
session.setPassword("whocares");
session.setUserInfo(new UserInfo() {
@Override
@@ -76,28 +75,33 @@ public class AsyncAuthTest extends AsyncAuthTestBase {
// Do nothing
}
});
+
try {
session.connect();
} catch (JSchException e) {
- if (e.getMessage().equals("Auth cancel")) {
+ String reason = e.getMessage();
+ if (Objects.equals(reason, "Auth cancel")) {
return false;
} else {
throw e;
}
}
- channel = (ChannelShell) session.openChannel("shell");
- channel.connect();
try {
- channel.disconnect();
- } catch (Exception ignore) {
- // ignored
- }
+ ChannelShell channel = (ChannelShell) session.openChannel(Channel.CHANNEL_SHELL);
+ channel.connect();
- try {
- session.disconnect();
- } catch (Exception ignore) {
- // ignored
+ try {
+ channel.disconnect();
+ } catch (Exception ignore) {
+ // ignored
+ }
+ } finally {
+ try {
+ session.disconnect();
+ } catch (Exception ignore) {
+ // ignored
+ }
}
return true;
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/auth/AsyncAuthTestBase.java b/sshd-core/src/test/java/org/apache/sshd/server/auth/AsyncAuthTestBase.java
index ba903f9..9f035aa 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/auth/AsyncAuthTestBase.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/auth/AsyncAuthTestBase.java
@@ -37,9 +37,8 @@ import com.jcraft.jsch.JSchException;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public abstract class AsyncAuthTestBase extends BaseTestSupport {
-
- SshServer server;
- int port;
+ protected SshServer server;
+ protected int port;
private PasswordAuthenticator authenticator;