summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Whipple <tw@tomwhipple.com>2006-07-20 22:13:11 +0000
committerTom Whipple <tw@tomwhipple.com>2006-07-20 22:13:11 +0000
commit9b155544d4e82961c046ef771046a29b6666c626 (patch)
treec9c002c0ec06f867ef4c84775e6948db291cc650
parentd68713ea212adde669f9727c2199c908d6d41738 (diff)
add xdg-su tests
-rw-r--r--tests/include/testassertions.sh10
-rwxr-xr-xtests/xdg-desktop-menu/t.menu_system_uninstall1
-rwxr-xr-xtests/xdg-su/t.su_badpass30
-rwxr-xr-xtests/xdg-su/t.su_basic34
-rwxr-xr-xtests/xdg-su/t.su_basic_asroot29
-rwxr-xr-xtests/xdg-su/t.su_no_carg22
-rwxr-xr-xtests/xdg-su/t.su_no_cflag23
7 files changed, 147 insertions, 2 deletions
diff --git a/tests/include/testassertions.sh b/tests/include/testassertions.sh
index 6860bd0..ea64c00 100644
--- a/tests/include/testassertions.sh
+++ b/tests/include/testassertions.sh
@@ -25,7 +25,7 @@ assert_exit() # execute command (saving output) and check exit code
assert_interactive_notroot() {
if [ `whoami` != 'root' ] ; then
- assert_interactive $@
+ assert_interactive "$@"
fi
}
@@ -47,7 +47,7 @@ assert_interactive() {
echo ""
if [ ! -z "$expect" ] ; then
if [ "$expect" != y -a "$expect" != n ] ; then
- echo "TEST SYNTAX ERROR: interactive assertions require 'y' or 'n' as choices."
+ echo "TEST SYNTAX ERROR: interactive assertions require 'y' or 'n' as choices. (found '$expect')"
exit 255
fi
echo -n "$query [y/n]: " >&2
@@ -226,6 +226,12 @@ infofile() # write file to journal using tet_infoline
done < "$1"
}
+require_interactive() {
+ if [ ! -z "$XDG_TEST_NO_INTERACTIVE" ] ; then
+ test_result UNTESTED "XDG_TEST_NO_INTERACTIVE is set, but this test needs interactive"
+ fi
+}
+
require_root() {
if [ `whoami` != 'root' ] ; then
test_result UNTESTED "not running as root, but test requires su privlages"
diff --git a/tests/xdg-desktop-menu/t.menu_system_uninstall b/tests/xdg-desktop-menu/t.menu_system_uninstall
index 4335921..8c88858 100755
--- a/tests/xdg-desktop-menu/t.menu_system_uninstall
+++ b/tests/xdg-desktop-menu/t.menu_system_uninstall
@@ -13,6 +13,7 @@ test_start "$FUNCNAME: verify a menu is removed correctly"
# Dependencies section
test_init
+require_root
set_no_display
USERPATH="$XDG_DATA_DIRS:$XDG_CONFIG_DIRS"
diff --git a/tests/xdg-su/t.su_badpass b/tests/xdg-su/t.su_badpass
new file mode 100755
index 0000000..ef98e1f
--- /dev/null
+++ b/tests/xdg-su/t.su_badpass
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+## Include utility functions.
+. "$XDG_TEST_DIR/include/testassertions.sh"
+. "$XDG_TEST_DIR/include/testcontrol.sh"
+
+## Test function
+test_su_badpass() {
+test_start "$FUNCTNAME: basic su password failure"
+
+test_init
+
+## Require a running X server
+require_notroot
+require_interactive
+
+assert_display
+
+test_procedure
+
+assert_interactive "Please DO NOT enter the correct password when prompted. (Repeat as necessary)"
+
+assert_exit 4 xdg-su -c whoami
+assert_nostdout
+assert_nostderr
+
+test_result
+}
+
+run_test test_su_badpass
diff --git a/tests/xdg-su/t.su_basic b/tests/xdg-su/t.su_basic
new file mode 100755
index 0000000..771fe40
--- /dev/null
+++ b/tests/xdg-su/t.su_basic
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+## Include utility functions.
+. "$XDG_TEST_DIR/include/testassertions.sh"
+. "$XDG_TEST_DIR/include/testcontrol.sh"
+
+## Test function
+test_su_basic() {
+test_start "$FUNCTNAME: basic su - up-privlage"
+
+test_init
+
+## Require a running X server
+require_notroot
+require_interactive
+
+assert_display
+
+echo "root" >out.expected
+
+test_procedure
+
+assert_interactive "Please enter the admin password when pompted."
+
+assert_exit 0 xdg-su -c whoami
+assert_stdout out.expected
+assert_nostderr
+
+assert_interactive "Were you prompted for the admin password?" y
+
+test_result
+}
+
+run_test test_su_basic
diff --git a/tests/xdg-su/t.su_basic_asroot b/tests/xdg-su/t.su_basic_asroot
new file mode 100755
index 0000000..e2f1eac
--- /dev/null
+++ b/tests/xdg-su/t.su_basic_asroot
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+## Include utility functions.
+. "$XDG_TEST_DIR/include/testassertions.sh"
+. "$XDG_TEST_DIR/include/testcontrol.sh"
+
+## Test function
+test_su_basic_asroot() {
+test_start "$FUNCTNAME: basic su already root"
+
+test_init
+
+require_root
+assert_display
+
+echo "root" >out.expected
+
+test_procedure
+
+assert_exit 0 xdg-su -c whoami
+assert_stdout out.expected
+assert_nostderr
+
+assert_interactive "Were you prompted for the admin password?" n
+
+test_result
+}
+
+run_test test_su_basic_asroot
diff --git a/tests/xdg-su/t.su_no_carg b/tests/xdg-su/t.su_no_carg
new file mode 100755
index 0000000..53063b9
--- /dev/null
+++ b/tests/xdg-su/t.su_no_carg
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+## Include utility functions.
+. "$XDG_TEST_DIR/include/testassertions.sh"
+. "$XDG_TEST_DIR/include/testcontrol.sh"
+
+## Test function
+test_su_no_carg() {
+test_start "$FUNCTNAME: expected error when -c has no option"
+
+test_procedure
+
+assert_exit 1 xdg-su -c ''
+assert_nostdout
+assert_stderr
+
+assert_interactive "Were you prompted for the admin password?" n
+
+test_result
+}
+
+run_test test_su_no_carg
diff --git a/tests/xdg-su/t.su_no_cflag b/tests/xdg-su/t.su_no_cflag
new file mode 100755
index 0000000..c8e34dd
--- /dev/null
+++ b/tests/xdg-su/t.su_no_cflag
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+## Include utility functions.
+. "$XDG_TEST_DIR/include/testassertions.sh"
+. "$XDG_TEST_DIR/include/testcontrol.sh"
+
+## Test function
+test_su_no_cflag() {
+test_start "$FUNCTNAME: expected error when no -c arg is present"
+test_purpose "Verify bug 7136 has been corrected"
+
+test_procedure
+
+assert_exit 1 xdg-su whoami
+assert_nostdout
+assert_stderr
+
+assert_interactive "Were you prompted for the admin password?" n
+
+test_result
+}
+
+run_test test_su_no_cflag