461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha/*
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha SSSD
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha authtok - Utilities tests
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha Authors:
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha Pallavi Jha <pallavikumarijha@gmail.com>
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha Copyright (C) 2013 Red Hat
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha This program is free software; you can redistribute it and/or modify
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha it under the terms of the GNU General Public License as published by
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha the Free Software Foundation; either version 3 of the License, or
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha (at your option) any later version.
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha This program is distributed in the hope that it will be useful,
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha but WITHOUT ANY WARRANTY; without even the implied warranty of
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha GNU General Public License for more details.
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha You should have received a copy of the GNU General Public License
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha along with this program. If not, see <http://www.gnu.org/licenses/>.
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha*/
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha#include <string.h>
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose#include <popt.h>
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose#include "tests/cmocka/common_mock.h"
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha#include "util/authtok.h"
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jhastruct test_state {
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha struct sss_auth_token *authtoken;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha};
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int setup(void **state)
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha{
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha struct test_state *ts = NULL;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose assert_true(leak_check_setup());
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose ts = talloc(global_talloc_context, struct test_state);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_non_null(ts);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ts->authtoken = sss_authtok_new(ts);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_non_null(ts->authtoken);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose check_leaks_push(ts);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha *state = (void *)ts;
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha}
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozekstatic int teardown(void **state)
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha{
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose assert_non_null(ts);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_true(check_leaks_pop(ts));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha talloc_free(ts);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose assert_true(leak_check_teardown());
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return 0;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha}
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jhastatic void test_sss_authtok_new(void **state)
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha{
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha struct test_state *ts = talloc_get_type_abort(*state, struct test_state);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha struct sss_auth_token *authtoken;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha authtoken = sss_authtok_new(ts);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_non_null(authtoken);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha talloc_free(authtoken);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha}
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha/* @test_authtok_type_x : tests following functions for different value of type
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha * sss_authtok_set
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha * sss_authtok_get_type
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha * sss_authtok_get_size
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha * sss_authtok_get_data
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha * sss_authtok_get_password
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha * sss_authtok_get_ccfile
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha *
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha * @test_authtok_type_password : type => SSS_AUTHTOK_TYPE_PASSWORD
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha * @test_authtok_type_ccfile : type => SSS_AUTHTOK_TYPE_CCFILE
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha * @test_authtok_type_empty : type => SSS_AUTHTOK_TYPE_EMPTY
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha */
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha/* Test when type has value SSS_AUTHTOK_TYPE_PASSWORD */
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jhastatic void test_sss_authtok_password(void **state)
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha{
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha size_t len;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha errno_t ret;
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose char *data;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha size_t ret_len;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha const char *pwd;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha struct test_state *ts;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha enum sss_authtok_type type;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha data = talloc_strdup(ts, "password");
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_non_null(data);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha len = strlen(data) + 1;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha type = SSS_AUTHTOK_TYPE_PASSWORD;
4b8021779e4db2a212a8214c17e778e843ae2b3aStef Walter ret = sss_authtok_set(ts->authtoken, type, (const uint8_t *)data, len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(type, sss_authtok_get_type(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(len, sss_authtok_get_size(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_string_equal(data, sss_authtok_get_data(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_get_password(ts->authtoken, &pwd, &ret_len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_string_equal(data, pwd);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(len - 1, ret_len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_set_password(ts->authtoken, data, len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_get_password(ts->authtoken, &pwd, &ret_len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_string_equal(data, pwd);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(len - 1, ret_len);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose talloc_free(data);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose sss_authtok_set_empty(ts->authtoken);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha}
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha/* Test when type has value SSS_AUTHTOK_TYPE_CCFILE */
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jhastatic void test_sss_authtok_ccfile(void **state)
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha{
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha size_t len;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha errno_t ret;
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose char *data;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha size_t ret_len;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha const char *pwd;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha struct test_state *ts;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha enum sss_authtok_type type;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha data = talloc_strdup(ts, "path/to/cc_file");
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_non_null(data);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha len = strlen(data) + 1;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha type = SSS_AUTHTOK_TYPE_CCFILE;
4b8021779e4db2a212a8214c17e778e843ae2b3aStef Walter ret = sss_authtok_set(ts->authtoken, type, (const uint8_t *)data, len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(type, sss_authtok_get_type(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(len, sss_authtok_get_size(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_string_equal(data, sss_authtok_get_data(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_get_ccfile(ts->authtoken, &pwd, &ret_len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_string_equal(data, pwd);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(len - 1, ret_len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_set_ccfile(ts->authtoken, data, len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_get_ccfile(ts->authtoken, &pwd, &ret_len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_string_equal(data, pwd);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(len - 1, ret_len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
4b8021779e4db2a212a8214c17e778e843ae2b3aStef Walter ret = sss_authtok_set(ts->authtoken, type, (const uint8_t *) data, 0);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(type, sss_authtok_get_type(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(len, sss_authtok_get_size(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_string_equal(data, sss_authtok_get_data(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_get_ccfile(ts->authtoken, &pwd, &ret_len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_string_equal(data, pwd);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(len - 1, ret_len);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose talloc_free(data);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose sss_authtok_set_empty(ts->authtoken);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha}
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha/* Test when type has value SSS_AUTHTOK_TYPE_EMPTY */
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jhastatic void test_sss_authtok_empty(void **state)
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha{
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha errno_t ret;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha size_t ret_len;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha const char *pwd;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha struct test_state *ts;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha enum sss_authtok_type type;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha type = SSS_AUTHTOK_TYPE_EMPTY;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_set(ts->authtoken, type, NULL, 0);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(type, sss_authtok_get_type(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(0, sss_authtok_get_size(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_null(sss_authtok_get_data(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_get_password(ts->authtoken, &pwd, &ret_len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, ENOENT);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_get_ccfile(ts->authtoken, &pwd, &ret_len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, ENOENT);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha sss_authtok_set_empty(ts->authtoken);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(type, sss_authtok_get_type(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(0, sss_authtok_get_size(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_null(sss_authtok_get_data(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
8c4aeae19dbb436c17b5f4032285adbaed727eeaLukas Slebodnik ret = sss_authtok_set(ts->authtoken, type, (const uint8_t*)"", 0);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(type, sss_authtok_get_type(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(EOK, sss_authtok_get_size(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_null(sss_authtok_get_data(ts->authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_get_password(ts->authtoken, &pwd, &ret_len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, ENOENT);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_get_ccfile(ts->authtoken, &pwd, &ret_len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, ENOENT);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha}
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jhastatic void test_sss_authtok_wipe_password(void **state)
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha{
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha size_t len;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha errno_t ret;
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose char *data;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha size_t ret_len;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha const char *pwd;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha struct test_state *ts;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha enum sss_authtok_type type;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ts = talloc_get_type_abort(*state, struct test_state);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha data = talloc_strdup(ts, "password");
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_non_null(data);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha len = strlen(data) + 1;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha type = SSS_AUTHTOK_TYPE_PASSWORD;
4b8021779e4db2a212a8214c17e778e843ae2b3aStef Walter ret = sss_authtok_set(ts->authtoken, type, (const uint8_t *)data, len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha sss_authtok_wipe_password(ts->authtoken);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_get_password(ts->authtoken, &pwd, &ret_len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_string_equal(pwd, "");
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(len - 1, ret_len);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose sss_authtok_set_empty(ts->authtoken);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose talloc_free(data);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha}
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jhastatic void test_sss_authtok_copy(void **state)
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha{
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha size_t len;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha errno_t ret;
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose char *data;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha struct test_state *ts;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha enum sss_authtok_type type;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha struct sss_auth_token *dest_authtoken;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ts= talloc_get_type_abort(*state, struct test_state);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha dest_authtoken = sss_authtok_new(ts);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_non_null(dest_authtoken);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha data = talloc_strdup(ts, "password");
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_non_null(data);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha len = strlen(data) + 1;
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha type = SSS_AUTHTOK_TYPE_EMPTY;
4b8021779e4db2a212a8214c17e778e843ae2b3aStef Walter ret = sss_authtok_set(ts->authtoken, type, (const uint8_t *)data, len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(EOK, sss_authtok_copy(ts->authtoken, dest_authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(type, sss_authtok_get_type(dest_authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose sss_authtok_set_empty(dest_authtoken);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha type = SSS_AUTHTOK_TYPE_PASSWORD;
4b8021779e4db2a212a8214c17e778e843ae2b3aStef Walter ret = sss_authtok_set(ts->authtoken, type, (const uint8_t *)data, len);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha ret = sss_authtok_copy(ts->authtoken, dest_authtoken);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(ret, EOK);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(type, sss_authtok_get_type(dest_authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_string_equal(data, sss_authtok_get_data(dest_authtoken));
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha assert_int_equal(len, sss_authtok_get_size(dest_authtoken));
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose sss_authtok_set_empty(dest_authtoken);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose talloc_free(dest_authtoken);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose sss_authtok_set_empty(ts->authtoken);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose talloc_free(data);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha}
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bosevoid test_sss_authtok_2fa(void **state)
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose{
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose int ret;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose const char *fa1;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose size_t fa1_size;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose const char *fa2;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose size_t fa2_size;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose struct test_state *ts;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ts = talloc_get_type_abort(*state, struct test_state);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_authtok_set_2fa(NULL, "a", 0, "b", 0);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EINVAL);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose /* Test missing first factor */
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_authtok_set_2fa(ts->authtoken, NULL, 1, "b", 1);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EINVAL);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose /* Test missing second factor */
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_authtok_set_2fa(ts->authtoken, "a", 1, NULL, 1);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EINVAL);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose /* Test wrong first factor length */
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_authtok_set_2fa(ts->authtoken, "ab", 1, "b", 1);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EINVAL);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose /* Test wrong second factor length */
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_authtok_set_2fa(ts->authtoken, "a", 1, "bc", 1);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EINVAL);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_authtok_set_2fa(ts->authtoken, "a", 1, "bc", 2);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EOK);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(sss_authtok_get_size(ts->authtoken),
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose 2 * sizeof(uint32_t) + 5);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(sss_authtok_get_type(ts->authtoken), SSS_AUTHTOK_TYPE_2FA);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose#if __BYTE_ORDER == __LITTLE_ENDIAN
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_memory_equal(sss_authtok_get_data(ts->authtoken),
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose "\2\0\0\0\3\0\0\0a\0bc\0",
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose 2 * sizeof(uint32_t) + 5);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose#else
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_memory_equal(sss_authtok_get_data(ts->authtoken),
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose "\0\0\0\2\0\0\0\3a\0bc\0",
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose 2 * sizeof(uint32_t) + 5);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose#endif
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_authtok_get_2fa(ts->authtoken, &fa1, &fa1_size, &fa2, &fa2_size);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EOK);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(fa1_size, 1);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_string_equal(fa1, "a");
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(fa2_size, 2);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_string_equal(fa2, "bc");
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose sss_authtok_set_empty(ts->authtoken);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose /* check return code of empty token */
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_authtok_get_2fa(ts->authtoken, &fa1, &fa1_size, &fa2, &fa2_size);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, ENOENT);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose /* check return code for other token type */
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_authtok_set_password(ts->authtoken, "abc", 0);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EOK);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_authtok_get_2fa(ts->authtoken, &fa1, &fa1_size, &fa2, &fa2_size);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EACCES);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose sss_authtok_set_empty(ts->authtoken);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose /* check return code for garbage */
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_authtok_set(ts->authtoken, SSS_AUTHTOK_TYPE_2FA,
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose (const uint8_t *) "1111222233334444", 16);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EINVAL);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose sss_authtok_set_empty(ts->authtoken);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose}
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bosevoid test_sss_authtok_2fa_blobs(void **state)
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose{
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose int ret;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose struct test_state *ts;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose size_t needed_size;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose uint8_t *buf;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose char *fa1;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose size_t fa1_len;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose char *fa2;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose size_t fa2_len;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ts = talloc_get_type_abort(*state, struct test_state);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_auth_pack_2fa_blob(NULL, 0, "defg", 0, NULL, 0, &needed_size);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EINVAL);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_auth_pack_2fa_blob("abc", 0, NULL, 0, NULL, 0, &needed_size);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EINVAL);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_auth_pack_2fa_blob("", 0, "defg", 0, NULL, 0, &needed_size);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EINVAL);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_auth_pack_2fa_blob("abc", 0, "", 0, NULL, 0, &needed_size);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EINVAL);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_auth_pack_2fa_blob("abc", 0, "defg", 0, NULL, 0, &needed_size);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EAGAIN);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose buf = talloc_size(ts, needed_size);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_non_null(buf);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_auth_pack_2fa_blob("abc", 0, "defg", 0, buf, needed_size,
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose &needed_size);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EOK);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose#if __BYTE_ORDER == __LITTLE_ENDIAN
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_memory_equal(buf, "\4\0\0\0\5\0\0\0abc\0defg\0", needed_size);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose#else
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_memory_equal(buf, "\0\0\0\4\0\0\0\5abc\0defg\0", needed_size);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose#endif
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_auth_unpack_2fa_blob(ts, buf, needed_size, &fa1, &fa1_len, &fa2,
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose &fa2_len);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EOK);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(fa1_len, 3);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_string_equal(fa1, "abc");
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(fa2_len, 4);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_string_equal(fa2, "defg");
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose talloc_free(buf);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose talloc_free(fa1);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose talloc_free(fa2);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose}
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bosevoid test_sss_authtok_sc_blobs(void **state)
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose{
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose int ret;
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose struct test_state *ts;
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose size_t needed_size;
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose uint8_t *buf;
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose const char *pin;
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose size_t pin_len;
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose const char *token_name;
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose size_t token_name_len;
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose const char *module_name;
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose size_t module_name_len;
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose const char *key_id;
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose size_t key_id_len;
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose ts = talloc_get_type_abort(*state, struct test_state);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose ret = sss_auth_pack_sc_blob("abc", 0, "defg", 0, "hijkl", 0, "mnopqr", 0,
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose NULL, 0, &needed_size);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(ret, EAGAIN);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose buf = talloc_size(ts, needed_size);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_non_null(buf);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose ret = sss_auth_pack_sc_blob("abc", 0, "defg", 0, "hijkl", 0, "mnopqr", 0,
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose buf, needed_size, &needed_size);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(ret, EOK);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose#if __BYTE_ORDER == __LITTLE_ENDIAN
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_memory_equal(buf, "\4\0\0\0\5\0\0\0\6\0\0\0\7\0\0\0abc\0defg\0hijkl\0mnopqr\0",
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose needed_size);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose#else
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_memory_equal(buf, "\0\0\0\4\0\0\0\5\0\0\0\6\0\0\0\7abc\0defg\0hijkl\0mnopqr\0",
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose needed_size);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose#endif
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose ret = sss_authtok_set(ts->authtoken, SSS_AUTHTOK_TYPE_SC_PIN, buf,
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose needed_size);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(ret, EOK);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose ret = sss_authtok_get_sc(ts->authtoken, &pin, &pin_len,
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose &token_name, &token_name_len,
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose &module_name, &module_name_len,
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose &key_id, &key_id_len);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(ret, EOK);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(pin_len, 3);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_string_equal(pin, "abc");
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(token_name_len, 4);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_string_equal(token_name, "defg");
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(module_name_len, 5);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_string_equal(module_name, "hijkl");
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(key_id_len, 6);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_string_equal(key_id, "mnopqr");
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose ret = sss_authtok_get_sc(ts->authtoken, NULL, NULL,
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose &token_name, &token_name_len,
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose &module_name, &module_name_len,
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose &key_id, &key_id_len);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(ret, EOK);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(token_name_len, 4);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_string_equal(token_name, "defg");
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(module_name_len, 5);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_string_equal(module_name, "hijkl");
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(key_id_len, 6);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_string_equal(key_id, "mnopqr");
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose ret = sss_authtok_get_sc(ts->authtoken, NULL, NULL,
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose &token_name, NULL,
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose &module_name, NULL,
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose &key_id, NULL);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(ret, EOK);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_string_equal(token_name, "defg");
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_string_equal(module_name, "hijkl");
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_string_equal(key_id, "mnopqr");
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose sss_authtok_set_empty(ts->authtoken);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose talloc_free(buf);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose}
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose#define MISSING_NULL_CHECK do { \
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(ret, EOK); \
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(fa1_len, 3); \
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_string_equal(fa1, "abc"); \
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_int_equal(fa2_len, 4); \
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose assert_string_equal(fa2, "defg"); \
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose \
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose talloc_free(fa1); \
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose talloc_free(fa2); \
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose} while (0)
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bosevoid test_sss_authtok_2fa_blobs_missing_null(void **state)
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose{
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose int ret;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose struct test_state *ts;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose char *fa1;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose size_t fa1_len;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose char *fa2;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose size_t fa2_len;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose#if __BYTE_ORDER == __LITTLE_ENDIAN
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose uint8_t b0[] = {0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 'a', 'b', 'c', 0x00, 'd', 'e', 'f', 'g', 0x00};
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose uint8_t b1[] = {0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 0x00};
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose uint8_t b2[] = {0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 'a', 'b', 'c', 0x00, 'd', 'e', 'f', 'g'};
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose uint8_t b3[] = {0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 'a', 'b', 'c', 'd', 'e', 'f', 'g'};
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose#else
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose uint8_t b0[] = {0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 'a', 'b', 'c', 0x00, 'd', 'e', 'f', 'g', 0x00};
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose uint8_t b1[] = {0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 0x00};
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose uint8_t b2[] = {0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 'a', 'b', 'c', 0x00, 'd', 'e', 'f', 'g'};
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose uint8_t b3[] = {0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 'a', 'b', 'c', 'd', 'e', 'f', 'g'};
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose#endif
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ts = talloc_get_type_abort(*state, struct test_state);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_auth_unpack_2fa_blob(ts, b0, sizeof(b0), &fa1, &fa1_len, &fa2,
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose &fa2_len);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose MISSING_NULL_CHECK;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_auth_unpack_2fa_blob(ts, b1, sizeof(b1), &fa1, &fa1_len, &fa2,
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose &fa2_len);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose MISSING_NULL_CHECK;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_auth_unpack_2fa_blob(ts, b2, sizeof(b2), &fa1, &fa1_len, &fa2,
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose &fa2_len);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose MISSING_NULL_CHECK;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose ret = sss_auth_unpack_2fa_blob(ts, b3, sizeof(b3), &fa1, &fa1_len, &fa2,
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose &fa2_len);
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose MISSING_NULL_CHECK;
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose}
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bosevoid test_sss_authtok_sc_keypad(void **state)
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose{
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose struct test_state *ts;
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose ts = talloc_get_type_abort(*state, struct test_state);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose sss_authtok_set_sc_keypad(NULL);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose sss_authtok_set_sc_keypad(ts->authtoken);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(sss_authtok_get_type(ts->authtoken),
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose SSS_AUTHTOK_TYPE_SC_KEYPAD);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(sss_authtok_get_size(ts->authtoken), 0);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_null(sss_authtok_get_data(ts->authtoken));
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose}
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bosevoid test_sss_authtok_sc_pin(void **state)
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose{
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose struct test_state *ts;
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose int ret;
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose size_t size;
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose const char *pin;
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose size_t len;
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose ts = talloc_get_type_abort(*state, struct test_state);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose ret = sss_authtok_set_sc_pin(NULL, NULL, 0);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(ret, EFAULT);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose ret = sss_authtok_set_sc_pin(ts->authtoken, NULL, 0);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(ret, EINVAL);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose ret = sss_authtok_set_sc_pin(ts->authtoken, "12345678", 0);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(ret, EOK);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(sss_authtok_get_type(ts->authtoken),
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose SSS_AUTHTOK_TYPE_SC_PIN);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose size = sss_authtok_get_size(ts->authtoken);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(size, 28);
bc07967636135e48252198936ac8975510918e99Sumit Bose#if __BYTE_ORDER == __LITTLE_ENDIAN
bc07967636135e48252198936ac8975510918e99Sumit Bose assert_memory_equal(sss_authtok_get_data(ts->authtoken),
bc07967636135e48252198936ac8975510918e99Sumit Bose "\11\0\0\0\1\0\0\0\1\0\0\0\1\0\0\0" "12345678\0\0\0\0",
bc07967636135e48252198936ac8975510918e99Sumit Bose size);
bc07967636135e48252198936ac8975510918e99Sumit Bose#else
bc07967636135e48252198936ac8975510918e99Sumit Bose assert_memory_equal(sss_authtok_get_data(ts->authtoken),
bc07967636135e48252198936ac8975510918e99Sumit Bose "\0\0\0\11\0\0\0\1\0\0\0\1\0\0\0\1" "12345678\0\0\0\0",
bc07967636135e48252198936ac8975510918e99Sumit Bose size);
bc07967636135e48252198936ac8975510918e99Sumit Bose#endif
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose ret = sss_authtok_set_sc_pin(ts->authtoken, "12345678", 5);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(ret, EOK);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(sss_authtok_get_type(ts->authtoken),
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose SSS_AUTHTOK_TYPE_SC_PIN);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose size = sss_authtok_get_size(ts->authtoken);
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose assert_int_equal(size, 25);
bc07967636135e48252198936ac8975510918e99Sumit Bose#if __BYTE_ORDER == __LITTLE_ENDIAN
bc07967636135e48252198936ac8975510918e99Sumit Bose assert_memory_equal(sss_authtok_get_data(ts->authtoken),
bc07967636135e48252198936ac8975510918e99Sumit Bose "\6\0\0\0\1\0\0\0\1\0\0\0\1\0\0\0" "12345\0\0\0\0",
bc07967636135e48252198936ac8975510918e99Sumit Bose size);
bc07967636135e48252198936ac8975510918e99Sumit Bose#else
bc07967636135e48252198936ac8975510918e99Sumit Bose assert_memory_equal(sss_authtok_get_data(ts->authtoken),
bc07967636135e48252198936ac8975510918e99Sumit Bose "\0\0\0\6\0\0\0\1\0\0\0\1\0\0\0\1" "12345\0\0\0\0",
bc07967636135e48252198936ac8975510918e99Sumit Bose size);
bc07967636135e48252198936ac8975510918e99Sumit Bose#endif
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose ret = sss_authtok_get_sc_pin(ts->authtoken, &pin, &len);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(ret, EOK);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(len, 5);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_string_equal(pin, "12345");
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose sss_authtok_set_empty(ts->authtoken);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose ret = sss_authtok_get_sc_pin(ts->authtoken, &pin, &len);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(ret, ENOENT);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose ret = sss_authtok_set_password(ts->authtoken, "12345", 0);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(ret, EOK);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose ret = sss_authtok_get_sc_pin(ts->authtoken, &pin, &len);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(ret, EACCES);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose sss_authtok_set_empty(ts->authtoken);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose ret = sss_authtok_get_sc_pin(NULL, &pin, &len);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose assert_int_equal(ret, EFAULT);
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose}
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Boseint main(int argc, const char *argv[])
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha{
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose poptContext pc;
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose int opt;
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose struct poptOption long_options[] = {
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose POPT_AUTOHELP
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose SSSD_DEBUG_OPTS
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose POPT_TABLEEND
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose };
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek const struct CMUnitTest tests[] = {
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_authtok_new,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_authtok_password,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_authtok_ccfile,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_authtok_empty,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_authtok_wipe_password,
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek setup, teardown),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test_setup_teardown(test_sss_authtok_copy,
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose setup, teardown),
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose cmocka_unit_test_setup_teardown(test_sss_authtok_2fa,
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose setup, teardown),
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose cmocka_unit_test_setup_teardown(test_sss_authtok_2fa_blobs,
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose setup, teardown),
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose cmocka_unit_test_setup_teardown(test_sss_authtok_2fa_blobs_missing_null,
bc052ea17d858c19f9cb9c9e2bc602e754f68831Sumit Bose setup, teardown),
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose cmocka_unit_test_setup_teardown(test_sss_authtok_sc_keypad,
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose setup, teardown),
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose cmocka_unit_test_setup_teardown(test_sss_authtok_sc_pin,
10703cd558016685ee778e333f1d4490238d46e7Sumit Bose setup, teardown),
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose cmocka_unit_test_setup_teardown(test_sss_authtok_sc_blobs,
dd17a3aaddab6f122dff3bd15b7005464c07c0eaSumit Bose setup, teardown),
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha };
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose debug_level = SSSDBG_INVALID;
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose while((opt = poptGetNextOpt(pc)) != -1) {
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose switch(opt) {
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose default:
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose fprintf(stderr, "\nInvalid option %s: %s\n\n",
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose poptBadOption(pc, 0), poptStrerror(opt));
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose poptPrintUsage(pc, stderr, 0);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose return 1;
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose }
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose }
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose poptFreeContext(pc);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose DEBUG_CLI_INIT(debug_level);
80b5dbe123ec94c5a8fcb99f9a4953c1513deb58Sumit Bose
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek return cmocka_run_group_tests(tests, NULL, NULL);
461da2984c747708e8badd27fa55ef879f40e712Pallavi Jha}