Permalink
Browse files

I have developed few testsuites for toybox commands -

1. lsattr/chattr
2. mount
3. chmod
4. pgrep/pkill
5. groupadd
6. groupdel
7. useradd
  • Loading branch information...
divya1502 committed Jul 5, 2014
1 parent 4a855d6 commit ef0ed68d5ba5794c1352e64273d4c5039e62476b
View
@@ -0,0 +1,250 @@
#!/bin/bash
# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
#testing "name" "command" "result" "infile" "stdin"
declare -a StrForMod=('---' '--x' '-w-' '-wx' 'r--' 'r-x' 'rw-' 'rwx')
#StrForMod[0]='---'
#StrForMod[1]='--x'
#StrForMod[2]='-w-'
#StrForMod[3]='-wx'
#StrForMod[4]='r--'
#StrForMod[5]='r-x'
#StrForMod[6]='rw-'
#StrForMod[7]='rwx'
# Creating test files to test chmod command
mkdir dir
touch file
for u in {0..7}
do
for g in {0..7}
do
for o in {0..7}
do
rm -rf dir && mkdir dir
uu=${StrForMod[$u]}
gg=${StrForMod[$g]}
oo=${StrForMod[$o]}
testing "chmod $u$g$o dir" "chmod $u$g$o dir &&
ls -ld dir | cut -d' ' -f 1" "d$uu$gg$oo\n" "" ""
done
done
done
for u in {0..7}
do
for g in {0..7}
do
for o in {0..7}
do
rm -rf file && touch file
uu=${StrForMod[$u]}
gg=${StrForMod[$g]}
oo=${StrForMod[$o]}
testing "chmod $u$g$o file" "chmod $u$g$o file &&
ls -ld file | cut -d' ' -f 1" "-$uu$gg$oo\n" "" ""
done
done
done
rm -rf dir file && mkdir dir && touch file
testing "chmod 750 dir 640 file" \
"chmod 750 dir 640 file 2>/dev/null ||
ls -ld dir file | cut -d' ' -f 1" "drwxr-x---\n-rwxr-x---\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod 666 dir file" \
"chmod 666 dir file &&
ls -ld dir file | cut -d' ' -f 1" "drw-rw-rw-\n-rw-rw-rw-\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod 765 *" "chmod 765 * &&
ls -ld dir file | cut -d' ' -f 1" "drwxrw-r-x\n-rwxrw-r-x\n" "" ""
##### u,g,o,a=r,w,x
rm -rf dir file && mkdir dir && touch file
testing "chmod u=r dir file" "chmod u=r dir file &&
ls -ld dir file | cut -d' ' -f 1" "dr--r-xr-x\n-r--r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u=w dir file" "chmod u=w dir file &&
ls -ld dir file | cut -d' ' -f 1" "d-w-r-xr-x\n--w-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u=x dir file" "chmod u=x dir file &&
ls -ld dir file | cut -d' ' -f 1" "d--xr-xr-x\n---xr--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u+r dir file" "chmod u+r dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u+w dir file" "chmod u+w dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u+x dir file" "chmod u+x dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rwxr--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u-r dir file" "chmod u-r dir file &&
ls -ld dir file | cut -d' ' -f 1" "d-wxr-xr-x\n--w-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u-w dir file" "chmod u-w dir file &&
ls -ld dir file | cut -d' ' -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod u-x dir file" "chmod u-x dir file &&
ls -ld dir file | cut -d' ' -f 1" "drw-r-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g=r dir file" "chmod g=r dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr--r-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g=w dir file" "chmod g=w dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwx-w-r-x\n-rw--w-r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g=x dir file" "chmod g=x dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwx--xr-x\n-rw---xr--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g+r dir file" "chmod g+r dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g+w dir file" "chmod g+w dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxrwxr-x\n-rw-rw-r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g+x dir file" "chmod g+x dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r-xr--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g-r dir file" "chmod g-r dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwx--xr-x\n-rw----r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g-w dir file" "chmod g-w dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod g-x dir file" "chmod g-x dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr--r-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o=r dir file" "chmod o=r dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr--\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o=w dir file" "chmod o=w dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-x-w-\n-rw-r---w-\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o=x dir file" "chmod o=x dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-x--x\n-rw-r----x\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o+r dir file" "chmod o+r dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o+w dir file" "chmod o+w dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xrwx\n-rw-r--rw-\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o+x dir file" "chmod o+x dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r-x\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o-r dir file" "chmod o-r dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-x--x\n-rw-r-----\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o-w dir file" "chmod o-w dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod o-x dir file" "chmod o-x dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr--\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a=r dir file" "chmod a=r dir file &&
ls -ld dir file | cut -d' ' -f 1" "dr--r--r--\n-r--r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a=w dir file" "chmod a=w dir file &&
ls -ld dir file | cut -d' ' -f 1" "d-w--w--w-\n--w--w--w-\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a=x dir file" "chmod a=x dir file &&
ls -ld dir file | cut -d' ' -f 1" "d--x--x--x\n---x--x--x\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a+r dir file" "chmod a+r dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a+w dir file" "chmod a+w dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxrwxrwx\n-rw-rw-rw-\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a+x dir file" "chmod a+x dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rwxr-xr-x\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a-r dir file" "chmod a-r dir file &&
ls -ld dir file | cut -d' ' -f 1" "d-wx--x--x\n--w-------\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a-w dir file" "chmod a-w dir file &&
ls -ld dir file | cut -d' ' -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod a-x dir file" "chmod a-x dir file &&
ls -ld dir file | cut -d' ' -f 1" "drw-r--r--\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod =r dir file" "chmod =r dir file &&
ls -ld dir file | cut -d' ' -f 1" "dr--r--r--\n-r--r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod =w dir file" "chmod =w dir file &&
ls -ld dir file | cut -d' ' -f 1" "d-w-------\n--w-------\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod =x dir file" "chmod =x dir file &&
ls -ld dir file | cut -d' ' -f 1" "d--x--x--x\n---x--x--x\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod +r dir file" "chmod +r dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod +w dir file" "chmod +w dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rw-r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod +x dir file" "chmod +x dir file &&
ls -ld dir file | cut -d' ' -f 1" "drwxr-xr-x\n-rwxr-xr-x\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod -r dir file" "chmod -r dir file &&
ls -ld dir file | cut -d' ' -f 1" "d-wx--x--x\n--w-------\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod -w dir file" "chmod -w dir file &&
ls -ld dir file | cut -d' ' -f 1" "dr-xr-xr-x\n-r--r--r--\n" "" ""
rm -rf dir file && mkdir dir && touch file
testing "chmod -x dir file" "chmod -x dir file &&
ls -ld dir file | cut -d' ' -f 1" "drw-r--r--\n-rw-r--r--\n" "" ""
# Removing test files for cleanup purpose
rm -rf dir file
View
@@ -0,0 +1,56 @@
#!/bin/bash
# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
[ -f testing.sh ] && . testing.sh
# 70 characters long string; hereafter, we will use it as per our need.
_s70="abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz123456789"
echo "# usage: addgroup [-g GID] [USER] GROUP
# Add a group or add a user to a group."
# Redirecting all output to /dev/null for grep and delgroup
arg="&>/dev/null"
#testing "name" "command" "result" "infile" "stdin"
testing "groupadd group_name (text)" "groupadd toyTestGroup &&
grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
echo 'yes'" "yes\n" "" ""
testing "groupadd group_name (alphanumeric)" "groupadd toy1Test2Group3 &&
grep '^toy1Test2Group3:' /etc/group $arg && groupdel toy1Test2Group3 $arg &&
echo 'yes'" "yes\n" "" ""
testing "groupadd group_name (numeric)" "groupadd 987654321 &&
grep '^987654321:' /etc/group $arg && groupdel 987654321 $arg &&
echo 'yes'" "yes\n" "" ""
testing "groupadd group_name (with ./-)" "groupadd toy.1Test-2Group.3 &&
grep '^toy.1Test-2Group.3:' /etc/group $arg &&
groupdel toy.1Test-2Group.3 $arg && echo 'yes'" "yes\n" "" ""
_s210=`echo $_s70$_s70$_s70`
testing "groupadd group_name (long string)" "groupadd $_s210 &&
grep '^$_s210:' /etc/group $arg && groupdel $_s210 $arg && echo 'yes'" \
"yes\n" "" ""
testing "groupadd group_name with group_id" "groupadd -g 49999 toyTestGroup &&
grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
echo 'yes'" "yes\n" "" ""
testing "groupadd group_name with group_id (system_group)" \
"groupadd -g 49999 -S toyTestGroup && grep '^toyTestGroup:' /etc/group $arg &&
groupdel toyTestGroup $arg && echo 'yes'" "yes\n" "" ""
testing "groupadd group_name (system_group)" "groupadd -S toyTestGroup &&
grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
echo 'yes'" "yes\n" "" ""
testing "groupadd group_name (add/del user)" "groupadd toyTestGroup &&
grep '^toyTestGroup:' /etc/group $arg && groupadd $USER toyTestGroup &&
grep '^toyTestGroup:.*:.*:.*$USER.*' /etc/group $arg &&
groupdel $USER toyTestGroup $arg || groupdel toyTestGroup &&
grep '^toyTestGroup:' /etc/group $arg || echo 'yes'" "yes\n" "" ""
echo "Testing to add single group multiple times after removing it..."
for each in {01..20}
do
testing "groupadd group_name ($each)" "groupadd toyTestGroup &&
grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
echo 'yes'" "yes\n" "" ""
done
View
@@ -0,0 +1,27 @@
#!/bin/bash
# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
[ -f testing.sh ] && . testing.sh
# Redirecting all output to /dev/null for grep and delgroup
arg="&>/dev/null"
#testing "name" "command" "result" "infile" "stdin"
testing "groupadd group_name (text)" "groupadd toyTestGroup &&
grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
echo 'yes'" "yes\n" "" ""
testing "groupadd group_name (alphanumeric)" "groupadd toy1Test2Group3 &&
grep '^toy1Test2Group3:' /etc/group $arg && groupdel toy1Test2Group3 $arg &&
echo 'yes'" "yes\n" "" ""
testing "groupadd group_name (numeric)" "groupadd 987654321 &&
grep '^987654321:' /etc/group $arg && groupdel 987654321 $arg &&
echo 'yes'" "yes\n" "" ""
testing "groupadd group_name (with ./-)" "groupadd toy.1Test-2Group.3 &&
grep '^toy.1Test-2Group.3:' /etc/group $arg &&
groupdel toy.1Test-2Group.3 $arg && echo 'yes'" "yes\n" "" ""
testing "groupadd group_name with group_id" "groupadd -g 49999 toyTestGroup &&
grep '^toyTestGroup:' /etc/group $arg && groupdel toyTestGroup $arg &&
echo 'yes'" "yes\n" "" ""
Oops, something went wrong.

0 comments on commit ef0ed68

Please sign in to comment.