From: Adrian Szyndela Date: Thu, 9 Apr 2020 07:05:50 +0000 (+0200) Subject: tests: test multiple includedirs directive X-Git-Tag: accepted/tizen/6.0/unified/20201030.115601~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0a3ba72cc2532650afe3485b0a2b77739faefcec;p=platform%2Fcore%2Fsystem%2Flibdbuspolicy.git tests: test multiple includedirs directive This adds a test which checks if the files in all the directories specified in all the directives are parsed. It breaks the checks during building as it exposes a bug. The subsequent commit fixes the bug. Change-Id: I020246138586357717dbee73617182f79176eac9 --- diff --git a/Makefile.am b/Makefile.am index 9f2c98d..aad84e6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -150,7 +150,8 @@ TESTS = src/test-libdbuspolicy1-ownership \ src/test-libdbuspolicy1-access-deny-gdi \ src/test-libdbuspolicy1-send_destination_prefix-deny \ src/test-libdbuspolicy1-send_destination_prefix-deny-gdi \ - src/test-serializer + src/test-serializer \ + src/test-libdbuspolicy1-multiple-includedirs check_PROGRAMS = $(TESTS) @@ -167,6 +168,7 @@ src_test_libdbuspolicy1_access_deny_gdi_SOURCES = src/test-libdbuspolicy1-access src_test_libdbuspolicy1_send_destination_prefix_deny_SOURCES = src/test-libdbuspolicy1-send_destination_prefix-deny.cpp src_test_libdbuspolicy1_send_destination_prefix_deny_gdi_SOURCES = src/test-libdbuspolicy1-send_destination_prefix-deny-gdi.cpp src_test_serializer_SOURCES = src/test-serializer.cpp +src_test_libdbuspolicy1_multiple_includedirs_SOURCES = src/test-libdbuspolicy1-multiple-includedirs.cpp noinst_LTLIBRARIES = src/libinternal.la src_libinternal_la_SOURCES =\ @@ -193,6 +195,7 @@ src_test_libdbuspolicy1_access_deny_gdi_LDADD = $(TESTS_LDADD) src_test_libdbuspolicy1_send_destination_prefix_deny_LDADD = $(TESTS_LDADD) src_test_libdbuspolicy1_send_destination_prefix_deny_gdi_LDADD = $(TESTS_LDADD) src_test_serializer_LDADD = $(TESTS_LDADD) +src_test_libdbuspolicy1_multiple_includedirs_LDADD = $(TESTS_LDADD) if ENABLE_STANDALONE_TESTS noinst_LTLIBRARIES += src/libinternalfortests.la diff --git a/src/test-libdbuspolicy1-multiple-includedirs.cpp b/src/test-libdbuspolicy1-multiple-includedirs.cpp new file mode 100644 index 0000000..abdb0e8 --- /dev/null +++ b/src/test-libdbuspolicy1-multiple-includedirs.cpp @@ -0,0 +1,35 @@ +#include "internal/naive_policy_checker.hpp" +#include "internal/tslog.hpp" + +#include +#include + +ldp_xml_parser::Decision test_destination(const ldp_serialized::StorageBackendSerialized &db, const char *destination) { + KdbusBusNames names; + ldp_xml_parser::MatchItemSend item("ex.ample.interface", "ExampleMember", "/Ex/Ample/Path", + ldp_xml_parser::MessageType::METHOD_CALL, names.addSpaceSeparatedNames(destination)); + + return db.getDecisionItemUser(0, item).getDecision(); +} + +#define tassert(COND) do { if (!(COND)) throw std::runtime_error("test failed: " #COND); } while (0) + +int main() try { + tslog::init(); + + auto &checker = policy_checker_system(); + checker.initDb("tests/default_deny/system-multiple-includedirs.conf"); + + auto &db = checker.getPolicyDb(); + tassert(test_destination(db, "org.tizen.test.allow-me-for-root") == ldp_xml_parser::Decision::ALLOW); + tassert(test_destination(db, "org.tizen.test.deny-me-for-root") == ldp_xml_parser::Decision::DENY); + tassert(test_destination(db, "org.tizen.test.another-allow-me-for-root") == ldp_xml_parser::Decision::ALLOW); + tassert(test_destination(db, "org.tizen.test.another-deny-me-for-root") == ldp_xml_parser::Decision::DENY); + tassert(test_destination(db, "org.tizen.test.yet-another-allow-me-for-root") == ldp_xml_parser::Decision::ALLOW); + tassert(test_destination(db, "org.tizen.test.yet-another-deny-me-for-root") == ldp_xml_parser::Decision::DENY); + + return 0; +} catch (std::runtime_error &e) { + std::cerr << e.what(); + return 1; +} diff --git a/tests/default_deny/another-system.d/some-service.conf b/tests/default_deny/another-system.d/some-service.conf new file mode 100644 index 0000000..fae3d97 --- /dev/null +++ b/tests/default_deny/another-system.d/some-service.conf @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/tests/default_deny/system-multiple-includedirs.conf b/tests/default_deny/system-multiple-includedirs.conf new file mode 100644 index 0000000..99a7a2e --- /dev/null +++ b/tests/default_deny/system-multiple-includedirs.conf @@ -0,0 +1,20 @@ + + + + + + + + system-base.conf + + another-system.d + yet-another-system.d + + + diff --git a/tests/default_deny/system.d/some-service.conf b/tests/default_deny/system.d/some-service.conf new file mode 100644 index 0000000..4252922 --- /dev/null +++ b/tests/default_deny/system.d/some-service.conf @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/tests/default_deny/yet-another-system.d/some-service.conf b/tests/default_deny/yet-another-system.d/some-service.conf new file mode 100644 index 0000000..4ec24e9 --- /dev/null +++ b/tests/default_deny/yet-another-system.d/some-service.conf @@ -0,0 +1,12 @@ + + + + + + + + + +