a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher Jakub Hrozek <jhrozek@redhat.com>
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher Copyright (C) 2013 Red Hat
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher SSSD tests: InfoPipe responder
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher This program is free software; you can redistribute it and/or modify
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher it under the terms of the GNU General Public License as published by
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher the Free Software Foundation; either version 3 of the License, or
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher (at your option) any later version.
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher This program is distributed in the hope that it will be useful,
3dfa09a826e5f63b4948462c2452937fc329834dJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
3dfa09a826e5f63b4948462c2452937fc329834dJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3dfa09a826e5f63b4948462c2452937fc329834dJakub Hrozek GNU General Public License for more details.
3dfa09a826e5f63b4948462c2452937fc329834dJakub Hrozek You should have received a copy of the GNU General Public License
3dfa09a826e5f63b4948462c2452937fc329834dJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
3dfa09a826e5f63b4948462c2452937fc329834dJakub Hrozek/* dbus library checks for valid object paths when unit testing, we don't
3dfa09a826e5f63b4948462c2452937fc329834dJakub Hrozek * want that */
3dfa09a826e5f63b4948462c2452937fc329834dJakub Hrozekstatic struct ifp_ctx *
3dfa09a826e5f63b4948462c2452937fc329834dJakub Hrozek ifp_ctx = talloc_zero(mem_ctx, struct ifp_ctx);
3dfa09a826e5f63b4948462c2452937fc329834dJakub Hrozek ifp_ctx->rctx = mock_rctx(ifp_ctx, NULL, NULL, NULL);
3dfa09a826e5f63b4948462c2452937fc329834dJakub Hrozek ifp_ctx->rctx->allowed_uids = talloc_array(ifp_ctx->rctx, uint32_t, 1);
3dfa09a826e5f63b4948462c2452937fc329834dJakub Hrozek ifp_ctx->sysbus = talloc_zero(ifp_ctx, struct sysbus_ctx);
3dfa09a826e5f63b4948462c2452937fc329834dJakub Hrozek ifp_ctx->sysbus->conn = talloc_zero(ifp_ctx, struct sbus_connection);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallaghermock_sbus_request(TALLOC_CTX *mem_ctx, uid_t client)
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher sr = talloc_zero(mem_ctx, struct sbus_request);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher sr->conn = talloc_zero(sr, struct sbus_connection);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher sr->message = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher ifp_ctx = mock_ifp_ctx(global_talloc_context);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher sr = mock_sbus_request(ifp_ctx, geteuid());
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher assert_true(check_leaks_pop(ifp_ctx) == true);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher ifp_ctx = mock_ifp_ctx(global_talloc_context);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher sr = mock_sbus_request(ifp_ctx, geteuid()+1);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher assert_true(check_leaks_pop(ifp_ctx) == true);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher sr = mock_sbus_request(global_talloc_context, geteuid());
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher el = talloc(sr, struct ldb_message_element);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher el->values = talloc_array(el, struct ldb_val, 2);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher el->values[0].data = (uint8_t *) discard_const("one");
67ca9e7c006d8619f446c018eabf29eab1368ba5Ondrej Kos el->values[1].data = (uint8_t *) discard_const("two");
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher dbus_message_iter_init_append(sr->message, &iter);
13aea9c2b9c48dd614095b4551021868812ba2f0Pavel Reichl dbret = dbus_message_iter_close_container(&iter, &iter_dict);
13aea9c2b9c48dd614095b4551021868812ba2f0Pavel Reichl /* Test the reply contains what we expect */
13aea9c2b9c48dd614095b4551021868812ba2f0Pavel Reichl assert_int_equal(dbus_message_iter_get_arg_type(&iter),
d9de4b26f44a344025bbfa23104b7b67935fae35Pavel Reichl assert_int_equal(dbus_message_iter_get_arg_type(&iter),
13aea9c2b9c48dd614095b4551021868812ba2f0Pavel Reichl dbus_message_iter_get_basic(&iter_dict, &attr_name);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher assert_int_equal(dbus_message_iter_get_arg_type(&iter_dict),
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher dbus_message_iter_recurse(&iter_dict, &iter_dict);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher assert_int_equal(dbus_message_iter_get_arg_type(&iter_dict),
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher dbus_message_iter_recurse(&iter_dict, &iter_dict);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher dbus_message_iter_get_basic(&iter_dict, &attr_val);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher assert_true(dbus_message_iter_next(&iter_dict));
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher dbus_message_iter_get_basic(&iter_dict, &attr_val);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher assert_false(dbus_message_iter_next(&iter_dict));
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagherstatic void assert_string_list_equal(const char **s1,
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher const char **s2)
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher for (i=0; s1[i]; i++) {
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagherstatic void attr_parse_test(const char *expected[], const char *input)
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher res = ifp_parse_user_attr_list(test_ctx, input);
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher /* Positive test */
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher /* Negative test */
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagherstatic void attr_parse_test_ex(const char *expected[], const char *input,
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl res = parse_attr_list_ex(test_ctx, input, defaults);
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* Positive test */
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl /* Negative test */
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher /* Test defaults */
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher const char *exp_defaults[] = { SYSDB_NAME, SYSDB_UIDNUM,
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose /* Test adding some attributes to the defaults */
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose const char *exp_add[] = { "telephoneNumber", "streetAddress",
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose attr_parse_test(exp_add, "+telephoneNumber, +streetAddress");
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose /* Test removing some attributes to the defaults */
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose attr_parse_test(exp_rm, "-"SYSDB_SHELL ",-"SYSDB_UIDNUM);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose /* Test both add and remove */
781b04eb4b1d103120d736b81f1a74ea76a72947Jakub Hrozek attr_parse_test(exp_add_rm, "+telephoneNumber, -"SYSDB_SHELL);
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose /* Test rm trumps add */
36c266d467e9105041b33e9b1cdcd9ff073d893eSumit Bose const char *exp_add_rm_override[] = { SYSDB_NAME, SYSDB_UIDNUM,
a23919ed39d212f9f5694d9b103c84641fdb7680Stephen Gallagher "+telephoneNumber, -telephoneNumber, +telephoneNumber");
NULL };
NULL };
struct ifp_test_req_ctx);
switch(opt) {