summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorPavel Březina <pbrezina@redhat.com>2014-12-16 15:19:05 +0100
committerJakub Hrozek <jhrozek@redhat.com>2015-01-23 21:45:38 +0100
commit3a8f6b575f4019f21c9425a26f1b346c08a197ae (patch)
treee640b5e6302b48b38ef3a3172f1e58a3500a74ff /src/tests
parent51d65c4ad15c2cc23f38fa09dd6efeb15e4f3e86 (diff)
downloadsssd-3a8f6b575f4019f21c9425a26f1b346c08a197ae.tar.gz
sssd-3a8f6b575f4019f21c9425a26f1b346c08a197ae.tar.xz
sssd-3a8f6b575f4019f21c9425a26f1b346c08a197ae.zip
sbus: move common opath functions from ifp to sbus code
These functions are quite general thus they may be part of sbus interface. Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/cmocka/test_ifp.c98
-rw-r--r--src/tests/cmocka/test_sbus_opath.c157
2 files changed, 157 insertions, 98 deletions
diff --git a/src/tests/cmocka/test_ifp.c b/src/tests/cmocka/test_ifp.c
index 5793f9191..484ab8568 100644
--- a/src/tests/cmocka/test_ifp.c
+++ b/src/tests/cmocka/test_ifp.c
@@ -134,14 +134,6 @@ void ifp_test_req_wrong_uid(void **state)
assert_true(leak_check_teardown());
}
-void test_path_prefix(void **state)
-{
- const char *prefix = "foo";
-
- assert_non_null(ifp_path_strip_prefix("foobar", prefix));
- assert_null(ifp_path_strip_prefix("notfoo", prefix));
-}
-
void test_el_to_dict(void **state)
{
static struct sbus_request *sr;
@@ -362,64 +354,6 @@ void test_attr_allowed(void **state)
assert_false(ifp_attr_allowed(NULL, "name"));
}
-void test_path_escape_unescape(void **state)
-{
- char *escaped;
- char *raw;
- TALLOC_CTX *mem_ctx;
-
- assert_true(leak_check_setup());
- mem_ctx = talloc_new(global_talloc_context);
-
- escaped = ifp_bus_path_escape(mem_ctx, "noescape");
- assert_non_null(escaped);
- assert_string_equal(escaped, "noescape");
- raw = ifp_bus_path_unescape(mem_ctx, escaped);
- talloc_free(escaped);
- assert_non_null(raw);
- assert_string_equal(raw, "noescape");
- talloc_free(raw);
-
- escaped = ifp_bus_path_escape(mem_ctx, "redhat.com");
- assert_non_null(escaped);
- assert_string_equal(escaped, "redhat_2ecom"); /* dot is 0x2E in ASCII */
- raw = ifp_bus_path_unescape(mem_ctx, escaped);
- talloc_free(escaped);
- assert_non_null(raw);
- assert_string_equal(raw, "redhat.com");
- talloc_free(raw);
-
- escaped = ifp_bus_path_escape(mem_ctx, "path_with_underscore");
- assert_non_null(escaped);
- /* underscore is 0x5F in ascii */
- assert_string_equal(escaped, "path_5fwith_5funderscore");
- raw = ifp_bus_path_unescape(mem_ctx, escaped);
- talloc_free(escaped);
- assert_non_null(raw);
- assert_string_equal(raw, "path_with_underscore");
- talloc_free(raw);
-
- /* empty string */
- escaped = ifp_bus_path_escape(mem_ctx, "");
- assert_non_null(escaped);
- assert_string_equal(escaped, "_");
- raw = ifp_bus_path_unescape(mem_ctx, escaped);
- talloc_free(escaped);
- assert_non_null(raw);
- assert_string_equal(raw, "");
- talloc_free(raw);
-
- /* negative tests */
- escaped = ifp_bus_path_escape(mem_ctx, NULL);
- assert_null(escaped);
- raw = ifp_bus_path_unescape(mem_ctx, "wrongpath_");
- assert_null(raw);
-
- assert_true(leak_check_teardown());
-}
-
-#define PATH_BASE "/some/path"
-
struct ifp_test_req_ctx {
struct ifp_req *ireq;
struct sbus_request *sr;
@@ -462,32 +396,6 @@ void ifp_test_req_teardown(void **state)
assert_true(leak_check_teardown());
}
-void test_reply_path(void **state)
-{
- struct ifp_test_req_ctx *test_ctx = talloc_get_type_abort(*state,
- struct ifp_test_req_ctx);
- char *path;
-
- /* Doesn't need escaping */
- path = ifp_reply_objpath(test_ctx->ireq, PATH_BASE, "domname", NULL);
- assert_non_null(path);
- assert_string_equal(path, PATH_BASE"/domname");
- talloc_free(path);
-}
-
-void test_reply_path_escape(void **state)
-{
- struct ifp_test_req_ctx *test_ctx = talloc_get_type_abort(*state,
- struct ifp_test_req_ctx);
- char *path;
-
- /* A dot needs escaping */
- path = ifp_reply_objpath(test_ctx->ireq, PATH_BASE, "redhat.com", NULL);
- assert_non_null(path);
- assert_string_equal(path, PATH_BASE"/redhat_2ecom");
- talloc_free(path);
-}
-
int main(int argc, const char *argv[])
{
poptContext pc;
@@ -501,17 +409,11 @@ int main(int argc, const char *argv[])
const UnitTest tests[] = {
unit_test(ifp_test_req_create),
unit_test(ifp_test_req_wrong_uid),
- unit_test(test_path_prefix),
unit_test_setup_teardown(test_el_to_dict,
ifp_test_req_setup, ifp_test_req_teardown),
unit_test(test_attr_acl),
unit_test(test_attr_acl_ex),
unit_test(test_attr_allowed),
- unit_test(test_path_escape_unescape),
- unit_test_setup_teardown(test_reply_path,
- ifp_test_req_setup, ifp_test_req_teardown),
- unit_test_setup_teardown(test_reply_path_escape,
- ifp_test_req_setup, ifp_test_req_teardown),
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
diff --git a/src/tests/cmocka/test_sbus_opath.c b/src/tests/cmocka/test_sbus_opath.c
new file mode 100644
index 000000000..b526c8873
--- /dev/null
+++ b/src/tests/cmocka/test_sbus_opath.c
@@ -0,0 +1,157 @@
+/*
+ Authors:
+ Jakub Hrozek <jhrozek@redhat.com>
+ Pavel Březina <pbrezina@redhat.com>
+
+ Copyright (C) 2014 Red Hat
+
+ 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/>.
+*/
+
+#include <talloc.h>
+#include <errno.h>
+#include <popt.h>
+
+#include "sbus/sssd_dbus.h"
+#include "tests/cmocka/common_mock.h"
+#include "tests/common.h"
+
+void test_sbus_opath_strip_prefix(void **state)
+{
+ const char *prefix = "/org/freedesktop/sssd/";
+ const char *path = "/org/freedesktop/sssd/infopipe";
+ const char *strip;
+
+ strip = sbus_opath_strip_prefix(path, prefix);
+ assert_non_null(prefix);
+ assert_string_equal(strip, "infopipe");
+
+ strip = sbus_opath_strip_prefix("/other/path", prefix);
+ assert_null(strip);
+}
+
+void test_sbus_opath_escape_unescape(void **state)
+{
+ char *escaped;
+ char *raw;
+ TALLOC_CTX *mem_ctx;
+
+ assert_true(leak_check_setup());
+ mem_ctx = talloc_new(global_talloc_context);
+
+ escaped = sbus_opath_escape_part(mem_ctx, "noescape");
+ assert_non_null(escaped);
+ assert_string_equal(escaped, "noescape");
+ raw = sbus_opath_unescape_part(mem_ctx, escaped);
+ talloc_free(escaped);
+ assert_non_null(raw);
+ assert_string_equal(raw, "noescape");
+ talloc_free(raw);
+
+ escaped = sbus_opath_escape_part(mem_ctx, "redhat.com");
+ assert_non_null(escaped);
+ assert_string_equal(escaped, "redhat_2ecom"); /* dot is 0x2E in ASCII */
+ raw = sbus_opath_unescape_part(mem_ctx, escaped);
+ talloc_free(escaped);
+ assert_non_null(raw);
+ assert_string_equal(raw, "redhat.com");
+ talloc_free(raw);
+
+ escaped = sbus_opath_escape_part(mem_ctx, "path_with_underscore");
+ assert_non_null(escaped);
+ /* underscore is 0x5F in ascii */
+ assert_string_equal(escaped, "path_5fwith_5funderscore");
+ raw = sbus_opath_unescape_part(mem_ctx, escaped);
+ talloc_free(escaped);
+ assert_non_null(raw);
+ assert_string_equal(raw, "path_with_underscore");
+ talloc_free(raw);
+
+ /* empty string */
+ escaped = sbus_opath_escape_part(mem_ctx, "");
+ assert_non_null(escaped);
+ assert_string_equal(escaped, "_");
+ raw = sbus_opath_unescape_part(mem_ctx, escaped);
+ talloc_free(escaped);
+ assert_non_null(raw);
+ assert_string_equal(raw, "");
+ talloc_free(raw);
+
+ /* negative tests */
+ escaped = sbus_opath_escape_part(mem_ctx, NULL);
+ assert_null(escaped);
+ raw = sbus_opath_unescape_part(mem_ctx, "wrongpath_");
+ assert_null(raw);
+
+ assert_true(leak_check_teardown());
+}
+
+void test_sbus_opath_compose(void **state)
+{
+ char *path;
+
+ /* Doesn't need escaping */
+ path = sbus_opath_compose(NULL, "/base/path", "domname");
+ assert_non_null(path);
+ assert_string_equal(path, "/base/path/domname");
+ talloc_free(path);
+}
+
+void test_sbus_opath_compose_escape(void **state)
+{
+ char *path;
+
+ /* A dot needs escaping */
+ path = sbus_opath_compose(NULL, "/base/path", "redhat.com", NULL);
+ assert_non_null(path);
+ assert_string_equal(path, "/base/path/redhat_2ecom");
+ talloc_free(path);
+}
+
+int main(int argc, const char *argv[])
+{
+ poptContext pc;
+ int opt;
+ struct poptOption long_options[] = {
+ POPT_AUTOHELP
+ SSSD_DEBUG_OPTS
+ POPT_TABLEEND
+ };
+
+ const UnitTest tests[] = {
+ unit_test(test_sbus_opath_strip_prefix),
+ unit_test(test_sbus_opath_escape_unescape),
+ unit_test(test_sbus_opath_compose),
+ unit_test(test_sbus_opath_compose_escape),
+ };
+
+ /* Set debug level to invalid value so we can deside if -d 0 was used. */
+ debug_level = SSSDBG_INVALID;
+
+ pc = poptGetContext(argv[0], argc, argv, long_options, 0);
+ while((opt = poptGetNextOpt(pc)) != -1) {
+ switch(opt) {
+ default:
+ fprintf(stderr, "\nInvalid option %s: %s\n\n",
+ poptBadOption(pc, 0), poptStrerror(opt));
+ poptPrintUsage(pc, stderr, 0);
+ return 1;
+ }
+ }
+ poptFreeContext(pc);
+
+ DEBUG_CLI_INIT(debug_level);
+
+ return run_tests(tests);
+}