Debian Codegraph @

tests/client/torture_auth_common.c

raw
1 /*
2 * This file is part of the SSH Library
3 *
4 * Copyright (c) 2010 by Aris Adamantiadis
5 *
6 * The SSH Library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or (at your
9 * option) any later version.
10 *
11 * The SSH Library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 * License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with the SSH Library; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
20 */
21
22 #include "config.h"
23
24 #include "torture.h"
25 #include "libssh/libssh.h"
26
27 /* agent_is_running */
28 #include "agent.c"
29
30 void torture_auth_agent(void **state);
31 void torture_auth_agent(void **state)
32 {
33 struct torture_state *s = *state;
34 ssh_session session = s->ssh.session;
35 int rc;
36
37 if (!ssh_agent_is_running(session)){
38 print_message("*** Agent not running. Test ignored\n");
39 return;
40 }
41 rc = ssh_options_set(session, SSH_OPTIONS_USER, TORTURE_SSH_USER_ALICE);
42 assert_int_equal(rc, SSH_OK);
43
44 rc = ssh_connect(session);
45 assert_int_equal(rc, SSH_OK);
46
47 rc = ssh_userauth_none(session,NULL);
48 /* This request should return a SSH_REQUEST_DENIED error */
49 if (rc == SSH_ERROR) {
50 assert_int_equal(ssh_get_error_code(session), SSH_REQUEST_DENIED);
51 }
52 rc = ssh_userauth_list(session, NULL);
53 assert_true(rc & SSH_AUTH_METHOD_PUBLICKEY);
54
55 /* negative test case */
56 rc = ssh_userauth_agent(NULL, NULL);
57 assert_int_equal(rc, SSH_AUTH_ERROR);
58
59 rc = ssh_userauth_agent(session, NULL);
60 assert_ssh_return_code(session, rc);
61 }
62
63 void torture_auth_agent_nonblocking(void **state);
64 void torture_auth_agent_nonblocking(void **state)
65 {
66 struct torture_state *s = *state;
67 ssh_session session = s->ssh.session;
68 int rc;
69
70 if (!ssh_agent_is_running(session)){
71 print_message("*** Agent not running. Test ignored\n");
72 return;
73 }
74 rc = ssh_options_set(session, SSH_OPTIONS_USER, TORTURE_SSH_USER_ALICE);
75 assert_int_equal(rc, SSH_OK);
76
77 rc = ssh_connect(session);
78 assert_int_equal(rc, SSH_OK);
79
80 rc = ssh_userauth_none(session,NULL);
81 /* This request should return a SSH_REQUEST_DENIED error */
82 if (rc == SSH_ERROR) {
83 assert_int_equal(ssh_get_error_code(session), SSH_REQUEST_DENIED);
84 }
85 rc = ssh_userauth_list(session, NULL);
86 assert_true(rc & SSH_AUTH_METHOD_PUBLICKEY);
87
88 ssh_set_blocking(session,0);
89
90 do {
91 rc = ssh_userauth_agent(session, NULL);
92 } while (rc == SSH_AUTH_AGAIN);
93 assert_ssh_return_code(session, rc);
94 }