From 87c6d9ea92d83460457353cfea6c5bde8744994a Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Sun, 19 Jun 2016 07:14:23 +0200 Subject: UTIL: Add a utility function sss_output_name Adds a convenience function that will help reduce the amount of code duplication in the responders. All responders need to parse the username from the internal format, lower-case the name, if the domain is case-insensitive and then replace spaces if the responder is configured to do so. Reviewed-by: Sumit Bose --- src/tests/cmocka/test_utils.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/tests') diff --git a/src/tests/cmocka/test_utils.c b/src/tests/cmocka/test_utils.c index 456629581..e171848f1 100644 --- a/src/tests/cmocka/test_utils.c +++ b/src/tests/cmocka/test_utils.c @@ -1679,6 +1679,36 @@ static void test_sss_create_internal_fqname_list(void **state) assert_true(check_leaks_pop(global_talloc_context) == true); } +static void test_sss_output_name(void **state) +{ + char *outname; + char *fqname; + + check_leaks_push(global_talloc_context); + + fqname = sss_create_internal_fqname(global_talloc_context, + "Foo Bar", "DOM"); + assert_non_null(fqname); + + outname = sss_output_name(global_talloc_context, fqname, true, 0); + assert_non_null(outname); + assert_string_equal(outname, "Foo Bar"); + talloc_zfree(outname); + + outname = sss_output_name(global_talloc_context, fqname, false, 0); + assert_non_null(outname); + assert_string_equal(outname, "foo bar"); + talloc_zfree(outname); + + outname = sss_output_name(global_talloc_context, fqname, false, '-'); + assert_non_null(outname); + assert_string_equal(outname, "foo-bar"); + talloc_zfree(outname); + + talloc_free(fqname); + assert_true(check_leaks_pop(global_talloc_context) == true); +} + int main(int argc, const char *argv[]) { poptContext pc; @@ -1770,6 +1800,9 @@ int main(int argc, const char *argv[]) cmocka_unit_test_setup_teardown(test_sss_create_internal_fqname_list, setup_leak_tests, teardown_leak_tests), + cmocka_unit_test_setup_teardown(test_sss_output_name, + setup_leak_tests, + teardown_leak_tests), }; /* Set debug level to invalid value so we can deside if -d 0 was used. */ -- cgit