Add dbus tests for bus ownership prefix check 84/35284/4
authorMarcin Niesluchowski <m.niesluchow@samsung.com>
Wed, 11 Feb 2015 12:49:59 +0000 (13:49 +0100)
committerZbigniew Jasinski <z.jasinski@samsung.com>
Thu, 9 Apr 2015 13:56:31 +0000 (15:56 +0200)
* tcc_1230_own_prefix_deny
    Check for ownership prefix created in conf file. Not granted for client
    requesting name.
* tcc_1270_own_prefix_allow
    Check for ownership prefix created in conf file. Granted for client
    requesting name.

Change-Id: Ifcc2a2e2303f7205b23e587679d996f4bd73bc11

tests/dbus-tests/cynara_dbus_tests.cpp

index d71d5c2a26c70bb25b25d10df72f42d09d45c638..7d7a4fd20195c5bc0b64cd7a3407798185babce1 100644 (file)
@@ -40,9 +40,11 @@ using namespace DBusTest;
 
 static const std::string ROOT_UID_STR("0");
 
+static const std::string CONNECTION_NAME_PREFIX("com.security_tests");
+
 static const std::string connectionNameFromStr(const std::string &str)
 {
-    return "com.security_tests." + str;
+    return CONNECTION_NAME_PREFIX + "." + str;
 }
 
 static const std::string privilegeFromStr(const std::string &str)
@@ -97,12 +99,14 @@ static pid_t assertFork()
 
 RUNNER_TEST_GROUP_INIT(CYNARA_DBUS);
 
-static void testOwn(const std::string &testId, bool allow)
+static void testOwn(const std::string &testId,
+                    const std::function<void(const std::string &)> &addBusconfigPolicyFunc,
+                    bool allow)
 {
     SmackAccess access;
     const std::string label(smackLabelFromStr(testId));
 
-    addBusconfigPolicyOwn(testId);
+    addBusconfigPolicyFunc(testId);
     addSmackAccessForDbus(access, label);
     if (allow)
         addCynaraPolicy(testId);
@@ -125,10 +129,27 @@ static void testOwn(const std::string &testId, bool allow)
 
 RUNNER_MULTIPROCESS_TEST_SMACK(tcc_1130_own_deny)
 {
-    testOwn("tcc1130", false);
+    testOwn("tcc1130", addBusconfigPolicyOwn, false);
 }
 
 RUNNER_MULTIPROCESS_TEST_SMACK(tcc_1170_own_allow)
 {
-    testOwn("tcc1170", true);
+    testOwn("tcc1170", addBusconfigPolicyOwn, true);
+}
+
+static void addBusconfigPolicyOwnPrefix(const std::string &id)
+{
+    BusConfigWriter writer;
+    writer.addPolicyCheck(privilegeFromStr(id), {{Attr::OWN_PREFIX, CONNECTION_NAME_PREFIX}});
+    writer.save();
+}
+
+RUNNER_CHILD_TEST_SMACK(tcc_1230_own_prefix_deny)
+{
+    testOwn("tcc1230", addBusconfigPolicyOwnPrefix, false);
+}
+
+RUNNER_CHILD_TEST_SMACK(tcc_1270_own_prefix_allow)
+{
+    testOwn("tcc1270", addBusconfigPolicyOwnPrefix, true);
 }