From 0b5e252d973e00200660a81f1cdb440f8f4f1886 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Tue, 21 Nov 2023 20:40:51 +0530 Subject: [PATCH] LU-17057 tests: Fix sanity-sec/0 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 Change-Id: I06e6d22840e31add8c24cf90c31b98464d580ae7 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53194 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Sebastien Buisson Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/tests/sanity-sec.sh | 59 +++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/lustre/tests/sanity-sec.sh b/lustre/tests/sanity-sec.sh index 70a4a70..8de6f43 100755 --- a/lustre/tests/sanity-sec.sh +++ b/lustre/tests/sanity-sec.sh @@ -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 =============================" -- 1.8.3.1