* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. */
-#include "internal/include/fb_generated.h"
-#include "internal/include/flatbuffers/flatbuffers.h"
#include "internal/policy_containers.hpp"
#include "internal/serializer.hpp"
+#include "internal/serialized_convert.hpp"
+#include "internal/storage_backend_serialized.hpp"
+#include <boost/utility/string_ref.hpp>
#include <cstdarg>
#include <iostream>
#include <ostream>
-namespace ldp_xml_parser {
+using ldp_serialized::makeDecision;
+using ldp_serialized::makeMessageType;
+using ldp_serialized::makeBusAccessType;
static void print_error(const char *fmt...) {
va_list args;
va_end(args);
}
-std::map<FB::MessageType, const char *> messageTypeMap = {
- { FB::MessageType_ANY, "ANY" },
- { FB::MessageType_MIN, "MIN" },
- { FB::MessageType_MAX, "MAX" },
- { FB::MessageType_METHOD_RETURN, "METHOD_RETURN" },
- { FB::MessageType_ERROR, "ERROR" },
- { FB::MessageType_SIGNAL, "SIGNAL" },
- { FB::MessageType_METHOD_CALL, "METHOD_CALL" }
+std::map<ldp_xml_parser::MessageType, const char *> messageTypeMap = {
+ { ldp_xml_parser::MessageType::ANY, "ANY" },
+ { ldp_xml_parser::MessageType::METHOD_RETURN, "METHOD_RETURN" },
+ { ldp_xml_parser::MessageType::ERROR, "ERROR" },
+ { ldp_xml_parser::MessageType::SIGNAL, "SIGNAL" },
+ { ldp_xml_parser::MessageType::METHOD_CALL, "METHOD_CALL" }
};
-std::map<FB::Decision, const char *> decisionTypeMap = {
- { FB::Decision_ANY, "ANY" },
- { FB::Decision_MIN, "MIN" },
- { FB::Decision_MAX, "MAX" },
- { FB::Decision_CHECK, "CHECK" },
- { FB::Decision_DENY, "DENY" },
- { FB::Decision_ALLOW, "ALLOW" }
+std::map<ldp_xml_parser::Decision, const char *> decisionTypeMap = {
+ { ldp_xml_parser::Decision::ANY, "ANY" },
+ { ldp_xml_parser::Decision::CHECK, "CHECK" },
+ { ldp_xml_parser::Decision::DENY, "DENY" },
+ { ldp_xml_parser::Decision::ALLOW, "ALLOW" }
};
-std::map<FB::BusAccessType, const char *> busTypeMap = {
- { FB::BusAccessType_MIN, "MIN" },
- { FB::BusAccessType_MAX, "MAX" },
- { FB::BusAccessType_USER, "USER" },
- { FB::BusAccessType_GROUP, "GROUP" },
- { FB::BusAccessType_ALL_USERS, "ALL_USERS" },
- { FB::BusAccessType_ALL_GROUPS, "ALL_GROUPS" },
+std::map<ldp_xml_parser::BusAccessType, const char *> busTypeMap = {
+ { ldp_xml_parser::BusAccessType::USER, "USER" },
+ { ldp_xml_parser::BusAccessType::GROUP, "GROUP" },
+ { ldp_xml_parser::BusAccessType::ALL_USERS, "ALL_USERS" },
+ { ldp_xml_parser::BusAccessType::ALL_GROUPS, "ALL_GROUPS" },
};
struct TestsHelper {
return value.c_str();
}
- static const char *to_str(const FB::MessageType value) {
+ static const char *to_str(const ldp_xml_parser::MessageType value) {
return messageTypeMap[value];
}
- static const char *to_str(const FB::Decision value) {
+ static const char *to_str(const ldp_xml_parser::Decision value) {
return decisionTypeMap[value];
}
- static const char *to_str(const FB::BusAccessType value) {
+ static const char *to_str(const ldp_xml_parser::BusAccessType value) {
return busTypeMap[value];
}
- template <typename T>
- static bool compare(const T current, const T expected) {
+ template <typename T, typename S>
+ static bool compare(const T current, const S expected) {
if (current != expected) {
// print_error("Current: \"%s\" expected: \"%s\"", to_str(current), to_str(expected));
return false;
struct NodeTest {
const std::string name;
const std::string privilege;
- const FB::Decision decision;
+ const ldp_xml_parser::Decision decision;
const std::string prefix_privilege;
- const FB::Decision prefix_decision;
+ const ldp_xml_parser::Decision prefix_decision;
void printContent() const {
TH::print_property("name", name);
TH::print_property("prefix_privilege", prefix_privilege);
TH::print_property("prefix_decision", prefix_decision);
}
-
- bool isMatch(const FB::PolicyOwnNode *node, const std::string &token) const {
- return (TH::compare(node->token()->str(), token) &&
- TH::compare(node->decision_item()->privilege()->str(), privilege) &&
- TH::compare(node->decision_item()->decision(), decision) &&
- TH::compare(node->prefix_decision_item()->privilege()->str(), prefix_privilege) &&
- TH::compare(node->prefix_decision_item()->decision(), prefix_decision));
- }
};
struct ItemSRTest {
const std::string interface;
const std::string member;
const std::string path;
- const FB::MessageType type;
+ const ldp_xml_parser::MessageType type;
const bool is_name_prefix;
- const FB::Decision decision;
+ const ldp_xml_parser::Decision decision;
void printContent() const {
TH::print_property("name", name);
TH::print_property("is_name_prefix", is_name_prefix);
TH::print_property("decision", decision);
}
-
- template <typename T>
- bool isMatch(const T *item) const {
- return TH::compare(item->name()->str(), name) &&
- TH::compare(item->interface()->str(), interface) &&
- TH::compare(item->member()->str(), member) &&
- TH::compare(item->path()->str(), path) &&
- TH::compare(item->type(), type) &&
- TH::compare(item->is_name_prefix(), is_name_prefix) &&
- TH::compare(item->decision()->decision(), decision);
- }
};
struct ItemAccessTest {
const uid_t uid;
const gid_t gid;
- const FB::Decision decision;
+ const ldp_xml_parser::Decision decision;
const std::string privilege;
- const FB::BusAccessType type;
+ const ldp_xml_parser::BusAccessType type;
void printContent() const {
TH::print_property("uid", uid);
TH::print_property("privilege", privilege);
TH::print_property("type", type);
}
-
- bool isMatch(const FB::ItemAccess *item) const {
- return TH::compare(item->uid(), uid) &&
- TH::compare(item->gid(), gid) &&
- TH::compare(item->decision()->decision(), decision) &&
- TH::compare(item->decision()->privilege()->str(), privilege) &&
- TH::compare(item->type(), type);
- }
};
-
std::vector<NodeTest> context_default_tests = {
- { "org", "", FB::Decision_ANY, "", FB::Decision_ANY },
- { "org.tizen", "", FB::Decision_ANY, "", FB::Decision_ANY },
- { "org.tizen.pok2", "", FB::Decision_ANY, "privilege1", FB::Decision_CHECK },
- { "org.tizen.pok2.a", "", FB::Decision_ANY, "", FB::Decision_DENY },
- { "org.tizen.pok2.a.b", "", FB::Decision_ANY, "privilege2", FB::Decision_CHECK },
- { "org.tizen.pnope", "http://tizen.org/privilege/packagemanager.nope", FB::Decision_CHECK, "", FB::Decision_ANY },
- { "org.tizen.pok1.a1", "http://tizen.org/privilege/packagemanager.nope", FB::Decision_CHECK, "http://tizen.org/privilege/packagemanager.admin", FB::Decision_CHECK },
- { "org.tizen.pok1.a", "", FB::Decision_ANY, "", FB::Decision_DENY },
- { "org.tizen.pok1.a.b4", "http://tizen.org/privilege/packagemanager.nope", FB::Decision_CHECK, "", FB::Decision_ANY },
- { "org.tizen.pok1.a.b3", "", FB::Decision_ANY, "http://tizen.org/privilege/packagemanager.nope", FB::Decision_CHECK },
- { "org.tizen.pok1.a.b2", "http://tizen.org/privilege/packagemanager.admin", FB::Decision_CHECK, "", FB::Decision_ANY },
- { "org.tizen.pok1.a.b1", "", FB::Decision_ANY, "http://tizen.org/privilege/packagemanager.admin", FB::Decision_CHECK },
- { "org.tizen.pok", "http://tizen.org/privilege/packagemanager.admin", FB::Decision_CHECK, "", FB::Decision_ANY },
+ { "org", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.pok2", "", ldp_xml_parser::Decision::ANY, "privilege1", ldp_xml_parser::Decision::CHECK },
+ { "org.tizen.pok2.a", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::DENY },
+ { "org.tizen.pok2.a.b", "", ldp_xml_parser::Decision::ANY, "privilege2", ldp_xml_parser::Decision::CHECK },
+ { "org.tizen.pnope", "http://tizen.org/privilege/packagemanager.nope", ldp_xml_parser::Decision::CHECK, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.pok1.a1", "http://tizen.org/privilege/packagemanager.nope", ldp_xml_parser::Decision::CHECK, "http://tizen.org/privilege/packagemanager.admin", ldp_xml_parser::Decision::CHECK },
+ { "org.tizen.pok1.a", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::DENY },
+ { "org.tizen.pok1.a.b4", "http://tizen.org/privilege/packagemanager.nope", ldp_xml_parser::Decision::CHECK, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.pok1.a.b3", "", ldp_xml_parser::Decision::ANY, "http://tizen.org/privilege/packagemanager.nope", ldp_xml_parser::Decision::CHECK },
+ { "org.tizen.pok1.a.b2", "http://tizen.org/privilege/packagemanager.admin", ldp_xml_parser::Decision::CHECK, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.pok1.a.b1", "", ldp_xml_parser::Decision::ANY, "http://tizen.org/privilege/packagemanager.admin", ldp_xml_parser::Decision::CHECK },
+ { "org.tizen.pok", "http://tizen.org/privilege/packagemanager.admin", ldp_xml_parser::Decision::CHECK, "", ldp_xml_parser::Decision::ANY },
};
std::vector<NodeTest> context_mandatory_tests = {};
std::vector<NodeTest> user_root_tests = {
- { "org", "", FB::Decision_ANY, "", FB::Decision_ANY },
- { "org.tizen", "", FB::Decision_ANY, "", FB::Decision_ANY },
- { "org.tizen.a1", "", FB::Decision_ANY, "", FB::Decision_ALLOW },
- { "org.tizen.a1.b", "", FB::Decision_DENY, "", FB::Decision_ANY },
- { "org.tizen.b", "", FB::Decision_ANY, "", FB::Decision_ANY },
- { "org.tizen.b.z", "", FB::Decision_ALLOW, "", FB::Decision_ANY },
- { "org.tizen.b.c", "", FB::Decision_ANY, "", FB::Decision_ALLOW },
- { "org.tizen.a", "", FB::Decision_ANY, "", FB::Decision_ALLOW },
- { "org.tizen.a.d", "", FB::Decision_ANY, "", FB::Decision_ALLOW },
- { "org.tizen.a.c", "", FB::Decision_DENY, "", FB::Decision_ALLOW },
- { "org.tizen.a.b", "", FB::Decision_ANY, "", FB::Decision_DENY },
- { "org.tizen.a.b.c2", "", FB::Decision_ANY, "", FB::Decision_ALLOW },
- { "org.tizen.a.b.c1", "", FB::Decision_ANY, "", FB::Decision_DENY },
- { "org.tizen.a.b.c1.d", "", FB::Decision_ANY, "", FB::Decision_ANY },
- { "org.tizen.a.b.c1.d.e", "", FB::Decision_ANY, "", FB::Decision_ANY },
- { "org.tizen.a.b.c1.d.e.f", "", FB::Decision_ANY, "", FB::Decision_ANY },
- { "org.tizen.a.b.c1.d.e.f.g", "", FB::Decision_ALLOW, "", FB::Decision_ANY },
- { "org.tizen.a.b.c3", "", FB::Decision_DENY, "", FB::Decision_ALLOW },
- { "org.tizen.a.b.c3.d", "", FB::Decision_ANY, "", FB::Decision_DENY },
- { "org.tizen.a.b.c3.d.esth", "", FB::Decision_ALLOW, "", FB::Decision_ANY },
- { "org.tizen.a.b.c3.d.e", "", FB::Decision_ANY, "", FB::Decision_ALLOW },
- { "org.tizen.a.b.c3.d.e.f", "", FB::Decision_DENY, "", FB::Decision_ANY },
- { "org.tizen.a.b.c3.d.e.f.g", "", FB::Decision_ALLOW, "", FB::Decision_ANY },
- { "org.tizen.a.b.c", "", FB::Decision_ANY, "", FB::Decision_ALLOW },
- { "org.tizen.a.b.c.d", "", FB::Decision_ANY, "", FB::Decision_DENY },
- { "org.tizen.a.b.c.d.esth", "", FB::Decision_ALLOW, "", FB::Decision_ANY },
- { "org.tizen.a.b.c.d.e", "", FB::Decision_ANY, "", FB::Decision_ALLOW },
- { "org.tizen.a.b.c.d.e.f", "", FB::Decision_DENY, "", FB::Decision_ANY },
- { "org.tizen.a.bsth", "", FB::Decision_DENY, "", FB::Decision_ANY },
- { "org.tizen.ldposd", "", FB::Decision_ALLOW, "", FB::Decision_ANY },
- { "org.tizen.ldposa", "", FB::Decision_ALLOW, "", FB::Decision_ANY },
- { "org.tizen.test", "", FB::Decision_ANY, "", FB::Decision_ANY },
- { "org.tizen.test.dest_prefix", "", FB::Decision_ANY, "", FB::Decision_ALLOW },
- { "org.tizen.ldpoga", "", FB::Decision_ALLOW, "", FB::Decision_ANY },
- { "org.tizen.ldpo", "", FB::Decision_ANY, "", FB::Decision_ALLOW },
- { "org.tizen.ldpogd", "", FB::Decision_ALLOW, "", FB::Decision_ANY },
+ { "org", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.a1", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.a1.b", "", ldp_xml_parser::Decision::DENY, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.b", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.b.z", "", ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.b.c", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.a", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.a.d", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.a.c", "", ldp_xml_parser::Decision::DENY, "", ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.a.b", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::DENY },
+ { "org.tizen.a.b.c2", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.a.b.c1", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::DENY },
+ { "org.tizen.a.b.c1.d", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.a.b.c1.d.e", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.a.b.c1.d.e.f", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.a.b.c1.d.e.f.g", "", ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.a.b.c3", "", ldp_xml_parser::Decision::DENY, "", ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.a.b.c3.d", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::DENY },
+ { "org.tizen.a.b.c3.d.esth", "", ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.a.b.c3.d.e", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.a.b.c3.d.e.f", "", ldp_xml_parser::Decision::DENY, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.a.b.c3.d.e.f.g", "", ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.a.b.c", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.a.b.c.d", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::DENY },
+ { "org.tizen.a.b.c.d.esth", "", ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.a.b.c.d.e", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.a.b.c.d.e.f", "", ldp_xml_parser::Decision::DENY, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.a.bsth", "", ldp_xml_parser::Decision::DENY, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.ldposd", "", ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.ldposa", "", ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.test", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.test.dest_prefix", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.ldpoga", "", ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::Decision::ANY },
+ { "org.tizen.ldpo", "", ldp_xml_parser::Decision::ANY, "", ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.ldpogd", "", ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::Decision::ANY },
};
std::vector<ItemSRTest> item_send_context_default_tests {
- { "", "", "", "", FB::MessageType_METHOD_CALL, false, FB::Decision_DENY },
- { "org.freedesktop.DBus", "org.freedesktop.DBus", "", "", FB::MessageType_ANY, false, FB::Decision_ALLOW },
- { "org.freedesktop.DBus", "org.freedesktop.DBus.Introspectable", "", "", FB::MessageType_ANY, false, FB::Decision_ALLOW },
- { "org.freedesktop.DBus", "org.freedesktop.DBus", "UpdateActivationEnvironment", "", FB::MessageType_ANY, false, FB::Decision_DENY },
- { "org.freedesktop.DBus", "org.freedesktop.DBus.Debug.Stats", "", "", FB::MessageType_ANY, false, FB::Decision_DENY },
- { "org.freedesktop.DBus", "org.freedesktop.systemd1.Activator", "", "", FB::MessageType_ANY, false, FB::Decision_DENY },
+ { "", "", "", "", ldp_xml_parser::MessageType::METHOD_CALL, false, ldp_xml_parser::Decision::DENY },
+ { "org.freedesktop.DBus", "org.freedesktop.DBus", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::ALLOW },
+ { "org.freedesktop.DBus", "org.freedesktop.DBus.Introspectable", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::ALLOW },
+ { "org.freedesktop.DBus", "org.freedesktop.DBus", "UpdateActivationEnvironment", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::DENY },
+ { "org.freedesktop.DBus", "org.freedesktop.DBus.Debug.Stats", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::DENY },
+ { "org.freedesktop.DBus", "org.freedesktop.systemd1.Activator", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::DENY },
};
std::vector<ItemSRTest> item_receive_context_default_test {
- { "", "", "", "", FB::MessageType_METHOD_CALL, false, FB::Decision_ALLOW },
- { "", "", "", "", FB::MessageType_METHOD_RETURN, false, FB::Decision_ALLOW },
- { "", "", "", "", FB::MessageType_ERROR, false, FB::Decision_ALLOW },
- { "", "", "", "", FB::MessageType_SIGNAL, false, FB::Decision_ALLOW },
+ { "", "", "", "", ldp_xml_parser::MessageType::METHOD_CALL, false, ldp_xml_parser::Decision::ALLOW },
+ { "", "", "", "", ldp_xml_parser::MessageType::METHOD_RETURN, false, ldp_xml_parser::Decision::ALLOW },
+ { "", "", "", "", ldp_xml_parser::MessageType::ERROR, false, ldp_xml_parser::Decision::ALLOW },
+ { "", "", "", "", ldp_xml_parser::MessageType::SIGNAL, false, ldp_xml_parser::Decision::ALLOW },
};
std::vector<ItemSRTest> item_send_root_tests {
- { "org.tizen.test.dest_prefix.ap", "", "", "", FB::MessageType_ANY, true, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.ao", "", "", "", FB::MessageType_ANY, false, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.ap.1.d", "", "", "", FB::MessageType_ANY, false, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.ap.1.dp", "", "", "", FB::MessageType_ANY, true, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.ap.1.d.ap", "", "", "", FB::MessageType_ANY, true, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.ap.1.dp.ap", "", "", "", FB::MessageType_ANY, true, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.ap.1.dp.a", "", "", "", FB::MessageType_ANY, false, FB::Decision_ALLOW },
-
- { "org.tizen.test.dest_prefix.ap.2.apxdp", "", "", "", FB::MessageType_ANY, true, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.ap.2.apxdp.dp", "", "", "", FB::MessageType_ANY, true, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.ap.2.apxdp.dp.ap", "", "", "", FB::MessageType_ANY, true, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.ap.2.apxdp.dp.ap.d", "", "", "", FB::MessageType_ANY, false, FB::Decision_DENY },
-
- { "org.tizen.test.dest_prefix.ap.3.dpxap", "", "", "", FB::MessageType_ANY, true, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.ap.3.dpxap.ap", "", "", "", FB::MessageType_ANY, true, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.ap.3.dpxap.ap.dp", "", "", "", FB::MessageType_ANY, true, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.ap.3.dpxap.ap.dp.ap", "", "", "", FB::MessageType_ANY, true, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.ap.3.dpxap.ap.dp.a", "", "", "", FB::MessageType_ANY, false, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.ap.3.dpxap", "", "", "", FB::MessageType_ANY, true, FB::Decision_ALLOW },
-
- { "org.tizen.test.dest_prefix.dp", "", "", "", FB::MessageType_ANY, true, FB::Decision_DENY },
-
- { "org.tizen.test.dest_prefix.do", "", "", "", FB::MessageType_ANY, false, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.ao.ao", "", "", "", FB::MessageType_ANY, false, FB::Decision_ALLOW },
-
- { "org.tizen.test.dest_prefix.dp.1.a", "", "", "", FB::MessageType_ANY, false, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.dp.1.ap", "", "", "", FB::MessageType_ANY, true, FB::Decision_ALLOW },
-
- { "org.tizen.test.dest_prefix.dp.1.a.dp", "", "", "", FB::MessageType_ANY, true, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.dp.1.ap.dp", "", "", "", FB::MessageType_ANY, true, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.dp.1.ap.d", "", "", "", FB::MessageType_ANY, false, FB::Decision_DENY },
-
- { "org.tizen.test.dest_prefix.dp.2.dpxap", "", "", "", FB::MessageType_ANY, true, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.dp.2.dpxap.ap", "", "", "", FB::MessageType_ANY, true, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.dp.2.dpxap.ap.dp", "", "", "", FB::MessageType_ANY, true, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.dp.2.dpxap.ap.dp.a", "", "", "", FB::MessageType_ANY, false, FB::Decision_ALLOW },
-
- { "org.tizen.test.dest_prefix.dp.2.dpxap", "", "", "", FB::MessageType_ANY, true, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.dp.2.dpxap.ap.d", "", "", "", FB::MessageType_ANY, false, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.dp.2.dpxap.ap.dp.f.d", "", "", "", FB::MessageType_ANY, false, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.dp.2.dpxap.f.f.f.dp", "", "", "", FB::MessageType_ANY, true, FB::Decision_DENY },
-
- { "org.tizen.test.dest_prefix.dp.3.apxdp", "", "", "", FB::MessageType_ANY, true, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.dp.3.apxdp.dp", "", "", "", FB::MessageType_ANY, true, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.dp.3.apxdp.dp.ap", "", "", "", FB::MessageType_ANY, true, FB::Decision_ALLOW },
- { "org.tizen.test.dest_prefix.dp.3.apxdp.dp.ap.dp", "", "", "", FB::MessageType_ANY, true, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.dp.3.apxdp.dp.ap.d", "", "", "", FB::MessageType_ANY, false, FB::Decision_DENY },
- { "org.tizen.test.dest_prefix.dp.3.apxdp", "", "", "", FB::MessageType_ANY, true, FB::Decision_DENY },
+ { "org.tizen.test.dest_prefix.ap", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.ao", "", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.ap.1.d", "", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.ap.1.dp", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.ap.1.d.ap", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.ap.1.dp.ap", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.ap.1.dp.a", "", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::ALLOW },
+
+ { "org.tizen.test.dest_prefix.ap.2.apxdp", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.ap.2.apxdp.dp", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.ap.2.apxdp.dp.ap", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.ap.2.apxdp.dp.ap.d", "", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::DENY },
+
+ { "org.tizen.test.dest_prefix.ap.3.dpxap", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.ap.3.dpxap.ap", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.ap.3.dpxap.ap.dp", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.ap.3.dpxap.ap.dp.ap", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.ap.3.dpxap.ap.dp.a", "", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.ap.3.dpxap", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::ALLOW },
+
+ { "org.tizen.test.dest_prefix.dp", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::DENY },
+
+ { "org.tizen.test.dest_prefix.do", "", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.ao.ao", "", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::ALLOW },
+
+ { "org.tizen.test.dest_prefix.dp.1.a", "", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.dp.1.ap", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::ALLOW },
+
+ { "org.tizen.test.dest_prefix.dp.1.a.dp", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.dp.1.ap.dp", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.dp.1.ap.d", "", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::DENY },
+
+ { "org.tizen.test.dest_prefix.dp.2.dpxap", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.dp.2.dpxap.ap", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.dp.2.dpxap.ap.dp", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.dp.2.dpxap.ap.dp.a", "", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::ALLOW },
+
+ { "org.tizen.test.dest_prefix.dp.2.dpxap", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.dp.2.dpxap.ap.d", "", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.dp.2.dpxap.ap.dp.f.d", "", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.dp.2.dpxap.f.f.f.dp", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::DENY },
+
+ { "org.tizen.test.dest_prefix.dp.3.apxdp", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.dp.3.apxdp.dp", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.dp.3.apxdp.dp.ap", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::ALLOW },
+ { "org.tizen.test.dest_prefix.dp.3.apxdp.dp.ap.dp", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.dp.3.apxdp.dp.ap.d", "", "", "", ldp_xml_parser::MessageType::ANY, false, ldp_xml_parser::Decision::DENY },
+ { "org.tizen.test.dest_prefix.dp.3.apxdp", "", "", "", ldp_xml_parser::MessageType::ANY, true, ldp_xml_parser::Decision::DENY },
};
std::vector<ItemAccessTest> item_access_context_default_test {
- { 0, 0, FB::Decision_ALLOW, "", FB::BusAccessType_ALL_USERS },
- { 1, 0, FB::Decision_DENY, "", FB::BusAccessType_USER },
- { 2, 0, FB::Decision_DENY, "", FB::BusAccessType_USER },
- { 0, 20, FB::Decision_ALLOW, "", FB::BusAccessType_GROUP },
- { 0, 30, FB::Decision_DENY, "", FB::BusAccessType_GROUP },
- { 3, 0, FB::Decision_ALLOW, "", FB::BusAccessType_USER },
- { 7, 0, FB::Decision_ALLOW, "", FB::BusAccessType_USER },
- { 8, 0, FB::Decision_DENY, "", FB::BusAccessType_USER },
- { 9991, 0, FB::Decision_CHECK, "privilege1", FB::BusAccessType_USER },
- { 9992, 0, FB::Decision_CHECK, "privilege2", FB::BusAccessType_USER },
- { 9993, 0, FB::Decision_CHECK, "privilege1", FB::BusAccessType_USER },
- { 888, 0, FB::Decision_CHECK, "privilege1", FB::BusAccessType_USER },
+ { 0, 0, ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::BusAccessType::ALL_USERS },
+ { 1, 0, ldp_xml_parser::Decision::DENY, "", ldp_xml_parser::BusAccessType::USER },
+ { 2, 0, ldp_xml_parser::Decision::DENY, "", ldp_xml_parser::BusAccessType::USER },
+ { 0, 20, ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::BusAccessType::GROUP },
+ { 0, 30, ldp_xml_parser::Decision::DENY, "", ldp_xml_parser::BusAccessType::GROUP },
+ { 3, 0, ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::BusAccessType::USER },
+ { 7, 0, ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::BusAccessType::USER },
+ { 8, 0, ldp_xml_parser::Decision::DENY, "", ldp_xml_parser::BusAccessType::USER },
+ { 9991, 0, ldp_xml_parser::Decision::CHECK, "privilege1", ldp_xml_parser::BusAccessType::USER },
+ { 9992, 0, ldp_xml_parser::Decision::CHECK, "privilege2", ldp_xml_parser::BusAccessType::USER },
+ { 9993, 0, ldp_xml_parser::Decision::CHECK, "privilege1", ldp_xml_parser::BusAccessType::USER },
+ { 888, 0, ldp_xml_parser::Decision::CHECK, "privilege1", ldp_xml_parser::BusAccessType::USER },
};
std::vector<ItemAccessTest> item_access_context_mandatory_test {
- { 6, 0, FB::Decision_DENY, "", FB::BusAccessType_USER },
- { 7, 0, FB::Decision_DENY, "", FB::BusAccessType_USER },
- { 8, 0, FB::Decision_ALLOW, "", FB::BusAccessType_USER },
- { 0, 9992, FB::Decision_CHECK, "privilege1", FB::BusAccessType_GROUP },
- { 9993, 0, FB::Decision_CHECK, "privilege2", FB::BusAccessType_USER },
+ { 6, 0, ldp_xml_parser::Decision::DENY, "", ldp_xml_parser::BusAccessType::USER },
+ { 7, 0, ldp_xml_parser::Decision::DENY, "", ldp_xml_parser::BusAccessType::USER },
+ { 8, 0, ldp_xml_parser::Decision::ALLOW, "", ldp_xml_parser::BusAccessType::USER },
+ { 0, 9992, ldp_xml_parser::Decision::CHECK, "privilege1", ldp_xml_parser::BusAccessType::GROUP },
+ { 9993, 0, ldp_xml_parser::Decision::CHECK, "privilege2", ldp_xml_parser::BusAccessType::USER },
};
class SerializerTests {
ldp_serializer::Serializer serializer;
- const FB::File *file;
+ ldp_serialized::StorageBackendSerialized _db;
+
+ const auto &db() const { return _db.getBackend(); }
+
+ template <typename PolicyOwnNode>
+ bool isMatch(const NodeTest &test, const PolicyOwnNode &node, const std::string &token) const {
+ return
+ TH::compare(token, db().stringGetCStr(db().ownNodeGetToken(node))) &&
+ TH::compare(test.privilege, db().stringGetCStr(db().decisionItemGetPrivilege(db().ownNodeGetDecisionItem(node)))) &&
+ TH::compare(test.decision, makeDecision(db().decisionItemGetDecision(db().ownNodeGetDecisionItem(node)))) &&
+ TH::compare(test.prefix_privilege, db().stringGetCStr(db().decisionItemGetPrivilege(db().ownNodeGetPrefixDecisionItem(node)))) &&
+ TH::compare(test.prefix_decision, makeDecision(db().decisionItemGetDecision(db().ownNodeGetPrefixDecisionItem(node))));
+ }
+
+ template <typename T>
+ bool isMatch(const ItemSRTest &test, const T &item) const {
+ return
+ TH::compare(test.name, db().stringGetCStr(db().itemSrGetName(item))) &&
+ TH::compare(test.interface, db().stringGetCStr(db().itemSrGetInterface(item))) &&
+ TH::compare(test.member, db().stringGetCStr(db().itemSrGetMember(item))) &&
+ TH::compare(test.path, db().stringGetCStr(db().itemSrGetPath(item))) &&
+ TH::compare(test.type, makeMessageType(db().itemSrGetMessageType(item))) &&
+ TH::compare(test.is_name_prefix, db().itemSrGetIsNamePrefix(item)) &&
+ TH::compare(test.decision, makeDecision(db().decisionItemGetDecision(db().itemGetDecisionItem(item))));
+ }
+
+ template <typename ItemAccess>
+ bool isMatch(const ItemAccessTest &test, const ItemAccess &item) const {
+ return
+ TH::compare(test.uid, db().itemAccessGetUid(item)) &&
+ TH::compare(test.gid, db().itemAccessGetGid(item)) &&
+ TH::compare(test.decision, makeDecision(db().decisionItemGetDecision(db().itemGetDecisionItem(item)))) &&
+ TH::compare(test.privilege, db().stringGetCStr(db().decisionItemGetPrivilege(db().itemGetDecisionItem(item)))) &&
+ TH::compare(test.type, makeBusAccessType(db().itemAccessGetType(item)));
+ }
void serialize_xml(const std::string &file_name) {
size_t size;
- auto buff = serializer.serialize(file_name, size);
+ ldp_xml::StorageBackendXML xmlStorage;
- file = FB::GetFile(buff);
+ if (!xmlStorage.init(file_name.c_str())) {
+ print_error("xmlStorage init error");
+ return;
+ }
+
+ auto buff = serializer.serialize(xmlStorage, size);
+
+ _db.initFromData(buff, size, false);
}
- bool check_tree(const std::string &token, const FB::PolicyOwnNode *nnode, const NodeTest &test) {
+ template <typename PolicyOwnNode>
+ bool check_tree(const std::string &token, const PolicyOwnNode &nnode, const NodeTest &test) {
size_t dot = token.find('.');
+ auto children = db().ownNodeGetChildren(nnode);
if (dot == std::string::npos) {
- auto node = nnode->children()->LookupByKey(token.c_str());
- if (node == nullptr) {
+ auto node = db().containerLookupByKey(children, token.c_str());
+ if (!node.first) {
print_error("node %s not found for:", TH::to_str(token));
test.printContent();
return false;
}
- if (!test.isMatch(node, token)) {
+ if (!isMatch(test, node.second, token)) {
print_error("No matching child found for test:");
test.printContent();
return false;
std::string part = token.substr(0, dot);
std::string rest = token.substr(dot + 1);
- auto new_node = nnode->children()->LookupByKey(part.c_str());
- if (new_node == nullptr) {
+ auto new_node = db().containerLookupByKey(children, part.c_str());
+ if (!new_node.first) {
print_error("node %s not found", TH::to_str(part));
return false;
}
- return check_tree(rest, new_node, test);
+ return check_tree(rest, new_node.second, test);
}
}
- bool check_tree(const FB::PolicyOwnNode *tree, const std::vector<NodeTest> &tree_tests) {
+ template <typename PolicyOwnNode>
+ bool check_tree(const PolicyOwnNode &tree, const std::vector<NodeTest> &tree_tests) {
for (const auto &test : tree_tests) {
if (!check_tree(test.name, tree, test))
return false;
}
bool check_own_set() {
- return check_tree(file->m_own_set()->context_default()->tree(), context_default_tests) &&
- check_tree(file->m_own_set()->context_mandatory()->tree(), context_mandatory_tests) &&
- check_tree(file->m_own_set()->user()->LookupByKey(0)->policy()->tree(), user_root_tests);
+ return check_tree(db().policyGetTree(db().setGetContextDefault(db().fileGetOwnSet(db().getFile()))), context_default_tests) &&
+ check_tree(db().policyGetTree(db().setGetContextMandatory(db().fileGetOwnSet(db().getFile()))), context_mandatory_tests) &&
+ check_tree(db().policyGetTree(db().setUserGroupGetPolicy(db().containerLookupByKey(db().setGetUser(db().fileGetOwnSet(db().getFile())), 0).second)), user_root_tests);
}
template <typename T, typename U>
bool checkPolicy(const T *policy, const std::vector<U> &tests) {
for (const auto &test : tests) {
bool found = false;
- for (const auto &item : *policy->items()) {
- if (test.isMatch(item)) {
+ auto items = db().policyGetItems(policy);
+ auto end = db().containerGetIteratorEnd(items);
+ for (auto it = db().containerGetIterator(items); it != end; it++) {
+ if (isMatch(test, *it)) {
found = true;
break;
}
}
bool check_send_set() {
- return checkPolicy(file->m_send_set()->context_default(), item_send_context_default_tests) &&
- checkPolicy(file->m_send_set()->user()->LookupByKey(0)->policy(), item_send_root_tests);
+ return checkPolicy(db().setGetContextDefault(db().fileGetSendSet(db().getFile())), item_send_context_default_tests) &&
+ checkPolicy(db().setUserGroupGetPolicy(db().containerLookupByKey(db().setGetUser(db().fileGetSendSet(db().getFile())), 0).second), item_send_root_tests);
}
bool check_receive_set() {
- return checkPolicy(file->m_receive_set()->context_default(), item_receive_context_default_test);
+ return checkPolicy(db().setGetContextDefault(db().fileGetReceiveSet(db().getFile())), item_receive_context_default_test);
}
bool check_access_set() {
- return checkPolicy(file->m_access_set()->context_default(), item_access_context_default_test) &&
- checkPolicy(file->m_access_set()->context_mandatory(), item_access_context_mandatory_test);
+ return checkPolicy(db().setGetContextDefault(db().fileGetAccessSet(db().getFile())), item_access_context_default_test) &&
+ checkPolicy(db().setGetContextMandatory(db().fileGetAccessSet(db().getFile())), item_access_context_mandatory_test);
}
public:
- SerializerTests() : file(nullptr) {}
+ SerializerTests() {}
bool run_all_tests(const std::string &config) {
serialize_xml(config);
check_access_set();
}
};
-}
int main() {
- auto st = ldp_xml_parser::SerializerTests();
+ auto st = SerializerTests();
if (st.run_all_tests("tests/default_deny/system.conf"))
return 0;
return -1;