[Freeipa-devel] [PATCH 140] extdom: migrate check-based test to cmocka
Sumit Bose
sbose at redhat.com
Wed Mar 18 12:32:58 UTC 2015
On Wed, Mar 18, 2015 at 12:53:04PM +0100, Martin Kosek wrote:
> On 03/18/2015 11:22 AM, Jakub Hrozek wrote:
> > On Wed, Mar 18, 2015 at 11:01:35AM +0100, Sumit Bose wrote:
> >> On Fri, Mar 13, 2015 at 03:14:55PM +0100, Jakub Hrozek wrote:
> >>> On Fri, Mar 13, 2015 at 11:56:46AM +0100, Sumit Bose wrote:
> >>>> On Wed, Mar 04, 2015 at 06:42:05PM +0100, Sumit Bose wrote:
> >>>>> Hi,
> >>>>>
> >>>>> this is the first patch for https://fedorahosted.org/freeipa/ticket/4922
> >>>>> which converts the check-based tests of the extdom plugin to cmocka.
> >>>>>
> >>>>> bye,
> >>>>> Sumit
> >>>>
> >>>> Rebased version attached.
> >>>>
> >>>> bye,
> >>>> Sumit
> >>>
> >>> The test itself is fine, but did freeipa consider moving to cmocka-1.0+
> >>> to avoid warnings like:
> >>> ipa_extdom_cmocka_tests.c: In function ‘main’:
> >>> ipa_extdom_cmocka_tests.c:408:5: warning: ‘_run_tests’ is deprecated
> >>> (declared at /usr/include/cmocka.h:2001) [-Wdeprecated-declarations]
> >>> return run_tests(tests);
> >>>
> >>> But I'm fine with ACKing this patch, the conversion should be done
> >>> separately.
> >>
> >> yes, I found it more flexible to use the old style now because it works
> >> with all versions of cmocka. When I converted the remaining check based
> >> test to cmocka I will provide a patch which will switch all to the new
> >> version.
> >>
> >> bye,
> >> Sumit
> >
> > Sure, ACK
> >
> > (sorry, from my point of view it was obvious I was OK with pushing even
> > the previous version. Hopefully it's even clearer now :-))
> >
>
> Thanks for this work guys! I would push it, but there is a conflict in ipa_extdom.
Rebased version attached.
bye,
Sumit
-------------- next part --------------
From cedaaba614dad266e5f5e90eafedf2b173b96c12 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Mon, 9 Feb 2015 18:12:01 +0100
Subject: [PATCH] extdom: migrate check-based test to cmocka
Besides moving the existing tests to cmocka two new tests are added
which were missing from the old tests.
Related to https://fedorahosted.org/freeipa/ticket/4922
---
.../ipa-slapi-plugins/ipa-extdom-extop/Makefile.am | 20 --
.../ipa-extdom-extop/ipa_extdom.h | 14 ++
.../ipa-extdom-extop/ipa_extdom_cmocka_tests.c | 156 +++++++++++++++-
.../ipa-extdom-extop/ipa_extdom_common.c | 28 +--
.../ipa-extdom-extop/ipa_extdom_tests.c | 203 ---------------------
5 files changed, 176 insertions(+), 245 deletions(-)
delete mode 100644 daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom_tests.c
diff --git a/daemons/ipa-slapi-plugins/ipa-extdom-extop/Makefile.am b/daemons/ipa-slapi-plugins/ipa-extdom-extop/Makefile.am
index a1679812ef3c5de8c6e18433cbb991a99ad0b6c8..9c2fa1c6a5f95ba06b33c0a5b560939863a88f0e 100644
--- a/daemons/ipa-slapi-plugins/ipa-extdom-extop/Makefile.am
+++ b/daemons/ipa-slapi-plugins/ipa-extdom-extop/Makefile.am
@@ -38,11 +38,6 @@ libipa_extdom_extop_la_LIBADD = \
TESTS =
check_PROGRAMS =
-if HAVE_CHECK
-TESTS += extdom_tests
-check_PROGRAMS += extdom_tests
-endif
-
if HAVE_CMOCKA
if HAVE_NSS_WRAPPER
TESTS_ENVIRONMENT = . ./test_data/test_setup.sh;
@@ -51,21 +46,6 @@ check_PROGRAMS += extdom_cmocka_tests
endif
endif
-extdom_tests_SOURCES = \
- ipa_extdom_tests.c \
- ipa_extdom_common.c \
- $(NULL)
-extdom_tests_CFLAGS = $(CHECK_CFLAGS)
-extdom_tests_LDFLAGS = \
- -rpath $(shell pkg-config --libs-only-L dirsrv | sed -e 's/-L//') \
- $(NULL)
-extdom_tests_LDADD = \
- $(CHECK_LIBS) \
- $(LDAP_LIBS) \
- $(DIRSRV_LIBS) \
- $(SSSNSSIDMAP_LIBS) \
- $(NULL)
-
extdom_cmocka_tests_SOURCES = \
ipa_extdom_cmocka_tests.c \
ipa_extdom_common.c \
diff --git a/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom.h b/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom.h
index 0d5d55d2fb0ece95466b0225b145a4edeef18efa..65dd43ea35726db6231386a0fcbba9be1bd71412 100644
--- a/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom.h
+++ b/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom.h
@@ -185,5 +185,19 @@ int getgrnam_r_wrapper(size_t buf_max, const char *name,
struct group *grp, char **_buf, size_t *_buf_len);
int getgrgid_r_wrapper(size_t buf_max, gid_t gid,
struct group *grp, char **_buf, size_t *_buf_len);
+int pack_ber_sid(const char *sid, struct berval **berval);
+int pack_ber_name(const char *domain_name, const char *name,
+ struct berval **berval);
+int pack_ber_user(struct ipa_extdom_ctx *ctx,
+ enum response_types response_type,
+ const char *domain_name, const char *user_name,
+ uid_t uid, gid_t gid,
+ const char *gecos, const char *homedir,
+ const char *shell, struct sss_nss_kv *kv_list,
+ struct berval **berval);
+int pack_ber_group(enum response_types response_type,
+ const char *domain_name, const char *group_name,
+ gid_t gid, char **members, struct sss_nss_kv *kv_list,
+ struct berval **berval);
void set_err_msg(struct extdom_req *req, const char *format, ...);
#endif /* _IPA_EXTDOM_H_ */
diff --git a/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom_cmocka_tests.c b/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom_cmocka_tests.c
index 586b58b0fd4c7610e9cb4643b6dae04f9d22b8ab..42d588d08a96f8a26345f85aade9523e05f6f56e 100644
--- a/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom_cmocka_tests.c
+++ b/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom_cmocka_tests.c
@@ -213,30 +213,46 @@ void test_getgrgid_r_wrapper(void **state)
free(buf);
}
+struct test_data {
+ struct extdom_req *req;
+ struct ipa_extdom_ctx *ctx;
+};
+
void extdom_req_setup(void **state)
{
- struct extdom_req *req;
+ struct test_data *test_data;
- req = calloc(sizeof(struct extdom_req), 1);
- assert_non_null(req);
+ test_data = calloc(sizeof(struct test_data), 1);
+ assert_non_null(test_data);
- *state = req;
+ test_data->req = calloc(sizeof(struct extdom_req), 1);
+ assert_non_null(test_data->req);
+
+ test_data->ctx = calloc(sizeof(struct ipa_extdom_ctx), 1);
+ assert_non_null(test_data->req);
+
+ *state = test_data;
}
void extdom_req_teardown(void **state)
{
- struct extdom_req *req;
+ struct test_data *test_data;
- req = (struct extdom_req *) *state;
+ test_data = (struct test_data *) *state;
- free_req_data(req);
+ free_req_data(test_data->req);
+ free(test_data->ctx);
+ free(test_data);
}
void test_set_err_msg(void **state)
{
struct extdom_req *req;
+ struct test_data *test_data;
+
+ test_data = (struct test_data *) *state;
+ req = test_data->req;
- req = (struct extdom_req *) *state;
assert_null(req->err_msg);
set_err_msg(NULL, NULL);
@@ -254,6 +270,127 @@ void test_set_err_msg(void **state)
assert_string_equal(req->err_msg, "Test [ABCD][1234].");
}
+#define TEST_SID "S-1-2-3-4"
+#define TEST_DOMAIN_NAME "DOMAIN"
+
+char res_sid[] = {0x30, 0x0e, 0x0a, 0x01, 0x01, 0x04, 0x09, 0x53, 0x2d, 0x31, \
+ 0x2d, 0x32, 0x2d, 0x33, 0x2d, 0x34};
+char res_nam[] = {0x30, 0x13, 0x0a, 0x01, 0x02, 0x30, 0x0e, 0x04, 0x06, 0x44, \
+ 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x04, 0x04, 0x74, 0x65, 0x73, \
+ 0x74};
+char res_uid[] = {0x30, 0x1c, 0x0a, 0x01, 0x03, 0x30, 0x17, 0x04, 0x06, 0x44, \
+ 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x04, 0x04, 0x74, 0x65, 0x73, \
+ 0x74, 0x02, 0x02, 0x30, 0x39, 0x02, 0x03, 0x00, 0xd4, 0x31};
+char res_gid[] = {0x30, 0x1e, 0x0a, 0x01, 0x04, 0x30, 0x19, 0x04, 0x06, 0x44, \
+ 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x04, 0x0a, 0x74, 0x65, 0x73, \
+ 0x74, 0x5f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x02, 0x03, 0x00, \
+ 0xd4, 0x31};
+
+void test_encode(void **state)
+{
+ int ret;
+ struct berval *resp_val;
+ struct ipa_extdom_ctx *ctx;
+ struct test_data *test_data;
+
+ test_data = (struct test_data *) *state;
+ ctx = test_data->ctx;
+
+ ctx->max_nss_buf_size = (128*1024*1024);
+
+ ret = pack_ber_sid(TEST_SID, &resp_val);
+ assert_int_equal(ret, LDAP_SUCCESS);
+ assert_int_equal(sizeof(res_sid), resp_val->bv_len);
+ assert_memory_equal(res_sid, resp_val->bv_val, resp_val->bv_len);
+ ber_bvfree(resp_val);
+
+ ret = pack_ber_name(TEST_DOMAIN_NAME, "test", &resp_val);
+ assert_int_equal(ret, LDAP_SUCCESS);
+ assert_int_equal(sizeof(res_nam), resp_val->bv_len);
+ assert_memory_equal(res_nam, resp_val->bv_val, resp_val->bv_len);
+ ber_bvfree(resp_val);
+
+ ret = pack_ber_user(ctx, RESP_USER, TEST_DOMAIN_NAME, "test", 12345, 54321,
+ NULL, NULL, NULL, NULL, &resp_val);
+ assert_int_equal(ret, LDAP_SUCCESS);
+ assert_int_equal(sizeof(res_uid), resp_val->bv_len);
+ assert_memory_equal(res_uid, resp_val->bv_val, resp_val->bv_len);
+ ber_bvfree(resp_val);
+
+ ret = pack_ber_group(RESP_GROUP, TEST_DOMAIN_NAME, "test_group", 54321,
+ NULL, NULL, &resp_val);
+ assert_int_equal(ret, LDAP_SUCCESS);
+ assert_int_equal(sizeof(res_gid), resp_val->bv_len);
+ assert_memory_equal(res_gid, resp_val->bv_val, resp_val->bv_len);
+ ber_bvfree(resp_val);
+}
+
+char req_sid[] = {0x30, 0x11, 0x0a, 0x01, 0x01, 0x0a, 0x01, 0x01, 0x04, 0x09, \
+ 0x53, 0x2d, 0x31, 0x2d, 0x32, 0x2d, 0x33, 0x2d, 0x34};
+char req_nam[] = {0x30, 0x16, 0x0a, 0x01, 0x02, 0x0a, 0x01, 0x01, 0x30, 0x0e, \
+ 0x04, 0x06, 0x44, 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x04, 0x04, \
+ 0x74, 0x65, 0x73, 0x74};
+char req_uid[] = {0x30, 0x14, 0x0a, 0x01, 0x03, 0x0a, 0x01, 0x01, 0x30, 0x0c, \
+ 0x04, 0x06, 0x44, 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x02, 0x02, \
+ 0x30, 0x39};
+char req_gid[] = {0x30, 0x15, 0x0a, 0x01, 0x04, 0x0a, 0x01, 0x01, 0x30, 0x0d, \
+ 0x04, 0x06, 0x44, 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x02, 0x03, \
+ 0x00, 0xd4, 0x31};
+
+void test_decode(void **state)
+{
+ struct berval req_val;
+ struct extdom_req *req;
+ int ret;
+
+ req_val.bv_val = req_sid;
+ req_val.bv_len = sizeof(req_sid);
+
+ ret = parse_request_data(&req_val, &req);
+
+ assert_int_equal(ret, LDAP_SUCCESS);
+ assert_int_equal(req->input_type, INP_SID);
+ assert_int_equal(req->request_type, REQ_SIMPLE);
+ assert_string_equal(req->data.sid, "S-1-2-3-4");
+ free_req_data(req);
+
+ req_val.bv_val = req_nam;
+ req_val.bv_len = sizeof(req_nam);
+
+ ret = parse_request_data(&req_val, &req);
+
+ assert_int_equal(ret, LDAP_SUCCESS);
+ assert_int_equal(req->input_type, INP_NAME);
+ assert_int_equal(req->request_type, REQ_SIMPLE);
+ assert_string_equal(req->data.name.domain_name, "DOMAIN");
+ assert_string_equal(req->data.name.object_name, "test");
+ free_req_data(req);
+
+ req_val.bv_val = req_uid;
+ req_val.bv_len = sizeof(req_uid);
+
+ ret = parse_request_data(&req_val, &req);
+
+ assert_int_equal(ret, LDAP_SUCCESS);
+ assert_int_equal(req->input_type, INP_POSIX_UID);
+ assert_int_equal(req->request_type, REQ_SIMPLE);
+ assert_string_equal(req->data.posix_uid.domain_name, "DOMAIN");
+ assert_int_equal(req->data.posix_uid.uid, 12345);
+ free_req_data(req);
+
+ req_val.bv_val = req_gid;
+ req_val.bv_len = sizeof(req_gid);
+
+ ret = parse_request_data(&req_val, &req);
+
+ assert_int_equal(ret, LDAP_SUCCESS);
+ assert_int_equal(req->input_type, INP_POSIX_GID);
+ assert_int_equal(req->request_type, REQ_SIMPLE);
+ assert_string_equal(req->data.posix_gid.domain_name, "DOMAIN");
+ assert_int_equal(req->data.posix_gid.gid, 54321);
+ free_req_data(req);
+}
+
int main(int argc, const char *argv[])
{
const UnitTest tests[] = {
@@ -263,6 +400,9 @@ int main(int argc, const char *argv[])
unit_test(test_getgrgid_r_wrapper),
unit_test_setup_teardown(test_set_err_msg,
extdom_req_setup, extdom_req_teardown),
+ unit_test_setup_teardown(test_encode,
+ extdom_req_setup, extdom_req_teardown),
+ unit_test(test_decode),
};
return run_tests(tests);
diff --git a/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom_common.c b/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom_common.c
index 4452d456bcabc211a0ca5814d24247c43cf95a91..2c08e56d65f8a1a9f33a29f1749936606f738ec5 100644
--- a/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom_common.c
+++ b/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom_common.c
@@ -464,7 +464,7 @@ static int add_kv_list(BerElement *ber, struct sss_nss_kv *kv_list)
return LDAP_SUCCESS;
}
-static int pack_ber_sid(const char *sid, struct berval **berval)
+int pack_ber_sid(const char *sid, struct berval **berval)
{
BerElement *ber = NULL;
int ret;
@@ -491,13 +491,13 @@ static int pack_ber_sid(const char *sid, struct berval **berval)
#define SSSD_SYSDB_SID_STR "objectSIDString"
-static int pack_ber_user(struct ipa_extdom_ctx *ctx,
- enum response_types response_type,
- const char *domain_name, const char *user_name,
- uid_t uid, gid_t gid,
- const char *gecos, const char *homedir,
- const char *shell, struct sss_nss_kv *kv_list,
- struct berval **berval)
+int pack_ber_user(struct ipa_extdom_ctx *ctx,
+ enum response_types response_type,
+ const char *domain_name, const char *user_name,
+ uid_t uid, gid_t gid,
+ const char *gecos, const char *homedir,
+ const char *shell, struct sss_nss_kv *kv_list,
+ struct berval **berval)
{
BerElement *ber = NULL;
int ret;
@@ -610,10 +610,10 @@ done:
return ret;
}
-static int pack_ber_group(enum response_types response_type,
- const char *domain_name, const char *group_name,
- gid_t gid, char **members, struct sss_nss_kv *kv_list,
- struct berval **berval)
+int pack_ber_group(enum response_types response_type,
+ const char *domain_name, const char *group_name,
+ gid_t gid, char **members, struct sss_nss_kv *kv_list,
+ struct berval **berval)
{
BerElement *ber = NULL;
int ret;
@@ -694,8 +694,8 @@ done:
return ret;
}
-static int pack_ber_name(const char *domain_name, const char *name,
- struct berval **berval)
+int pack_ber_name(const char *domain_name, const char *name,
+ struct berval **berval)
{
BerElement *ber = NULL;
int ret;
diff --git a/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom_tests.c b/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom_tests.c
deleted file mode 100644
index 1467e256619f827310408d558d48c580118d9a32..0000000000000000000000000000000000000000
--- a/daemons/ipa-slapi-plugins/ipa-extdom-extop/ipa_extdom_tests.c
+++ /dev/null
@@ -1,203 +0,0 @@
-/** BEGIN COPYRIGHT BLOCK
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Additional permission under GPLv3 section 7:
- *
- * In the following paragraph, "GPL" means the GNU General Public
- * License, version 3 or any later version, and "Non-GPL Code" means
- * code that is governed neither by the GPL nor a license
- * compatible with the GPL.
- *
- * You may link the code of this Program with Non-GPL Code and convey
- * linked combinations including the two, provided that such Non-GPL
- * Code only links to the code of this Program through those well
- * defined interfaces identified in the file named EXCEPTION found in
- * the source code files (the "Approved Interfaces"). The files of
- * Non-GPL Code may instantiate templates or use macros or inline
- * functions from the Approved Interfaces without causing the resulting
- * work to be covered by the GPL. Only the copyright holders of this
- * Program may make changes or additions to the list of Approved
- * Interfaces.
- *
- * Authors:
- * Sumit Bose <sbose at redhat.com>
- *
- * Copyright (C) 2011 Red Hat, Inc.
- * All rights reserved.
- * END COPYRIGHT BLOCK **/
-
-#include <check.h>
-
-#include "ipa_extdom.h"
-#include "util.h"
-
-char req_sid[] = {0x30, 0x11, 0x0a, 0x01, 0x01, 0x0a, 0x01, 0x01, 0x04, 0x09, \
- 0x53, 0x2d, 0x31, 0x2d, 0x32, 0x2d, 0x33, 0x2d, 0x34};
-char req_nam[] = {0x30, 0x16, 0x0a, 0x01, 0x02, 0x0a, 0x01, 0x01, 0x30, 0x0e, \
- 0x04, 0x06, 0x44, 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x04, 0x04, \
- 0x74, 0x65, 0x73, 0x74};
-char req_uid[] = {0x30, 0x14, 0x0a, 0x01, 0x03, 0x0a, 0x01, 0x01, 0x30, 0x0c, \
- 0x04, 0x06, 0x44, 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x02, 0x02, \
- 0x30, 0x39};
-char req_gid[] = {0x30, 0x15, 0x0a, 0x01, 0x04, 0x0a, 0x01, 0x01, 0x30, 0x0d, \
- 0x04, 0x06, 0x44, 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x02, 0x03, \
- 0x00, 0xd4, 0x31};
-
-char res_sid[] = {0x30, 0x0e, 0x0a, 0x01, 0x01, 0x04, 0x09, 0x53, 0x2d, 0x31, \
- 0x2d, 0x32, 0x2d, 0x33, 0x2d, 0x34};
-char res_nam[] = {0x30, 0x13, 0x0a, 0x01, 0x02, 0x30, 0x0e, 0x04, 0x06, 0x44, \
- 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x04, 0x04, 0x74, 0x65, 0x73, \
- 0x74};
-char res_uid[] = {0x30, 0x17, 0x0a, 0x01, 0x03, 0x30, 0x12, 0x04, 0x06, 0x44, \
- 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x04, 0x04, 0x74, 0x65, 0x73, \
- 0x74, 0x02, 0x02, 0x30, 0x39};
-char res_gid[] = {0x30, 0x1e, 0x0a, 0x01, 0x04, 0x30, 0x19, 0x04, 0x06, 0x44, \
- 0x4f, 0x4d, 0x41, 0x49, 0x4e, 0x04, 0x0a, 0x74, 0x65, 0x73, \
- 0x74, 0x5f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x02, 0x03, 0x00, \
- 0xd4, 0x31};
-
-#define TEST_SID "S-1-2-3-4"
-#define TEST_DOMAIN_NAME "DOMAIN"
-
-START_TEST(test_encode)
-{
- int ret;
- struct extdom_res res;
- struct berval *resp_val;
-
- res.response_type = RESP_SID;
- res.data.sid = TEST_SID;
-
- ret = pack_response(&res, &resp_val);
-
- fail_unless(ret == LDAP_SUCCESS, "pack_response() failed.");
- fail_unless(sizeof(res_sid) == resp_val->bv_len &&
- memcmp(res_sid, resp_val->bv_val, resp_val->bv_len) == 0,
- "Unexpected BER blob.");
- ber_bvfree(resp_val);
-
- res.response_type = RESP_NAME;
- res.data.name.domain_name = TEST_DOMAIN_NAME;
- res.data.name.object_name = "test";
-
- ret = pack_response(&res, &resp_val);
-
- fail_unless(ret == LDAP_SUCCESS, "pack_response() failed.");
- fail_unless(sizeof(res_nam) == resp_val->bv_len &&
- memcmp(res_nam, resp_val->bv_val, resp_val->bv_len) == 0,
- "Unexpected BER blob.");
- ber_bvfree(resp_val);
-}
-END_TEST
-
-START_TEST(test_decode)
-{
- struct berval req_val;
- struct extdom_req *req;
- int ret;
-
- req_val.bv_val = req_sid;
- req_val.bv_len = sizeof(req_sid);
-
- ret = parse_request_data(&req_val, &req);
-
- fail_unless(ret == LDAP_SUCCESS, "parse_request_data() failed.");
- fail_unless(req->input_type == INP_SID,
- "parse_request_data() returned unexpected input type");
- fail_unless(req->request_type == REQ_SIMPLE,
- "parse_request_data() returned unexpected request type");
- fail_unless(strcmp(req->data.sid, "S-1-2-3-4") == 0,
- "parse_request_data() returned unexpected sid");
- free_req_data(req);
-
- req_val.bv_val = req_nam;
- req_val.bv_len = sizeof(req_nam);
-
- ret = parse_request_data(&req_val, &req);
-
- fail_unless(ret == LDAP_SUCCESS,
- "parse_request_data() failed.");
- fail_unless(req->input_type == INP_NAME,
- "parse_request_data() returned unexpected input type");
- fail_unless(req->request_type == REQ_SIMPLE,
- "parse_request_data() returned unexpected request type");
- fail_unless(strcmp(req->data.name.domain_name, "DOMAIN") == 0,
- "parse_request_data() returned unexpected domain name");
- fail_unless(strcmp(req->data.name.object_name, "test") == 0,
- "parse_request_data() returned unexpected object name");
- free_req_data(req);
-
- req_val.bv_val = req_uid;
- req_val.bv_len = sizeof(req_uid);
-
- ret = parse_request_data(&req_val, &req);
-
- fail_unless(ret == LDAP_SUCCESS,
- "parse_request_data() failed.");
- fail_unless(req->input_type == INP_POSIX_UID,
- "parse_request_data() returned unexpected input type");
- fail_unless(req->request_type == REQ_SIMPLE,
- "parse_request_data() returned unexpected request type");
- fail_unless(strcmp(req->data.posix_uid.domain_name, "DOMAIN") == 0,
- "parse_request_data() returned unexpected domain name");
- fail_unless(req->data.posix_uid.uid == 12345,
- "parse_request_data() returned unexpected uid [%d]",
- req->data.posix_uid.uid);
- free_req_data(req);
-
- req_val.bv_val = req_gid;
- req_val.bv_len = sizeof(req_gid);
-
- ret = parse_request_data(&req_val, &req);
-
- fail_unless(ret == LDAP_SUCCESS,
- "parse_request_data() failed.");
- fail_unless(req->input_type == INP_POSIX_GID,
- "parse_request_data() returned unexpected input type");
- fail_unless(req->request_type == REQ_SIMPLE,
- "parse_request_data() returned unexpected request type");
- fail_unless(strcmp(req->data.posix_gid.domain_name, "DOMAIN") == 0,
- "parse_request_data() returned unexpected domain name");
- fail_unless(req->data.posix_gid.gid == 54321,
- "parse_request_data() returned unexpected gid [%d]",
- req->data.posix_gid.gid);
- free_req_data(req);
-}
-END_TEST
-
-Suite * ipa_extdom_suite(void)
-{
- Suite *s = suite_create("IPA extdom");
-
- TCase *tc_core = tcase_create("Core");
- tcase_add_test(tc_core, test_decode);
- tcase_add_test(tc_core, test_encode);
- /* TODO: add test for create_response() */
- suite_add_tcase(s, tc_core);
-
- return s;
-}
-
-int main(void)
-{
- int number_failed;
-
- Suite *s = ipa_extdom_suite ();
- SRunner *sr = srunner_create (s);
- srunner_run_all (sr, CK_VERBOSE);
- number_failed = srunner_ntests_failed (sr);
- srunner_free (sr);
-
- return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}
--
2.1.0
More information about the Freeipa-devel
mailing list