summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2016-06-19 07:14:23 +0200
committerJakub Hrozek <jhrozek@redhat.com>2016-07-07 10:24:31 +0200
commit87c6d9ea92d83460457353cfea6c5bde8744994a (patch)
treec64f26590a7408fd7ce2c81c02301fa241878070 /src/tests
parent8858d820445cffb67ef8cf790b3a8d37b008d654 (diff)
downloadsssd-87c6d9ea92d83460457353cfea6c5bde8744994a.tar.gz
sssd-87c6d9ea92d83460457353cfea6c5bde8744994a.tar.xz
sssd-87c6d9ea92d83460457353cfea6c5bde8744994a.zip
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 <sbose@redhat.com>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/cmocka/test_utils.c33
1 files changed, 33 insertions, 0 deletions
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. */