aboutsummaryrefslogtreecommitdiff
path: root/tests/client
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2011-09-11 00:50:51 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2011-09-11 17:22:27 +0200
commit7b663df185fdcf3e16cd8351d31f3d80a5635063 (patch)
treeeb498ccfd7db855f3043d87a415c1a851c8a1a8c /tests/client
parent33bd3d6cd935f93b6d2c8b89d11e32c5f540ea6c (diff)
downloadlibssh-7b663df185fdcf3e16cd8351d31f3d80a5635063.tar.gz
libssh-7b663df185fdcf3e16cd8351d31f3d80a5635063.tar.xz
libssh-7b663df185fdcf3e16cd8351d31f3d80a5635063.zip
Tests: unit test for agent authentication
Diffstat (limited to 'tests/client')
-rw-r--r--tests/client/torture_auth.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/client/torture_auth.c b/tests/client/torture_auth.c
index 3637a6a..ceeb2f3 100644
--- a/tests/client/torture_auth.c
+++ b/tests/client/torture_auth.c
@@ -193,6 +193,63 @@ static void torture_auth_password_nonblocking(void **state) {
assert_true(rc == SSH_AUTH_SUCCESS);
}
+static void torture_auth_agent(void **state) {
+ ssh_session session = *state;
+ char *user = getenv("TORTURE_USER");
+ int rc;
+
+ if (user == NULL) {
+ print_message("*** Please set the environment variable TORTURE_USER"
+ " 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_PUBLICKEY);
+
+ rc = ssh_userauth_agent(session, NULL);
+ assert_true(rc == SSH_AUTH_SUCCESS);
+}
+
+static void torture_auth_agent_nonblocking(void **state) {
+ ssh_session session = *state;
+ char *user = getenv("TORTURE_USER");
+ int rc;
+
+ if (user == NULL) {
+ print_message("*** Please set the environment variable TORTURE_USER"
+ " 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_PUBLICKEY);
+ ssh_set_blocking(session, 0);
+ do {
+ rc = ssh_userauth_agent(session, NULL);
+ } while (rc == SSH_AUTH_AGAIN);
+ assert_true(rc == SSH_AUTH_SUCCESS);
+}
int torture_run_tests(void) {
int rc;
@@ -201,6 +258,8 @@ int torture_run_tests(void) {
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),
+ unit_test_setup_teardown(torture_auth_agent, setup, teardown),
+ unit_test_setup_teardown(torture_auth_agent_nonblocking, setup, teardown),
};
ssh_init();