diff options
author | Andreas Schneider <asn@cynapses.org> | 2010-12-28 16:41:14 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cynapses.org> | 2010-12-28 22:14:47 +0100 |
commit | 8bd29736d216540fde9f9f2d56f3074ab5ba00f8 (patch) | |
tree | 7ed88f99a0ac6b6897b84aa9c5068fca7895409f | |
parent | 0b2cf70622cf86ad566a9b47bad4b1b70427371f (diff) | |
download | libssh-8bd29736d216540fde9f9f2d56f3074ab5ba00f8.tar.gz libssh-8bd29736d216540fde9f9f2d56f3074ab5ba00f8.tar.xz libssh-8bd29736d216540fde9f9f2d56f3074ab5ba00f8.zip |
tests: Migrated torture_auth to cmockery.
-rw-r--r-- | tests/client/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/client/torture_auth.c | 170 |
2 files changed, 96 insertions, 76 deletions
diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt index 7bb2dd57..a078e87b 100644 --- a/tests/client/CMakeLists.txt +++ b/tests/client/CMakeLists.txt @@ -1,6 +1,6 @@ project(clienttests C) add_cmockery_test(torture_algorithms torture_algorithms.c ${TORTURE_LIBRARY}) -#add_check_test(torture_auth torture_auth.c ${TORTURE_LIBRARY}) +add_cmockery_test(torture_auth torture_auth.c ${TORTURE_LIBRARY}) #add_check_test(torture_knownhosts torture_knownhosts.c ${TORTURE_LIBRARY}) #add_check_test(torture_proxycommand torture_proxycommand.c ${TORTURE_LIBRARY}) diff --git a/tests/client/torture_auth.c b/tests/client/torture_auth.c index 2381d8a9..463ebd10 100644 --- a/tests/client/torture_auth.c +++ b/tests/client/torture_auth.c @@ -25,89 +25,109 @@ #include "libssh/libssh.h" #include "libssh/priv.h" #include "libssh/session.h" -ssh_session session; -static void setup(void) { - int verbosity=torture_libssh_verbosity(); - session = ssh_new(); - ssh_options_set(session,SSH_OPTIONS_HOST,"localhost"); - ssh_options_set(session,SSH_OPTIONS_LOG_VERBOSITY,&verbosity); +static void setup(void **state) { + int verbosity = torture_libssh_verbosity(); + ssh_session session = ssh_new(); + + ssh_options_set(session, SSH_OPTIONS_HOST, "localhost"); + ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity); + + *state = session; } -static void teardown(void) { - ssh_disconnect(session); - ssh_free(session); +static void teardown(void **state) { + ssh_disconnect(*state); + ssh_free(*state); } -START_TEST (torture_auth_kbdint) -{ - int rc; - char *user=getenv("TORTURE_USER"); - char *password=getenv("TORTURE_PASSWORD"); - ck_assert_msg(user != NULL, "Please set the environment variable TORTURE_USER" - " to enable this test"); - ck_assert_msg(password != NULL, "Please set the environment variable " - "TORTURE_PASSWORD to enable this test"); - ssh_options_set(session,SSH_OPTIONS_USER,user); - rc=ssh_connect(session); - ck_assert_msg(rc==SSH_OK,ssh_get_error(session)); - - rc=ssh_userauth_none(session,NULL); - /* This request should return a SSH_REQUEST_DENIED error */ - if(rc == SSH_ERROR){ - ck_assert_msg(ssh_get_error_code(session)==SSH_REQUEST_DENIED, - ssh_get_error(session)); - } - ck_assert_msg(ssh_auth_list(session) & SSH_AUTH_METHOD_INTERACTIVE, - "SSH server doesn't allow keyboard-interactive"); - rc=ssh_userauth_kbdint(session,NULL,NULL); - ck_assert_msg(rc==SSH_AUTH_INFO,ssh_get_error(session)); - ck_assert_int_eq(ssh_userauth_kbdint_getnprompts(session),1); - ssh_userauth_kbdint_setanswer(session,0,password); - rc=ssh_userauth_kbdint(session,NULL,NULL); - /* Sometimes, SSH server send an empty query at the end of exchange */ - if(rc==SSH_AUTH_INFO){ - ck_assert_int_eq(ssh_userauth_kbdint_getnprompts(session),0); - rc=ssh_userauth_kbdint(session,NULL,NULL); - } - ck_assert_msg(rc==SSH_AUTH_SUCCESS,ssh_get_error(session)); +static void torture_auth_kbdint(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); + + rc = ssh_userauth_kbdint(session, NULL, NULL); + assert_true(rc == SSH_AUTH_INFO); + assert_int_equal(ssh_userauth_kbdint_getnprompts(session), 1); + + rc = ssh_userauth_kbdint_setanswer(session, 0, password); + assert_true(rc < 0); + + rc = ssh_userauth_kbdint(session, NULL, NULL); + /* 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); + rc = ssh_userauth_kbdint(session, NULL, NULL); + } + assert_true(rc == SSH_AUTH_SUCCESS); } -END_TEST - -START_TEST (torture_auth_password) -{ - int rc; - char *user=getenv("TORTURE_USER"); - char *password=getenv("TORTURE_PASSWORD"); - ck_assert_msg(user != NULL, "Please set the environment variable TORTURE_USER" - " to enable this test"); - ck_assert_msg(password != NULL, "Please set the environment variable " - "TORTURE_PASSWORD to enable this test"); - ssh_options_set(session,SSH_OPTIONS_USER,user); - rc=ssh_connect(session); - ck_assert_msg(rc==SSH_OK,ssh_get_error(session)); - - rc=ssh_userauth_none(session,NULL); - /* This request should return a SSH_REQUEST_DENIED error */ - if(rc == SSH_ERROR){ - ck_assert_msg(ssh_get_error_code(session)==SSH_REQUEST_DENIED, - ssh_get_error(session)); - } - ck_assert_msg(ssh_auth_list(session) & SSH_AUTH_METHOD_PASSWORD, - "SSH server doesn't allow password authentication"); - rc=ssh_userauth_password(session,NULL,password); - ck_assert_msg(rc==SSH_AUTH_SUCCESS,ssh_get_error(session)); -} -END_TEST -Suite *torture_make_suite(void) { - Suite *s = suite_create("libssh_auth"); +static void torture_auth_password(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); - torture_create_case_fixture(s, "torture_auth_kbint", - torture_auth_kbdint, setup, teardown); - torture_create_case_fixture(s, "torture_auth_password", - torture_auth_password, setup, teardown); - return s; + 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_PASSWORD); + + rc = ssh_userauth_password(session, NULL, password); + assert_true(rc == SSH_AUTH_SUCCESS); } +int torture_run_tests(void) { + const UnitTest tests[] = { + unit_test_setup_teardown(torture_auth_kbdint, setup, teardown), + unit_test_setup_teardown(torture_auth_password, setup, teardown), + }; + + return run_tests(tests); +} |