From 28ce5634df0a109d15f2b307e56fbfac92d7c876 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Mon, 21 May 2012 14:38:49 -0400 Subject: Add test-cases and 10 second timeout for polkit.spawn() Signed-off-by: David Zeuthen --- test/data/etc/polkit-1/rules.d/10-testing.rules | 63 ++++++++++++++++++++++ test/polkitbackend/test-polkitbackendjsauthority.c | 40 ++++++++++++++ 2 files changed, 103 insertions(+) (limited to 'test') diff --git a/test/data/etc/polkit-1/rules.d/10-testing.rules b/test/data/etc/polkit-1/rules.d/10-testing.rules index 0cad62c..4a35e48 100644 --- a/test/data/etc/polkit-1/rules.d/10-testing.rules +++ b/test/data/etc/polkit-1/rules.d/10-testing.rules @@ -71,3 +71,66 @@ polkit.addRule(function(action, subject, details) { return "no"; } }); + +// --------------------------------------------------------------------- +// spawning + +polkit.addRule(function(action, subject, details) { + if (action == "net.company.spawning.non_existing_helper") { + try { + polkit.spawn(["/path/to/non/existing/helper"]); + return "no"; + } catch (error) { + return "yes"; + } + } +}); + +polkit.addRule(function(action, subject, details) { + if (action == "net.company.spawning.successful_helper") { + try { + polkit.spawn(["/bin/true"]); + return "yes"; + } catch (error) { + return "no"; + } + } +}); + +polkit.addRule(function(action, subject, details) { + if (action == "net.company.spawning.failing_helper") { + try { + polkit.spawn(["/bin/false"]); + return "no"; + } catch (error) { + return "yes"; + } + } +}); + +polkit.addRule(function(action, subject, details) { + if (action == "net.company.spawning.helper_with_output") { + try { + var out = polkit.spawn(["echo", "-n", "-e", "Hello\nWorld"]); + if (out == "Hello\nWorld") + return "yes"; + else + return "no"; + } catch (error) { + return "no"; + } + } +}); + +polkit.addRule(function(action, subject, details) { + if (action == "net.company.spawning.helper_timeout") { + try { + polkit.spawn(["sleep", "20"]); + return "no"; + } catch (error) { + if (error == "Error: Error spawning helper: Timed out after 10 seconds (g-io-error-quark, 24)") + return "yes"; + return "no"; + } + } +}); diff --git a/test/polkitbackend/test-polkitbackendjsauthority.c b/test/polkitbackend/test-polkitbackendjsauthority.c index f81c7fb..948cbc1 100644 --- a/test/polkitbackend/test-polkitbackendjsauthority.c +++ b/test/polkitbackend/test-polkitbackendjsauthority.c @@ -23,6 +23,7 @@ #include "glib.h" +#include #include #include #include @@ -246,6 +247,43 @@ static const RulesTestCase rules_test_cases[] = { POLKIT_IMPLICIT_AUTHORIZATION_NOT_AUTHORIZED, NULL }, + + /* spawning */ + { + "spawning_non_existing_helper", + "net.company.spawning.non_existing_helper", + "unix-user:root", + POLKIT_IMPLICIT_AUTHORIZATION_AUTHORIZED, + NULL + }, + { + "spawning_successful_helper", + "net.company.spawning.successful_helper", + "unix-user:root", + POLKIT_IMPLICIT_AUTHORIZATION_AUTHORIZED, + NULL + }, + { + "spawning_failing_helper", + "net.company.spawning.failing_helper", + "unix-user:root", + POLKIT_IMPLICIT_AUTHORIZATION_AUTHORIZED, + NULL + }, + { + "spawning_helper_with_output", + "net.company.spawning.helper_with_output", + "unix-user:root", + POLKIT_IMPLICIT_AUTHORIZATION_AUTHORIZED, + NULL + }, + { + "spawning_helper_timeout", + "net.company.spawning.helper_timeout", + "unix-user:root", + POLKIT_IMPLICIT_AUTHORIZATION_AUTHORIZED, + NULL + }, }; /* ---------------------------------------------------------------------------------------------------- */ @@ -310,6 +348,8 @@ main (int argc, char *argv[]) { GIOExtensionPoint *ep; + setlocale (LC_ALL, ""); + g_type_init (); g_test_init (&argc, &argv, NULL); //polkit_test_redirect_logs (); -- cgit v1.2.1