Whamcloud - gitweb
LU-17057 tests: Fix sanity-sec/0 94/53194/5
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Tue, 21 Nov 2023 15:10:51 +0000 (20:40 +0530)
committerOleg Drokin <green@whamcloud.com>
Wed, 13 Dec 2023 12:23:06 +0000 (12:23 +0000)
Command executed through 'runas' on failure breaks
out of running test script. While this failure is
expected. The setting of 'set -e' forces the pipeline
to exit the running script immediately. This patch
fixes this by checking the return value and then
taking the appropriate action.

This patch also fixes 'touch' command to file f4 by
correctly calling it via uid and gid as it was set
few lines above.

Test-Parameters: trivial testlist=sanity-sec env=ONLY=0,ONLY_REPEAT=100
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: I06e6d22840e31add8c24cf90c31b98464d580ae7
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53194
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/sanity-sec.sh

index 70a4a70..8de6f43 100755 (executable)
@@ -144,23 +144,48 @@ sec_setup
 test_0() {
        umask 0022
 
-       chmod 0755 $DIR || error "chmod (1)"
-       rm -rf $DIR/$tdir || error "rm (1)"
-       mkdir -p $DIR/$tdir || error "mkdir (1)"
-       chown $USER0 $DIR/$tdir || error "chown (2)"
-       $RUNAS_CMD -u $ID0 ls $DIR || error "ls (1)"
-       rm -f $DIR/f0 || error "rm (2)"
-       $RUNAS_CMD -u $ID0 touch $DIR/f0 && error "touch (1)"
-       $RUNAS_CMD -u $ID0 touch $DIR/$tdir/f1 || error "touch (2)"
-       $RUNAS_CMD -u $ID1 touch $DIR/$tdir/f2 && error "touch (3)"
-       touch $DIR/$tdir/f3 || error "touch (4)"
-       chown root $DIR/$tdir || error "chown (3)"
-       chgrp $USER0 $DIR/$tdir || error "chgrp (1)"
-       chmod 0775 $DIR/$tdir || error "chmod (2)"
-       $RUNAS_CMD -u $ID0 touch $DIR/$tdir/f4 || error "touch (5)"
-       $RUNAS_CMD -u $ID1 touch $DIR/$tdir/f5 && error "touch (6)"
-       touch $DIR/$tdir/f6 || error "touch (7)"
-       rm -rf $DIR/$tdir || error "rm (3)"
+       chmod 0755 $DIR || error "chmod (1) Failed"
+       rm -rf $DIR/$tdir || error "rm (1) Failed"
+       mkdir -p $DIR/$tdir || error "mkdir (1) Failed"
+
+       # $DIR/$tdir owner changed to USER0(sanityusr)
+       chown $USER0 $DIR/$tdir || error "chown (2) Failed"
+       chmod 0755 $DIR/$tdir || error "chmod (2) Failed"
+
+       # Run as ID0 cmd must pass
+       $RUNAS_CMD -u $ID0 ls -ali $DIR || error "ls (1) Failed"
+       # Remove non-existing file f0
+       rm -f $DIR/f0 || error "rm (2) Failed"
+
+       # It is expected that this cmd should fail
+       # $DIR has only r-x rights for group and other
+       $RUNAS_CMD -u $ID0 touch $DIR/f0
+       (( $? == 0 )) && error "touch (1) should not pass"
+
+       # This must pass. $DIR/$tdir/ is owned by ID0/USER0
+       $RUNAS_CMD -u $ID0 touch $DIR/$tdir/f1 || error "touch (2) Failed"
+
+       # It is expected that this cmd should fail
+       # $tdir has rwxr-xr-x rights for $ID0
+       $RUNAS_CMD -u $ID1 touch $DIR/$tdir/f2
+       (( $? == 0 )) && error "touch (3) should not pass"
+
+       touch $DIR/$tdir/f3 || error "touch (4) Failed"
+       chown root $DIR/$tdir || error "chown (3) Failed"
+       chgrp $USER0 $DIR/$tdir || error "chgrp (1) Failed"
+       chmod 0775 $DIR/$tdir || error "chmod (3) Failed"
+
+       # Owner is root and group is USER0
+       $RUNAS_CMD -u $USER0 -g $USER0 touch $DIR/$tdir/f4 ||
+               error "touch (5) Failed"
+
+       # It is expected that this cmd should fail
+       # $tdir has rwxrwxr-x rights for group sanityusr/ID0, ID1 will fail
+       $RUNAS_CMD -u $ID1 -g $ID1 touch $DIR/$tdir/f5
+       (( $? == 0 )) && error "touch (6) should not pass"
+
+       touch $DIR/$tdir/f6 || error "touch (7) Failed"
+       rm -rf $DIR/$tdir || error "rm (3) Failed"
 }
 run_test 0 "uid permission ============================="