Add tests from the old svn tree

We're losing the svn history (which we could probably keep if we tried
hard enough) but don't consider that worthwhile.

Note these tests are destructive, so run them only in a throwaway
environment like a chroot, container, or vm.

The tests/run.all script should be the one which launches all the tests.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Serge Hallyn
2014-09-17 14:42:55 -05:00
parent 2cb54158b8
commit b999d48941
8970 changed files with 336314 additions and 0 deletions

1
tests/chsh/01/data/chsh1 Normal file
View File

@@ -0,0 +1 @@
You may not change the shell for 'myuser'.

1
tests/chsh/01/data/chsh2 Normal file
View File

@@ -0,0 +1 @@
You may not change the shell for 'myuser2'.

42
tests/chsh/01/data/group Normal file
View File

@@ -0,0 +1,42 @@
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
kmem:x:15:
dialout:x:20:
fax:x:21:
voice:x:22:
cdrom:x:24:
floppy:x:25:
tape:x:26:
sudo:x:27:
audio:x:29:
dip:x:30:
www-data:x:33:
backup:x:34:
operator:x:37:
list:x:38:
irc:x:39:
src:x:40:
gnats:x:41:
shadow:x:42:
utmp:x:43:
video:x:44:
sasl:x:45:
plugdev:x:46:
staff:x:50:
games:x:60:
users:x:100:
nogroup:x:65534:
crontab:x:101:
Debian-exim:x:102:
myuser:x:424242:

View File

@@ -0,0 +1,42 @@
root:*::
daemon:*::
bin:*::
sys:*::
adm:*::
tty:*::
disk:*::
lp:*::
mail:*::
news:*::
uucp:*::
man:*::
proxy:*::
kmem:*::
dialout:*::
fax:*::
voice:*::
cdrom:*::
floppy:*::
tape:*::
sudo:*::
audio:*::
dip:*::
www-data:*::
backup:*::
operator:*::
list:*::
irc:*::
src:*::
gnats:*::
shadow:*::
utmp:*::
video:*::
sasl:*::
plugdev:*::
staff:*::
games:*::
users:*::
nogroup:*::
crontab:x::
Debian-exim:x::
myuser:x::

21
tests/chsh/01/data/passwd Normal file
View File

@@ -0,0 +1,21 @@
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
irc:x:39:39:ircd:/var/run/ircd:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
Debian-exim:x:102:102::/var/spool/exim4:/bin/false
myuser:x:424242:424242::/home:/bin/bash
myuser2:x:424243:424242::/home:/bin/sh

21
tests/chsh/01/data/shadow Normal file
View File

@@ -0,0 +1,21 @@
root:$1$NBLBLIXb$WUgojj1bNuxWEADQGt1m9.:12991:0:99999:7:::
daemon:*:12977:0:99999:7:::
bin:*:12977:0:99999:7:::
sys:*:12977:0:99999:7:::
sync:*:12977:0:99999:7:::
games:*:12977:0:99999:7:::
man:*:12977:0:99999:7:::
lp:*:12977:0:99999:7:::
mail:*:12977:0:99999:7:::
news:*:12977:0:99999:7:::
uucp:*:12977:0:99999:7:::
proxy:*:12977:0:99999:7:::
www-data:*:12977:0:99999:7:::
backup:*:12977:0:99999:7:::
list:*:12977:0:99999:7:::
irc:*:12977:0:99999:7:::
gnats:*:12977:0:99999:7:::
nobody:*:12977:0:99999:7:::
Debian-exim:!:12977:0:99999:7:::
myuser:$1$yQnIAZWV$gDAMB2IkqaONgrQiRdo4y.:12991:0:99999:7:::
myuser2:$1$yQnIAZWV$gDAMB2IkqaONgrQiRdo4y.:12991:0:99999:7:::

16
tests/chsh/01/data/shells Normal file
View File

@@ -0,0 +1,16 @@
# /etc/shells: valid login shells
/bin/ash
/bin/csh
/bin/sh
/usr/bin/es
/usr/bin/ksh
/bin/ksh
/usr/bin/rc
/usr/bin/tcsh
/bin/tcsh
/usr/bin/zsh
/bin/sash
/bin/zsh
/usr/bin/esh
/bin/bash
/bin/rbash

143
tests/chsh/01/run Executable file
View File

@@ -0,0 +1,143 @@
#!/bin/sh
set -e
cd $(dirname $0)
# Rational:
# Test chage options
# no testsuite password
# root password: rootF00barbaz
# myuser password: myuserF00barbaz
save()
{
[ ! -d tmp ] && mkdir tmp
for i in passwd group shadow gshadow shells
do
[ -f /etc/$i ] && cp /etc/$i tmp/$i
[ -f /etc/$i- ] && cp /etc/$i- tmp/$i-
done
true
}
restore()
{
for i in passwd group shadow gshadow shells
do
[ -f tmp/$i ] && cp tmp/$i /etc/$i && rm tmp/$i
[ -f tmp/$i- ] && cp tmp/$i- /etc/$i- && rm tmp/$i-
done
rm -f tmp/out
rm -f tmp/shell tmp/sh:ell
rmdir tmp
}
save
# restore the files on exit
trap 'if [ "$?" != "0" ]; then echo "FAIL"; fi; restore' 0
for i in passwd group shadow gshadow shells
do
cp data/$i /etc
done
echo -n "changing to a restricted shell, by root..."
cp /bin/bash tmp/shell
chsh -s $(pwd)/tmp/shell myuser
ent=$(getent passwd myuser)
[ "$ent" = "myuser:x:424242:424242::/home:"$(pwd)"/tmp/shell" ] || exit 1
echo "OK"
echo -n "changing from a restricted shell, by myuser..."
su myuser -c "chsh -s /bin/bash" 2> tmp/out && exit 1
ent=$(getent passwd myuser)
[ "$ent" = "myuser:x:424242:424242::/home:"$(pwd)"/tmp/shell" ] || exit 1
diff -au data/chsh1 tmp/out
echo "OK"
echo -n "changing from a restricted shell, by root..."
chsh -s /bin/bash myuser
ent=$(getent passwd myuser)
[ "$ent" = "myuser:x:424242:424242::/home:/bin/bash" ] || exit 1
echo "OK"
# Need to be done by expect now (chage asks for a passwd if not root)
#echo -n "changing to a restricted shell, by myuser..."
#su myuser -c "chsh -s $(pwd)/tmp/shell" 2> tmp/out && exit 1
#ent=$(getent passwd myuser)
#[ "$ent" = "myuser:x:424242:424242::/home:/bin/bash" ] || exit 1
#grep "/tmp/shell is an invalid shell." tmp/out > /dev/null
#[ $(wc -l tmp/out| cut -d" " -f1) = "1" ] || exit 1
#echo "OK"
#echo -n "changing to a new valid shell, by myuser..."
#echo $(pwd)/tmp/shell >> /tmp/shells
#su myuser -c "chsh -s $(pwd)/tmp/shell" 2> tmp/out && exit 1
#ent=$(getent passwd myuser)
#[ "$ent" = "myuser:x:424242:424242::/home:/bin/bash" ] || exit 1
#grep "/tmp/shell is an invalid shell." tmp/out > /dev/null
#[ $(wc -l tmp/out| cut -d" " -f1) = "1" ] || exit 1
#echo "OK"
echo -n "changing another user's shell..."
su myuser -c "chsh -s /bin/sh myuser2" 2> tmp/out && exit 1
ent=$(getent passwd myuser2)
[ "$ent" = "myuser2:x:424243:424242::/home:/bin/sh" ] || exit 1
diff -au data/chsh2 tmp/out
echo "OK"
#echo -n "changing to a non-executable shell..."
#chmod a-x tmp/shell
#su myuser -c "chsh -s $(pwd)/tmp/shell myuser" 2> tmp/out && exit 1
#ent=$(getent passwd myuser)
#[ "$ent" = "myuser:x:424242:424242::/home:/bin/bash" ] || exit 1
#grep "/tmp/shell is an invalid shell." tmp/out > /dev/null
#[ $(wc -l tmp/out| cut -d" " -f1) = "1" ] || exit 1
#echo "OK"
echo -n "changing to an invalid shell name..."
cp /bin/bash tmp/sh:ell
echo $(pwd)/tmp/sh:ell >> /etc/shells
chsh -s $(pwd)/tmp/sh:ell myuser 2> tmp/out && exit 1
ent=$(getent passwd myuser)
[ "$ent" = "myuser:x:424242:424242::/home:/bin/bash" ] || exit 1
egrep "chsh: Invalid entry: .*/tmp/sh:ell" tmp/out > /dev/null
[ $(wc -l tmp/out| cut -d" " -f1) = "1" ] || exit 1
echo "OK"
echo "testing the interactive mode (1)..."
rm -f tmp/out
./run.exp /bin/bash myuser
[ -f tmp/out ] && exit 1
ent=$(getent passwd myuser)
[ "$ent" = "myuser:x:424242:424242::/home:/bin/bash" ] || exit 1
echo "OK"
#echo "testing the interactive mode (2)..."
#rm -f tmp/out
#su myuser -c "./run.exp /bin/bash"
#[ -f tmp/out ] && exit 1
#ent=$(getent passwd myuser)
#[ "$ent" = "myuser:x:424242:424242::/home:/bin/bash" ] || exit 1
#echo "OK"
echo "testing the interactive mode (3)..."
rm -f tmp/out
./run.exp /bin/sh myuser
[ -f tmp/out ] && exit 1
ent=$(getent passwd myuser)
[ "$ent" = "myuser:x:424242:424242::/home:/bin/sh" ] || exit 1
echo "OK"
echo "testing the interactive mode (4)..."
rm -f tmp/out
./run.exp $(pwd)/tmp/sh:ell myuser && exit 1
egrep "chsh: Invalid entry: .*/tmp/sh:ell" tmp/out > /dev/null
ent=$(getent passwd myuser)
[ "$ent" = "myuser:x:424242:424242::/home:/bin/sh" ] || exit 1
echo "OK"

38
tests/chsh/01/run.exp Executable file
View File

@@ -0,0 +1,38 @@
#!/usr/bin/expect
set timeout 5
if {$argc < 1} {
puts "usage: run.exp \[shell] \[user]"
exit 1
}
set shell [lindex $argv 0]
if {$argc == 2} {
spawn /usr/bin/chsh [lindex $argv 1]
} else {
spawn /usr/bin/chsh
}
expect "Changing the login shell for myuser"
expect "Enter the new value, or press ENTER for the default"
expect -re "Login Shell .*\]: "
send "$shell\r"
expect "$shell\r\n"
expect {
eof {
if ([string compare $expect_out(buffer) ""]) {
set fp [open "tmp/out" w]
puts $fp "$expect_out(buffer)"
puts "\nFAIL"
exit 1
}
} default {
puts "\nFAIL"
exit 1
}
}
puts "\nPASS"
exit 0