aboutsummaryrefslogtreecommitdiff
path: root/tests/client
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2011-09-11 17:16:50 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2011-09-11 17:39:20 +0200
commitf3d00e4bc3e33331d13ec8b6153102952771daa6 (patch)
tree7714096c02ac16527cbf67fc08f20d870d34bc57 /tests/client
parentfa68d91869844dc8b829dacb296dc430982832ec (diff)
downloadlibssh-f3d00e4bc3e33331d13ec8b6153102952771daa6.tar.gz
libssh-f3d00e4bc3e33331d13ec8b6153102952771daa6.tar.xz
libssh-f3d00e4bc3e33331d13ec8b6153102952771daa6.zip
tests: nonblocking keyboard-interactive
Diffstat (limited to 'tests/client')
-rw-r--r--tests/client/torture_auth.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/client/torture_auth.c b/tests/client/torture_auth.c
index b716693..4fbcf58 100644
--- a/tests/client/torture_auth.c
+++ b/tests/client/torture_auth.c
@@ -147,6 +147,60 @@ static void torture_auth_kbdint(void **state) {
assert_true(rc == SSH_AUTH_SUCCESS);
}
+static void torture_auth_kbdint_nonblocking(void **state) {
+ ssh_session session = *state;
+ char *user = getenv("TORTURE_USER");
+ char *password = getenv("TORTURE_PASSWORD");
+ int rc;
+
+ if (user == NULL) {
+ print_message("*** Please set the environment variable TORTURE_USER"
+ " to enable this test!!\n");
+ return;
+ }
+
+ if (password == NULL) {
+ print_message("*** Please set the environment variable "
+ "TORTURE_PASSWORD to enable this test!!\n");
+ return;
+ }
+
+ rc = ssh_options_set(session, SSH_OPTIONS_USER, user);
+ assert_true(rc == SSH_OK);
+
+ rc = ssh_connect(session);
+ assert_true(rc == SSH_OK);
+
+ rc = ssh_userauth_none(session,NULL);
+ /* This request should return a SSH_REQUEST_DENIED error */
+ if (rc == SSH_ERROR) {
+ assert_true(ssh_get_error_code(session) == SSH_REQUEST_DENIED);
+ }
+ assert_true(ssh_auth_list(session) & SSH_AUTH_METHOD_INTERACTIVE);
+ ssh_set_blocking(session,0);
+ do {
+ rc = ssh_userauth_kbdint(session, NULL, NULL);
+ } while (rc == SSH_AUTH_AGAIN);
+ assert_true(rc == SSH_AUTH_INFO);
+ assert_int_equal(ssh_userauth_kbdint_getnprompts(session), 1);
+ do {
+ rc = ssh_userauth_kbdint_setanswer(session, 0, password);
+ } while (rc == SSH_AUTH_AGAIN);
+ assert_false(rc < 0);
+
+ do {
+ rc = ssh_userauth_kbdint(session, NULL, NULL);
+ } while (rc == SSH_AUTH_AGAIN);
+ /* Sometimes, SSH server send an empty query at the end of exchange */
+ if(rc == SSH_AUTH_INFO) {
+ assert_int_equal(ssh_userauth_kbdint_getnprompts(session), 0);
+ do {
+ rc = ssh_userauth_kbdint(session, NULL, NULL);
+ } while (rc == SSH_AUTH_AGAIN);
+ }
+ assert_true(rc == SSH_AUTH_SUCCESS);
+}
+
static void torture_auth_password(void **state) {
ssh_session session = *state;
char *user = getenv("TORTURE_USER");
@@ -286,6 +340,7 @@ int torture_run_tests(void) {
int rc;
const UnitTest tests[] = {
unit_test_setup_teardown(torture_auth_kbdint, setup, teardown),
+ unit_test_setup_teardown(torture_auth_kbdint_nonblocking, setup, teardown),
unit_test_setup_teardown(torture_auth_password, setup, teardown),
unit_test_setup_teardown(torture_auth_password_nonblocking, setup, teardown),
unit_test_setup_teardown(torture_auth_autopubkey, setup, teardown),