From 1fcaac9a35b1e8e097a72e685ab517cb057d9764 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Tue, 3 Oct 2023 17:44:40 +0200 Subject: [PATCH] tests: Implement more negative auth tests Signed-off-by: Jakub Jelen Reviewed-by: Sahana Prasad --- tests/client/torture_auth.c | 12 ++++++++++++ tests/client/torture_auth_common.c | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/tests/client/torture_auth.c b/tests/client/torture_auth.c index d3e71d9e..fa58c14a 100644 --- a/tests/client/torture_auth.c +++ b/tests/client/torture_auth.c @@ -296,9 +296,21 @@ static void torture_auth_pubkey(void **state) { rc = ssh_pki_import_privkey_file(bob_ssh_key, NULL, NULL, NULL, &privkey); assert_int_equal(rc, SSH_OK); + /* negative tests */ + rc = ssh_userauth_try_publickey(NULL, NULL, privkey); + assert_int_equal(rc, SSH_AUTH_ERROR); + rc = ssh_userauth_try_publickey(session, NULL, NULL); + assert_int_equal(rc, SSH_AUTH_ERROR); + rc = ssh_userauth_try_publickey(session, NULL, privkey); assert_int_equal(rc, SSH_AUTH_SUCCESS); + /* negative tests */ + rc = ssh_userauth_publickey(NULL, NULL, privkey); + assert_int_equal(rc, SSH_AUTH_ERROR); + rc = ssh_userauth_publickey(session, NULL, NULL); + assert_int_equal(rc, SSH_AUTH_ERROR); + rc = ssh_userauth_publickey(session, NULL, privkey); assert_int_equal(rc, SSH_AUTH_SUCCESS); diff --git a/tests/client/torture_auth_common.c b/tests/client/torture_auth_common.c index 15e407ab..8a4f2854 100644 --- a/tests/client/torture_auth_common.c +++ b/tests/client/torture_auth_common.c @@ -52,6 +52,10 @@ void torture_auth_agent(void **state) rc = ssh_userauth_list(session, NULL); assert_true(rc & SSH_AUTH_METHOD_PUBLICKEY); + /* negative test case */ + rc = ssh_userauth_agent(NULL, NULL); + assert_int_equal(rc, SSH_AUTH_ERROR); + rc = ssh_userauth_agent(session, NULL); assert_ssh_return_code(session, rc); }