# HG changeset patch # User Divya Kothari # Date 1404526802 18000 # Node ID 7a2aec0876feca80bcc1e0cc68c90d5165a3a4f1 # Parent 7dd487ddd7dcbaa52f9594ce3dfa32bb2f7757e1 I have developed few testsuites for toybox commands - 1. lsattr/chattr 2. mount 3. chmod 4. pgrep/pkill 5. groupadd 6. groupdel 7. useradd diff -r 7dd487ddd7dc -r 7a2aec0876fe scripts/test/chmod.test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/test/chmod.test Fri Jul 04 21:20:02 2014 -0500 @@ -0,0 +1,250 @@ +#!/bin/bash + +# Copyright 2013 Divya Kothari +# Copyright 2013 Robin Mittal + +#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 diff -r 7dd487ddd7dc -r 7a2aec0876fe scripts/test/groupadd.test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/test/groupadd.test Fri Jul 04 21:20:02 2014 -0500 @@ -0,0 +1,56 @@ +#!/bin/bash +# Copyright 2013 Divya Kothari +# Copyright 2013 Robin Mittal + +[ -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 diff -r 7dd487ddd7dc -r 7a2aec0876fe scripts/test/groupdel.test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/test/groupdel.test Fri Jul 04 21:20:02 2014 -0500 @@ -0,0 +1,27 @@ +#!/bin/bash + +# Copyright 2013 Divya Kothari +# Copyright 2013 Robin Mittal + +[ -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" "" "" diff -r 7dd487ddd7dc -r 7a2aec0876fe scripts/test/lsattr.test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/test/lsattr.test Fri Jul 04 21:20:02 2014 -0500 @@ -0,0 +1,159 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# chattr - Testcases + +mkdir testattr +IN="cd testattr" +OUT="cd .." +_t="abcdefghijklmnopqrstuvwxyz" + +testing "chattr [-/+]i FILE[write]" "$IN && echo "$_t" > testFile && + chattr +i testFile && lsattr testFile && echo "$_t" > testFile; + chattr -i testFile; rm -rf testFile; $OUT " "----i-------- testFile\n" "" "" +testing "chattr [-/+]i FILE[re-write]" "$IN && echo "$_t" > testFile && + chattr +i testFile && echo \"$_t\" > testFile || chattr -i testFile && + echo \"$_t\" > testFile && lsattr testFile; rm -rf testFile; $OUT" \ + "------------- testFile\n" "" "" +testing "chattr [-/+]i FILE[append]" "$IN && echo "$_t" > testFile && + chattr +i testFile && echo \"$_t\" >> testFile || lsattr testFile && + chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" "" +testing "chattr [-/+]i FILE[move]" "$IN && echo "$_t" > testFile && + chattr +i testFile && mv testFile testFile1 || lsattr testFile && + chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" "" +testing "chattr [-/+]i FILE[delete]" "$IN && echo "$_t" > testFile && + chattr +i testFile && rm -f testFile || lsattr testFile && + chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" "" +testing "chattr [-/+]i FILE[read]" "$IN && echo "$_t" > testFile && + chattr +i testFile && cat testFile && lsattr testFile && + chattr -i testFile; rm -rf testFile; $OUT" "$_t\n----i-------- testFile\n" "" "" +testing "chattr [-/+]a FILE[write]" "$IN && echo "$_t" > testFile && + chattr +a testFile && echo $_t > testFile || lsattr testFile && + chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" "" +testing "chattr [-/+]a FILE[re-write]" "$IN && echo "$_t" > testFile && + chattr +a testFile && echo $_t > testFile || lsattr testFile && + chattr -a testFile && echo $_t > testFile && cat testFile && + lsattr testFile; rm -rf testFile; + $OUT" "-----a------- testFile\n$_t\n------------- testFile\n" "" "" +testing "chattr [-/+]a FILE[append]" "$IN && echo "$_t" > testFile && + chattr +a testFile && echo $_t >> testFile && cat testFile && + lsattr testFile && chattr -a testFile; rm -rf testFile; $OUT" \ + "$_t\n$_t\n-----a------- testFile\n" "" "" +testing "chattr [-/+]a FILE[move]" "$IN && echo "$_t" > testFile && + chattr +a testFile && mv testFile testFile1 || lsattr testFile && + chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" "" +testing "chattr [-/+]a FILE[delete]" "$IN && echo "$_t" > testFile && + chattr +a testFile && rm -f testFile || lsattr testFile && + chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" "" +testing "chattr [-/+]a FILE[read]" "$IN && echo "$_t" > testFile && + chattr +a testFile && cat testFile && lsattr testFile && chattr -a testFile; + rm -rf testFile; $OUT" "$_t\n-----a------- testFile\n" "" "" + +for attr in "A" "a" "c" "D" "d" "i" "j" "s" "S" "t" "T" "u" +do + testing "chattr [-/+]$attr FILE" "$IN && echo "$_t" > testFile && + chattr +$attr testFile && cat testFile && chattr -$attr testFile && + lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" "" +done + +for attr in "A" "a" "c" "D" "d" "i" "j" "s" "S" "t" "T" "u" +do + testing "chattr -$attr FILE" "$IN && echo "$_t" > testFile && chattr -$attr testFile && + cat testFile && lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" "" +done + +testing "chattr [-/+]AacDdijsStTu FILE" "$IN && echo "$_t" > testFile && + chattr +AacDdijsStTu testFile && cat testFile && chattr -AacDdijsStTu testFile && + lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" "" +testing "chattr [-/+]AacDdijsStTu(random) FILE" \ + "$IN && echo "$_t" > testFile && + chattr +AacDdijsStTu testFile && cat testFile && chattr -A testFile && + chattr -a testFile && chattr -c testFile && chattr -D testFile && + chattr -d testFile && chattr -i testFile && chattr -j testFile && + chattr -s testFile && chattr -S testFile && chattr -t testFile && + chattr -T testFile && chattr -u testFile && lsattr testFile && + chattr -AacDdijsStTu testFile; rm -rf testFile; $OUT" \ + "$_t\n------------- testFile\n" "" "" +testing "chattr [-/+]AacDdijsStTu FILE*" "$IN && + echo "$_t" > testFile && echo "$_t" > testFile1 && + echo "$_t" > testFile2 && echo "$_t" > testFile3 && + echo "$_t" > testFile4 && echo "$_t" > testFile5 && + echo "$_t" > testFile6 && echo "$_t" > testFile7 && + echo "$_t" > testFile8 && echo "$_t" > testFile9 && + echo "$_t" > testFile10 && echo "$_t" > testFile11 && + chattr +AacDdijsStTu testFile* && + cat testFile9 && chattr -AacDdijsStTu testFile* && lsattr testFile*; rm -rf testFile*; $OUT" \ + "$_t\n------------- testFile\n------------- testFile1\n------------- testFile10\n------------- testFile11\n------------- testFile2\n------------- testFile3\n------------- testFile4\n------------- testFile5\n------------- testFile6\n------------- testFile7\n------------- testFile8\n------------- testFile9\n" "" "" +testing "chattr [-/+]AacDdijsStTu(random) FILE*" \ + "$IN && echo "$_t" > testFile && + chattr +AacDdijsStTu testFile* && cat testFile && chattr -A testFile* && + chattr -a testFile* && chattr -c testFile* && chattr -D testFile* && + chattr -d testFile* && chattr -i testFile* && chattr -j testFile* && + chattr -s testFile* && chattr -S testFile* && chattr -t testFile* && + chattr -T testFile* && chattr -u testFile* && lsattr testFile; + rm -rf testFile; $OUT" \ + "$_t\n------------- testFile\n" "" "" +testing "chattr [-/+]i FILE[write]" \ + "$IN && echo "$_t" > testFile && + chattr +i testFile && + echo \"$_t\" > testFile || lsattr testFile && chattr -i testFile; + rm -rf testFile; $OUT" "----i-------- testFile\n" "" "" +testing "chattr [-/+]A FILE[write]" \ + "$IN && echo "$_t" > testFile && chattr +A testFile && + echo \"$_t\" > testFile && lsattr testFile && chattr -A testFile; + rm -rf testFile; $OUT" "-------A----- testFile\n" "" "" +testing "chattr [-/+]s FILE[write]" \ + "$IN && echo "$_t" > testFile && chattr +s testFile && + echo \"$_t\" > testFile && lsattr testFile && chattr -s testFile + rm -rf testFile; $OUT" "s------------ testFile\n" "" "" +testing "chattr -v version FILE[write]" \ + "$IN && echo "$_t" > testFile && + chattr -v 1234 testFile && echo \"$_t\" > testFile && + lsattr -v testFile; rm -rf testFile" \ + " 1234 ------------- testFile\n" "" "" + +_a="-------A-----" +testing "chattr -R [-/+]a FILE" "$IN && touch aa && chattr -R +A aa && lsattr aa && + chattr -R -A aa; rm -rf aa; $OUT" "$_a aa\n" "" "" +testing "chattr -R [-/+]a FILE.." "$IN && touch aa bb && + chattr -R +A aa bb && lsattr aa bb && + chattr -R -A aa bb; rm -rf aa bb; $OUT" "$_a aa\n$_a bb\n" "" "" + +# Clean up +rm -rf testattr + +# lsattr - Testcases +mkdir dir && cd dir && touch file +chattr +A file &>/dev/null + +_p=$PWD +_b="-------------" +_A="-------A-----" + +testing "lsattr file" "lsattr file" "$_A file\n" "" "" +testing "lsattr file_path" "lsattr $_p/file" "$_A $_p/file\n" "" "" +testing "lsattr -R file" "lsattr -R file" "$_A file\n" "" "" +testing "lsattr -R file_path" "lsattr -R $_p/file" "$_A $_p/file\n" "" "" +testing "lsattr -a file" "lsattr -a file" "$_A file\n" "" "" +testing "lsattr -a file_path" "lsattr -a $_p/file" "$_A $_p/file\n" "" "" +testing "lsattr -d ." "lsattr -d ." "$_b .\n" "" "" +testing "lsattr -d dir_path" "lsattr -d $_p" "$_b $_p\n" "" "" +testing "lsattr -d file" "lsattr -d file" "$_A file\n" "" "" +testing "lsattr -d file_path" "lsattr -d $_p/file" "$_A $_p/file\n" "" "" +sp_44=" " +testing "lsattr -l file" "lsattr -l file" "file $sp_44 No_Atime\n" "" "" +_v="12345" +testing "lsattr -v file" "chattr -v $_v * && lsattr -v file" \ + "$_v $_A file\n" "" "" +testing "lsattr -v file_path" "chattr -v $_v * && lsattr -v $_p/file" \ + "$_v $_A $_p/file\n" "" "" +testing "lsattr -Radlv file1 file2" "chattr -v $_v * && + lsattr -Radlv file input" \ + "$_v file $sp_44 No_Atime\n$_v input $sp_44 ---\n" "" "" + +# Cleanup +chattr -AacDdijsStTu file && cd .. +rm -rf dir diff -r 7dd487ddd7dc -r 7a2aec0876fe scripts/test/mount.test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/test/mount.test Fri Jul 04 21:20:02 2014 -0500 @@ -0,0 +1,87 @@ +#!/bin/bash + +# Copyright 2013 Divya Kothari +# Copyright 2013 Robin Mittal + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +root_fs=`df | grep "\/$" | awk '{print $1}'` +root_fs_type=`file -sL $root_fs | awk '{print $5}'` + +tmp_b_fs="tmp_b_fs" +tmp_b_fs_type="ext3" + +reCreateTmpFs() { + rm -rf $tmp_b_fs + mknod $tmp_b_fs b 1 0 + mkfs.ext3 $tmp_b_fs >/dev/null 2>&1 +} +reCreateTmpFs + +testing "mount $root_fs /mnt" \ + "mount $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" "" +testing "mount $tmp_b_fs /mnt" \ + "mount $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" "" +reCreateTmpFs + +chmod 444 /mnt +testing "mount $root_fs /mnt (read_only dir)" \ + "mount $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" "" +testing "mount $tmp_b_fs /mnt (read_only dir)" \ + "mount $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" "" +reCreateTmpFs +chmod 755 /mnt +testing "mount -w $root_fs /mnt (write_only mode)" \ + "mount -w $root_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && test -e /testDir && rmdir /testDir" "" "" "" +testing "mount -w $tmp_b_fs /mnt (write_only mode)" \ + "mount -w $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" "" +reCreateTmpFs +testing "mount -rw $tmp_b_fs /mnt (read_write mode)" \ + 'mount -rw $tmp_b_fs /mnt >/dev/null && mkdir /mnt/testDir && \ + sleep 1 && ! test -e /mnt/testDir && umount /mnt' "" "" "" +reCreateTmpFs +testing "mount $tmp_b_fs /mnt -t fs_type" \ + "mount $tmp_b_fs /mnt -t $tmp_b_fs_type >/dev/null 2>&1 && + mkdir /mnt/testDir && sleep 1 && umount /mnt && + ! test -e /mnt/testDir" "" "" "" +reCreateTmpFs +mkdir -p testDir1/testDir2 testDir +echo "abcdefghijklmnopqrstuvwxyz" > testDir1/testDir2/testFile +testing "mount -o bind dir1 dir2" \ + 'mount -o bind testDir1 testDir >/dev/null 2>&1 && \ + cat testDir/testDir2/testFile && sleep 1 && umount testDir' \ + "abcdefghijklmnopqrstuvwxyz\n" "" "" +testing "mount -o rbind dir1 dir2" \ + 'mount -o rbind testDir1 testDir >/dev/null 2>&1 && \ + cat testDir/testDir2/testFile && sleep 1 && umount testDir' \ + "abcdefghijklmnopqrstuvwxyz\n" "" "" +testing "mount -o loop $tmp_b_fs /mnt" \ + "mount -o loop $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDirp && + sleep 1 && umount -d /mnt && ! test -e /mnt/testDirp" "" "" "" +reCreateTmpFs + +mkdir testDir2 +testing "mount -o move mount_1 mount_2" \ + "mount $tmp_b_fs testDir1 && mkdir testDir1/testDirr && + mount -o move testDir1 testDir2 && test -r testDir2/testDirr && + sleep 1 && umount testDir2" "" "" "" +reCreateTmpFs +testing "mount -o rw $tmp_b_fs /mnt" \ + "mount -o rw $tmp_b_fs /mnt >/dev/null 2>&1 && mkdir /mnt/testDir && + sleep 1 && umount /mnt && ! test -e /mnt/testDir" "" "" "" +reCreateTmpFs +testing "mount -o ro $tmp_b_fs /mnt" \ + "mount -o ro $tmp_b_fs /mnt >/dev/null 2>&1 && + mkdir /mnt/testDir 2>/dev/null || sleep 1 && umount /mnt" "" "" "" +reCreateTmpFs + +umount testDir1 +rm -f $tmp_b_fs diff -r 7dd487ddd7dc -r 7a2aec0876fe scripts/test/pgrep.test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/test/pgrep.test Fri Jul 04 21:20:02 2014 -0500 @@ -0,0 +1,122 @@ +#!/bin/bash + +# Copyright 2013 Divya Kothari +# Copyright 2013 Robin Mittal + +#cleaning 'yes' processes +killall yes >/dev/null 2>&1 + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +# Starting processes to test pgrep command +yes >/dev/null & +proc=$! +echo "# Process created with id: $proc" +sleep 1 +session_id=0 +proc_parent=`cat /proc/${proc}/stat | awk '{ print $4 }'` +echo "# Parent Process id of $proc is $proc_parent" + +# Testcases for pgrep command +testing "pgrep pattern" "pgrep yes" "$proc\n" "" "" +testing "pgrep wildCardPattern" "pgrep ^y.*s$" "$proc\n" "" "" +testing "pgrep -l pattern" "pgrep -l yes" "$proc yes\n" "" "" +testing "pgrep -f pattern" "pgrep -f yes" "$proc\n" "" "" +testing "pgrep -n pattern" "pgrep -n yes" "$proc\n" "" "" +testing "pgrep -o pattern" "pgrep -o yes" "$proc\n" "" "" +testing "pgrep -s" "pgrep -s $session_id yes" "$proc\n" "" "" +testing "pgrep -P" "pgrep -P $proc_parent yes" "$proc\n" "" "" + +#Clean-up +killall yes >/dev/null 2>&1 + +# Testcases for pkill command + +yes >/dev/null & +sleep 1 +testing "pkill pattern" "pkill yes && sleep 1 && (pgrep yes || echo 'yes')" \ + "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +yes print1 >/dev/null & +yes print2 >/dev/null & +sleep 1 +testing "pkill pattern (multiple)" "pkill yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +sleep 1 +testing "pkill -f pattern (one)" "pkill -f yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes print1 >/dev/null & +sleep 1 +testing "pkill -f pattern args" "pkill -f \"yes print1\" && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +yes print1 >/dev/null & +yes print2 >/dev/null & +sleep 1 +testing "pkill -f pattern (multiple)" "pkill -f yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +sleep 1 +testing "pkill -s 0 -f pattern (regexp)" "pkill -s 0 -f ye* && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +proc1=$! +yes >/dev/null & +proc2=$! +sleep 1 +testing "pkill -n pattern" "pkill -n yes && sleep 1 && pgrep yes" \ + "$proc1\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +proc1=$! +yes >/dev/null & +proc2=$! +sleep 1 +testing "pkill -o pattern" "pkill -o yes && sleep 1 && pgrep yes" \ + "$proc2\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +sleep 1 +testing "pkill -s (blank) pattern" "pkill -s '' yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +sleep 1 +testing "pkill -s 0 pattern" "pkill -s 0 yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +proc=$! +proc_p=`cat /proc/${proc}/stat | awk '{ print $4 }'` +sleep 1 +testing "pkill -P parent_prodId pattern" "pkill -P $proc_p yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + +yes >/dev/null & +proc=$! +proc_parent=`cat /proc/${proc}/stat | awk '{ print $4 }'` +sleep 1 +testing "pkill -9 pattern" "pkill -9 yes && sleep 1 && + (pgrep yes || echo 'yes')" "yes\n" "" "" +killall yes >/dev/null 2>&1 + diff -r 7dd487ddd7dc -r 7a2aec0876fe scripts/test/useradd.test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/test/useradd.test Fri Jul 04 21:20:02 2014 -0500 @@ -0,0 +1,90 @@ +#!/bin/bash + +# Copyright 2013 Divya Kothari +# Copyright 2013 Robin Mittal + +[ -f testing.sh ] && . testing.sh + +# 70 characters long string; hereafter, we will use it as per our need. +_s70="abcdefghijklmnopqrstuvwxyz123456789abcdefghijklmnopqrstuvwxyz123456789" + +# Redirecting all output to /dev/null for grep, adduser and deluser +arg="&>/dev/null" + +#testing "name" "command" "result" "infile" "stdin" + +# Default password for adding user is: 'password' +pass=`echo -ne 'password\npassword\n'` + +testing "adduser user_name (text)" "useradd toyTestUser $arg || + grep '^toyTestUser:' /etc/passwd $arg && test -d /home/toyTestUser && + userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ + "yes\n" "" "$pass" + +testing "adduser user_name (alphanumeric)" "useradd toy1Test2User3 $arg || + grep '^toy1Test2User3:' /etc/passwd $arg && test -d /home/toy1Test2User3 && + userdel toy1Test2User3 $arg && rm -rf /home/toy1Test2User3 && echo 'yes'" \ + "yes\n" "" "$pass" + +testing "adduser user_name (numeric)" "useradd 987654321 $arg || + grep '^987654321:' /etc/passwd $arg && test -d /home/987654321 && + userdel 987654321 $arg && rm -rf /home/987654321 && echo 'yes'" \ + "yes\n" "" "$pass" + +testing "adduser user_name (with ./-/_)" "useradd toy.1Test-2User_3 $arg || + grep '^toy.1Test-2User_3:' /etc/passwd $arg && + test -d /home/toy.1Test-2User_3 && userdel toy.1Test-2User_3 $arg && + rm -rf /home/toy.1Test-2User_3 && echo 'yes'" "yes\n" "" "$pass" + +testing "adduser user_name (long string)" "useradd $_s70 $arg || + grep '^$_s70:' /etc/passwd $arg && test -d /home/$_s70 && + userdel $_s70 $arg && rm -rf /home/$_s70 && echo 'yes'" "yes\n" "" "$pass" + +testing "adduser user_name with dir" "useradd -h $PWD/dir toyTestUser $arg || + grep '^toyTestUser:.*dir' /etc/passwd $arg && test -d $PWD/dir && + userdel toyTestUser $arg && rm -rf $PWD/dir && echo 'yes'" "yes\n" "" "$pass" + +gecos="aaa,bbb,ccc,ddd,eee" +testing "adduser user_name with gecos" "useradd -g '$gecos' toyTestUser $arg || + grep '^toyTestUser:.*$gecos' /etc/passwd $arg && test -d /home/toyTestUser && + userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ + "yes\n" "" "$pass" + +shl="/bin/sh" +testing "adduser user_name with shell" "useradd -s $shl toyTestUser $arg || + grep '^toyTestUser:.*$shl$' /etc/passwd $arg && test -d /home/toyTestUser && + userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ + "yes\n" "" "$pass" + +g_name="root" +g_id=`grep $g_name /etc/group | cut -d : -f 3` +testing "adduser user_name with group" "useradd -G $g_name toyTestUser $arg || + grep '^toyTestUser:.*:.*:$g_id:.*' /etc/passwd $arg && + test -d /home/toyTestUser && userdel toyTestUser $arg && + rm -rf /home/toyTestUser && echo 'yes'" "yes\n" "" "$pass" + +testing "adduser user_name (system user)" "useradd -S toyTestUser $arg || + grep '^toyTestUser:.*:.*:.*' /etc/passwd $arg && + test ! -e /home/toyTestUser && userdel toyTestUser $arg && echo 'yes'" \ + "yes\n" "" "$pass" + +testing "adduser user_name with -D" "useradd -D toyTestUser $arg || + grep '^toyTestUser:.*:.*:.*' /etc/passwd $arg && test -d /home/toyTestUser && + userdel toyTestUser $arg && rm -rf /home/toyTestUser && echo 'yes'" \ + "yes\n" "" "$pass" + +testing "adduser user_name with -H" "useradd -H toyTestUser $arg || + grep '^toyTestUser:.*:.*:.*' /etc/passwd $arg && + test ! -e /home/toyTestUser && userdel toyTestUser $arg && echo 'yes'" \ + "yes\n" "" "$pass" + +testing "adduser user_name with dir and -H" \ + "useradd -H -h $PWD/dir toyTestUser $arg || + grep '^toyTestUser:.*dir' /etc/passwd $arg && test ! -e $PWD/dir && + userdel toyTestUser $arg && echo 'yes'" "yes\n" "" "$pass" + +testing "adduser user_name with user_id" "useradd -u 49999 toyTestUser $arg || + grep '^toyTestUser:x:49999:.*' /etc/passwd $arg && + test -d /home/toyTestUser && userdel toyTestUser $arg && + rm -rf /home/toyTestUser && echo 'yes'" "yes\n" "" "$pass" +