[folks] Assert that each D-Bus test case is run in its intended environment



commit 19a44b01b5dea3df8a6f6fc1b4dcab21054ae097
Author: Simon McVittie <simon mcvittie collabora co uk>
Date:   Mon Mar 18 19:10:57 2013 +0000

    Assert that each D-Bus test case is run in its intended environment
    
    This is a safety check so we don't trash the user's real home directory.
    
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=695381
    Reviewed-by: Philip Withnall <philip tecnocode co uk>
    [added a comment as per pwithnall's review -smcv]
    Signed-off-by: Simon McVittie <simon mcvittie collabora co uk>

 tests/lib/eds/test-case.vala            |    8 ++++++++
 tests/lib/libsocialweb/test-case.vala   |    7 +++++++
 tests/lib/telepathy/test-case.vala      |    7 +++++++
 tests/lib/tracker/test-case.vala        |    8 ++++++++
 tests/tools/with-session-bus-eds.sh     |    3 +++
 tests/tools/with-session-bus-tracker.sh |    3 +++
 tests/tools/with-session-bus.sh         |    3 +++
 7 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/tests/lib/eds/test-case.vala b/tests/lib/eds/test-case.vala
index 8ae92aa..8465589 100644
--- a/tests/lib/eds/test-case.vala
+++ b/tests/lib/eds/test-case.vala
@@ -42,6 +42,14 @@ public class EdsTest.TestCase : Folks.TestCase
 
   public TestCase (string name)
     {
+      /* This variable is set in the same place as the various variables we
+       * care about for sandboxing purposes, like XDG_CONFIG_HOME and
+       * DBUS_SESSION_BUS_ADDRESS. */
+      if (Environment.get_variable ("FOLKS_TESTS_SANDBOXED_DBUS")
+          != "eds")
+        error ("e-d-s tests must be run in a private D-Bus session " +
+            "with e-d-s services");
+
       base (name);
 
       Environment.set_variable ("FOLKS_BACKENDS_ALLOWED", "eds", true);
diff --git a/tests/lib/libsocialweb/test-case.vala b/tests/lib/libsocialweb/test-case.vala
index b730078..3ad094e 100644
--- a/tests/lib/libsocialweb/test-case.vala
+++ b/tests/lib/libsocialweb/test-case.vala
@@ -42,6 +42,13 @@ public class LibsocialwebTest.TestCase : Folks.TestCase
 
   public TestCase (string name)
     {
+      /* This variable is set in the same place as the various variables we
+       * care about for sandboxing purposes, like XDG_CONFIG_HOME and
+       * DBUS_SESSION_BUS_ADDRESS. */
+      if (Environment.get_variable ("FOLKS_TESTS_SANDBOXED_DBUS")
+          != "no-services")
+        error ("libsocialweb tests must be run in a private D-Bus session");
+
       base (name);
 
       Environment.set_variable ("FOLKS_BACKENDS_ALLOWED", "libsocialweb", true);
diff --git a/tests/lib/telepathy/test-case.vala b/tests/lib/telepathy/test-case.vala
index b5c898f..db1048d 100644
--- a/tests/lib/telepathy/test-case.vala
+++ b/tests/lib/telepathy/test-case.vala
@@ -90,6 +90,13 @@ public class TpfTest.TestCase : Folks.TestCase
    */
   public TestCase (string name)
     {
+      /* This variable is set in the same place as the various variables we
+       * care about for sandboxing purposes, like XDG_CONFIG_HOME and
+       * DBUS_SESSION_BUS_ADDRESS. */
+      if (Environment.get_variable ("FOLKS_TESTS_SANDBOXED_DBUS")
+          != "no-services")
+        error ("Telepathy tests must be run in a private D-Bus session");
+
       base (name);
 
       if (use_keyfile_too)
diff --git a/tests/lib/tracker/test-case.vala b/tests/lib/tracker/test-case.vala
index 20c9ac8..d49edf6 100644
--- a/tests/lib/tracker/test-case.vala
+++ b/tests/lib/tracker/test-case.vala
@@ -47,6 +47,14 @@ public class TrackerTest.TestCase : Folks.TestCase
    */
   public TestCase (string name)
     {
+      /* This variable is set in the same place as the various variables we
+       * care about for sandboxing purposes, like XDG_CONFIG_HOME and
+       * DBUS_SESSION_BUS_ADDRESS. */
+      if (Environment.get_variable ("FOLKS_TESTS_SANDBOXED_DBUS")
+          != "tracker")
+        error ("Tracker tests must be run in a private D-Bus session " +
+            "with Tracker services");
+
       base (name);
 
       Environment.set_variable ("FOLKS_BACKENDS_ALLOWED", "tracker", true);
diff --git a/tests/tools/with-session-bus-eds.sh b/tests/tools/with-session-bus-eds.sh
index faa5848..02f50af 100755
--- a/tests/tools/with-session-bus-eds.sh
+++ b/tests/tools/with-session-bus-eds.sh
@@ -38,6 +38,9 @@ eds_start
 
 e=0
 
+FOLKS_TESTS_SANDBOXED_DBUS=eds
+export FOLKS_TESTS_SANDBOXED_DBUS
+
 $cur_dir"/execute-test.sh" "$@" || e=$?
 
 trap - INT HUP TERM
diff --git a/tests/tools/with-session-bus-tracker.sh b/tests/tools/with-session-bus-tracker.sh
index 1bef880..11ad9c7 100755
--- a/tests/tools/with-session-bus-tracker.sh
+++ b/tests/tools/with-session-bus-tracker.sh
@@ -36,6 +36,9 @@ dbus_init 0
 dbus_start
 tracker_start
 
+FOLKS_TESTS_SANDBOXED_DBUS=tracker
+export FOLKS_TESTS_SANDBOXED_DBUS
+
 e=0
 $cur_dir"/execute-test.sh" "$@" || e=$?
 
diff --git a/tests/tools/with-session-bus.sh b/tests/tools/with-session-bus.sh
index fa78f94..d8f8d9b 100755
--- a/tests/tools/with-session-bus.sh
+++ b/tests/tools/with-session-bus.sh
@@ -31,6 +31,9 @@ trap cleanup INT HUP TERM
 dbus_init 0
 dbus_start
 
+FOLKS_TESTS_SANDBOXED_DBUS=no-services
+export FOLKS_TESTS_SANDBOXED_DBUS
+
 $cur_dir"/execute-test.sh" "$@" || e=$?
 
 trap - INT HUP TERM


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]