summaryrefslogtreecommitdiff
path: root/test/mocklibc/bin/mocklibc-test.in
diff options
context:
space:
mode:
authorNikki VonHollen <vonhollen@google.com>2011-12-20 15:11:23 -0800
committerDavid Zeuthen <davidz@redhat.com>2011-12-22 17:59:33 -0500
commit674357c20c1b6cb421fea6eb6924b274ec477c0e (patch)
treef434c0d7f0e0d5d932ce6e8b27fad31005b92d5f /test/mocklibc/bin/mocklibc-test.in
parent15d2e90a54009efb31300d8b59292d71ce98a5b2 (diff)
Bug 43610 - Add netgroup support
https://bugs.freedesktop.org/show_bug.cgi?id=43610 Added netgroup support and additional unit tests with MockLibc support. Signed-off-by: David Zeuthen <davidz@redhat.com>
Diffstat (limited to 'test/mocklibc/bin/mocklibc-test.in')
-rw-r--r--test/mocklibc/bin/mocklibc-test.in136
1 files changed, 136 insertions, 0 deletions
diff --git a/test/mocklibc/bin/mocklibc-test.in b/test/mocklibc/bin/mocklibc-test.in
new file mode 100644
index 0000000..9f00a77
--- /dev/null
+++ b/test/mocklibc/bin/mocklibc-test.in
@@ -0,0 +1,136 @@
+#!/bin/bash
+
+# Copyright 2011 Google Inc. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Author: Nikki VonHollen <vonhollen@gmail.com>
+
+
+# Figure out where everything is
+
+MOCKLIBC="@top_builddir@/bin/mocklibc"
+ETCDIR="@top_srcdir@/example"
+
+
+# Setup the mock environment
+
+export MOCK_PASSWD="${ETCDIR}/passwd"
+export MOCK_GROUP="${ETCDIR}/group"
+export MOCK_NETGROUP="${ETCDIR}/netgroup"
+
+
+# Test helper definitions
+
+TESTCOUNT=0
+FAILCOUNT=0
+
+fail () {
+ echo "Test Failed:"
+ echo $@ >&2
+ echo
+ FAILCOUNT=$((FAILCOUNT+1))
+}
+
+finish () {
+ if [[ $FAILCOUNT -gt 0 ]]
+ then
+ echo "Failed $FAILCOUNT of $TESTCOUNT tests."
+ exit 1
+ else
+ echo "Passed $TESTCOUNT tests."
+ exit 0
+ fi
+}
+
+assert_true () {
+ $MOCKLIBC $@ || fail "assert true: $@"
+ TESTCOUNT=$((TESTCOUNT+1))
+}
+
+assert_false () {
+ $MOCKLIBC $@ && fail "assert false: $@"
+ TESTCOUNT=$((TESTCOUNT+1))
+}
+
+assert_grep () {
+ $MOCKLIBC ${@:2} | grep -q "^${1}\$" || fail "'$1' doesn't match output of: ${@:2}"
+ TESTCOUNT=$((TESTCOUNT+1))
+}
+
+
+# Test implementations
+
+test_passwd () {
+ # Test user ids
+ assert_grep "0" id -u root
+ assert_grep "500" id -u john
+ assert_grep "501" id -u jane
+
+ # Test primary groups
+ assert_grep "root" id -gn root
+ assert_grep "john" id -gn john
+ assert_grep "jane" id -gn jane
+}
+
+test_group () {
+ # Test group lists for users
+ assert_grep "root" id -Gn root
+ assert_grep "john users" id -Gn john
+ assert_grep "jane users" id -Gn jane
+}
+
+test_netgroup () {
+ # Test whether each user is each netgroup
+ assert_true innetgr foo -u john
+ assert_false innetgr foo -u jane
+
+ assert_true innetgr bar -u jane
+ assert_false innetgr bar -u john
+
+ assert_true innetgr baz -u john
+ assert_true innetgr baz -u jane
+ assert_false innetgr baz -u henry
+
+ assert_true innetgr all -u john
+ assert_true innetgr all -u jane
+ assert_true innetgr all -u henry
+
+ assert_false innetgr none -u john
+ assert_false innetgr none -u jane
+ assert_false innetgr none -u henry
+
+ assert_false innetgr fake -u john
+}
+
+
+# Run the tests and print a report
+
+if (which id >/dev/null 2>&1)
+then
+ test_passwd
+ test_group
+else
+ echo "No 'id' command found, skipping passwd and group tests." >&2
+fi
+
+if (which innetgr >/dev/null 2>&1)
+then
+ test_netgroup
+else
+ echo "No 'innetgr' command found, skipping netgroup tests." >&2
+fi
+
+
+finish
+