[Pkg-shadow-commits] r1073 - in trunk/tests: . usertools/01
Nicolas FRANCOIS
nekral-guest at costa.debian.org
Sat Aug 5 23:39:23 UTC 2006
Author: nekral-guest
Date: 2006-08-05 23:39:22 +0000 (Sat, 05 Aug 2006)
New Revision: 1073
Added:
trunk/tests/usertools/01/run5
Modified:
trunk/tests/run_all
Log:
New tests for useradd -g
Modified: trunk/tests/run_all
===================================================================
--- trunk/tests/run_all 2006-08-05 01:57:17 UTC (rev 1072)
+++ trunk/tests/run_all 2006-08-05 23:39:22 UTC (rev 1073)
@@ -30,6 +30,7 @@
run_test ./usertools/01/run2
run_test ./usertools/01/run3
run_test ./usertools/01/run4
+run_test ./usertools/01/run5
echo "$succeded test(s) passed"
echo "$failed test(s) failed"
Added: trunk/tests/usertools/01/run5
===================================================================
--- trunk/tests/usertools/01/run5 2006-08-05 01:57:17 UTC (rev 1072)
+++ trunk/tests/usertools/01/run5 2006-08-05 23:39:22 UTC (rev 1073)
@@ -0,0 +1,183 @@
+#!/bin/sh
+
+set -e
+
+cd $(dirname $0)
+
+# Rational:
+# Test useradd -g
+# It must reject negative GID
+# accept textual and numerical groups
+
+save()
+{
+ [ ! -d tmp ] && mkdir tmp
+ for i in passwd group shadow gshadow
+ do
+ [ -f /etc/$i ] && cp /etc/$i tmp/$i
+ done
+
+ true
+}
+
+restore()
+{
+ for i in passwd group shadow gshadow
+ do
+ [ -f tmp/$i ] && cp tmp/$i /etc/$i && rm tmp/$i
+ done
+ rmdir tmp
+}
+
+save
+
+# restore the files on exit
+trap 'restore' 0
+
+cp data/{passwd,shadow,group,gshadow} /etc/
+
+lines_passwd=$(wc -l /etc/passwd | cut -f1 -d" ")
+lines_shadow=$(wc -l /etc/shadow | cut -f1 -d" ")
+lines_group=$(wc -l /etc/group | cut -f1 -d" ")
+lines_gshadow=$(wc -l /etc/gshadow | cut -f1 -d" ")
+
+################################################################################
+echo -n "Create user test1 in the non existent group -1..."
+msg=$(useradd test1 -g -1 2>&1) && echo "should have failed" || test "$?" = "6"
+test "$msg" = "useradd: unknown group -1"
+echo "OK"
+
+################################################################################
+echo -n "Create user test2 in the non existent group nekral..."
+msg=$(useradd test2 -g nekral 2>&1) && echo "should have failed" || test "$?" = "6"
+test "$msg" = "useradd: unknown group nekral"
+echo "OK"
+
+################################################################################
+echo -n "Create user test3 in group daemon (1)..."
+useradd test3 -g 1
+
+echo "test if the user was added"
+echo -n " passwd..."
+getent passwd test3 |
+ egrep "^test3:x:([0-9]+):1::/home/test3:/bin/sh$"
+echo " OK"
+uid=$(getent passwd test3|sed -ne "s/test3:x:\([0-9]*\):.*/\\1/p")
+# uid must be greater than UID_MIN (in login.defs)
+echo -n " uid: $uid < 1000..."
+test $uid -ge 1000
+echo " OK"
+echo -n " no group test3..."
+getent group test3 | egrep "^test3:x:$uid:$" && false || true
+echo " OK"
+echo -n " shadow..."
+getent shadow test3 | egrep "^test3:!:[0-9]+:0:99999:7:::$"
+echo " OK"
+echo -n " no group test3 in gshadow..."
+egrep "^test3:!::$" /etc/gshadow && false || true
+echo " OK"
+# the home directory should not exist
+echo -n " no homedir..."
+test -d /home/test3 && exit 1 || true
+echo " OK"
+echo -n " number of lines"
+test $(( lines_passwd + 1 )) = $(wc -l /etc/passwd | cut -f1 -d" ")
+echo -n "."
+test $(( lines_group )) = $(wc -l /etc/group | cut -f1 -d" ")
+echo -n "."
+test $(( lines_shadow + 1 )) = $(wc -l /etc/shadow | cut -f1 -d" ")
+echo -n "."
+test $(( lines_gshadow )) = $(wc -l /etc/gshadow | cut -f1 -d" ")
+echo -n "."
+echo " OK"
+
+echo -n "delete this user..."
+userdel test3
+echo "OK"
+
+echo "check if the user was deleted"
+echo -n " no entries..."
+egrep "^test3:" \
+ /etc/passwd /etc/group /etc/shadow /etc/gshadow && exit 1 || true
+echo " OK"
+echo -n " no homedir..."
+test -d /home/test3 && exit 1 || true
+echo " OK"
+echo -n " number of lines"
+test $lines_passwd = $(wc -l /etc/passwd | cut -f1 -d" ")
+echo -n "."
+test $lines_group = $(wc -l /etc/group | cut -f1 -d" ")
+echo -n "."
+test $lines_shadow = $(wc -l /etc/shadow | cut -f1 -d" ")
+echo -n "."
+test $lines_gshadow = $(wc -l /etc/gshadow | cut -f1 -d" ")
+echo -n "."
+echo " OK"
+
+################################################################################
+echo -n "Create user test4 in group nogroup..."
+useradd test4 -g nogroup
+
+echo "test if the user was added"
+echo -n " passwd..."
+getent passwd test4 |
+ egrep "^test4:x:([0-9]+):65534::/home/test4:/bin/sh$"
+echo " OK"
+uid=$(getent passwd test4|sed -ne "s/test4:x:\([0-9]*\):.*/\\1/p")
+# uid must be greater than UID_MIN (in login.defs)
+echo -n " uid: $uid < 1000..."
+test $uid -ge 1000
+echo " OK"
+echo -n " no group test4..."
+getent group test4 | egrep "^test4:x:$uid:$" && false || true
+echo " OK"
+echo -n " test4 in group nogroup..."
+egrep "^nogroup:x:65534:$" /etc/group
+echo " OK"
+echo -n " shadow..."
+getent shadow test4 | egrep "^test4:!:[0-9]+:0:99999:7:::$"
+echo " OK"
+echo -n " no group test4 in gshadow..."
+egrep "^test4:!::$" /etc/gshadow && false || true
+echo " OK"
+echo -n " test4 in group nogroup (in gshadow)..."
+egrep "^nogroup:\*::$" /etc/gshadow
+echo " OK"
+# the home directory should not exist
+echo -n " no homedir..."
+test -d /home/test4 && exit 1 || true
+echo " OK"
+echo -n " number of lines"
+test $(( lines_passwd + 1 )) = $(wc -l /etc/passwd | cut -f1 -d" ")
+echo -n "."
+test $(( lines_group )) = $(wc -l /etc/group | cut -f1 -d" ")
+echo -n "."
+test $(( lines_shadow + 1 )) = $(wc -l /etc/shadow | cut -f1 -d" ")
+echo -n "."
+test $(( lines_gshadow )) = $(wc -l /etc/gshadow | cut -f1 -d" ")
+echo -n "."
+echo " OK"
+
+echo -n "delete this user..."
+userdel test4
+echo "OK"
+
+echo "check if the user was deleted"
+echo -n " no entries..."
+egrep "^test4:" \
+ /etc/passwd /etc/group /etc/shadow /etc/gshadow && exit 1 || true
+echo " OK"
+echo -n " no homedir..."
+test -d /home/test4 && exit 1 || true
+echo " OK"
+echo -n " number of lines"
+test $lines_passwd = $(wc -l /etc/passwd | cut -f1 -d" ")
+echo -n "."
+test $lines_group = $(wc -l /etc/group | cut -f1 -d" ")
+echo -n "."
+test $lines_shadow = $(wc -l /etc/shadow | cut -f1 -d" ")
+echo -n "."
+test $lines_gshadow = $(wc -l /etc/gshadow | cut -f1 -d" ")
+echo -n "."
+echo " OK"
+
Property changes on: trunk/tests/usertools/01/run5
___________________________________________________________________
Name: svn:executable
+ *
More information about the Pkg-shadow-commits
mailing list