diff options
author | David Zeuthen <davidz@redhat.com> | 2012-05-21 14:38:49 -0400 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2012-05-21 14:38:49 -0400 |
commit | 28ce5634df0a109d15f2b307e56fbfac92d7c876 (patch) | |
tree | 5c9c78d2d03011181d26bdec0bf7dcae8a00d296 /test | |
parent | e7f01d6a37b0d922e9fe005e38fe9a958eb18e7f (diff) | |
download | polkit-28ce5634df0a109d15f2b307e56fbfac92d7c876.tar.gz |
Add test-cases and 10 second timeout for polkit.spawn()
Signed-off-by: David Zeuthen <davidz@redhat.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/data/etc/polkit-1/rules.d/10-testing.rules | 63 | ||||
-rw-r--r-- | test/polkitbackend/test-polkitbackendjsauthority.c | 40 |
2 files changed, 103 insertions, 0 deletions
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 <locale.h> #include <polkit/polkit.h> #include <polkitbackend/polkitbackendjsauthority.h> #include <polkittesthelper.h> @@ -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 (); |