summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2015-05-26 13:01:13 +0200
committerTomas Babej <tbabej@redhat.com>2015-07-08 01:56:52 +0200
commit5017726ebaf6eea3dedb1325efe00c0d6c4b6187 (patch)
tree8dc1a0b96a1e76da818892b8a61c61e3b2732302
parent3f7481a220371e1a1ff0babae39e26f78a8948ad (diff)
downloadfreeipa-5017726ebaf6eea3dedb1325efe00c0d6c4b6187.tar.gz
freeipa-5017726ebaf6eea3dedb1325efe00c0d6c4b6187.tar.xz
freeipa-5017726ebaf6eea3dedb1325efe00c0d6c4b6187.zip
ipa-kdb: add unit_tests for string_to_sid() and dom_sid_string()
Reviewed-By: Tomas Babej <tbabej@redhat.com>
-rw-r--r--daemons/ipa-kdb/tests/ipa_kdb_tests.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/daemons/ipa-kdb/tests/ipa_kdb_tests.c b/daemons/ipa-kdb/tests/ipa_kdb_tests.c
index 7b9b85d2c..edd4ae097 100644
--- a/daemons/ipa-kdb/tests/ipa_kdb_tests.c
+++ b/daemons/ipa-kdb/tests/ipa_kdb_tests.c
@@ -408,11 +408,71 @@ void test_get_authz_data_types(void **state)
krb5_free_principal(test_ctx->krb5_ctx, non_nfs_princ);
}
+void test_string_to_sid(void **state)
+{
+ int ret;
+ struct dom_sid sid;
+ struct dom_sid exp_sid = {1, 5, {0, 0, 0, 0, 0, 5},
+ {21, 2127521184, 1604012920, 1887927527, 72713,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
+
+ ret = string_to_sid(NULL, &sid);
+ assert_int_equal(ret, EINVAL);
+
+ ret = string_to_sid("abc", &sid);
+ assert_int_equal(ret, EINVAL);
+
+ ret = string_to_sid("S-", &sid);
+ assert_int_equal(ret, EINVAL);
+
+ ret = string_to_sid("S-ABC", &sid);
+ assert_int_equal(ret, EINVAL);
+
+ ret = string_to_sid("S-123", &sid);
+ assert_int_equal(ret, EINVAL);
+
+ ret = string_to_sid("S-1-123-1-2-3-4-5-6-7-8-9-0-1-2-3-4-5-6", &sid);
+ assert_int_equal(ret, EINVAL);
+
+ ret = string_to_sid("S-1-5-21-2127521184-1604012920-1887927527-72713",
+ &sid);
+ assert_int_equal(ret, 0);
+ assert_memory_equal(&exp_sid, &sid, sizeof(struct dom_sid));
+}
+
+void test_dom_sid_string(void **state)
+{
+ struct test_ctx *test_ctx;
+ char *str_sid;
+ struct dom_sid test_sid = {1, 5, {0, 0, 0, 0, 0, 5},
+ {21, 2127521184, 1604012920, 1887927527, 72713,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
+
+ test_ctx = (struct test_ctx *) *state;
+
+ str_sid = dom_sid_string(test_ctx, NULL);
+ assert_null(str_sid);
+
+ str_sid = dom_sid_string(test_ctx, &test_sid);
+ assert_non_null(str_sid);
+ assert_string_equal(str_sid,
+ "S-1-5-21-2127521184-1604012920-1887927527-72713");
+
+ test_sid.num_auths = -3;
+ str_sid = dom_sid_string(test_ctx, &test_sid);
+
+ test_sid.num_auths = 16;
+ str_sid = dom_sid_string(test_ctx, &test_sid);
+}
+
+
int main(int argc, const char *argv[])
{
const UnitTest tests[] = {
unit_test_setup_teardown(test_get_authz_data_types, setup, teardown),
unit_test_setup_teardown(test_filter_logon_info, setup, teardown),
+ unit_test(test_string_to_sid),
+ unit_test_setup_teardown(test_dom_sid_string, setup, teardown),
};
return run_tests(tests);