diff --git a/tests/golden/worm-xattr-unit b/tests/golden/worm-xattr-unit new file mode 100644 index 00000000..1f2eb6ff --- /dev/null +++ b/tests/golden/worm-xattr-unit @@ -0,0 +1,41 @@ +== test creation of worm xattr without .hide +setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument +== test creation of worm xattr on a directory +setfattr: /mnt/test/test/worm-xattr-unit: Invalid argument +== test creation of worm xattr +== test value is set correctly +== test deletion of xattr 1 sec after setting +setfattr: /mnt/test/test/worm-xattr-unit/file-1: Permission denied +== test setting xattr to a previous time after setting +setfattr: /mnt/test/test/worm-xattr-unit/file-1: Permission denied +== test deletion before expiration +rm: cannot remove ‘/mnt/test/test/worm-xattr-unit/file-1’: Permission denied +== Try to move the file prior to expiration +mv: cannot move ‘/mnt/test/test/worm-xattr-unit/file-1’ to ‘/mnt/test/test/worm-xattr-unit/file-2’: Permission denied +== Try to write to file before expiration +date: write error: Permission denied +== wait til expiration +== Try to write to file after expiration +== Try to move the file after expiration +== test deletion after expiration +== test creation with non integer value of a.a +setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument +== test creation with non integer value of .... +setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument +== test creation with non integer value of ... +setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument +== test creation with no nsec value of 11. +setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument +== test creation with no sec value of .11 +setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument +== test creation with . at start and end value .11. +setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument +== test creation with invalid format of two characters +setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument +== test creation with too large of a nsecs value 1.18446744073709551615 +setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument +== test creation with nsecs > NSECS_PER_SEC value 1.1000000000 +setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument +== test creation with sec > U64_MAX value of 184467440737095516159.1 +setfattr: /mnt/test/test/worm-xattr-unit/file-1: Invalid argument +== removing files after expiration diff --git a/tests/sequence b/tests/sequence index c6e463f1..e5ab4876 100644 --- a/tests/sequence +++ b/tests/sequence @@ -10,6 +10,7 @@ move-blocks.sh enospc.sh srch-basic-functionality.sh simple-xattr-unit.sh +worm-xattr-unit.sh totl-xattr-tag.sh lock-refleak.sh lock-shrink-consistency.sh diff --git a/tests/tests/worm-xattr-unit.sh b/tests/tests/worm-xattr-unit.sh new file mode 100644 index 00000000..7e68b9d4 --- /dev/null +++ b/tests/tests/worm-xattr-unit.sh @@ -0,0 +1,84 @@ +t_require_commands touch rm setfattr + +touch "$T_D0/file-1" +SECS=$(date '+%s') +NSECS=$(date '+%N') +DELAY=10 +EXP=$(( $SECS + $DELAY )) +EXP_DELAY=$(( $DELAY + 2 )) + +echo "== test creation of worm xattr without .hide" +setfattr -n scoutfs.worm.v1_expiration -v $EXP.$NSECS "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== test creation of worm xattr on a directory" +setfattr -n scoutfs.worm.v1_expiration -v $EXP.$NSECS "$T_D0" 2>&1 | t_filter_fs + +echo "== test creation of worm xattr" +setfattr -n scoutfs.hide.worm.v1_expiration -v $EXP.$NSECS "$T_D0/file-1" + +echo "== test value is set correctly" +diff -u --ignore-all-space <(echo "$EXP.$NSECS") <(getfattr --absolute-names --only-values -n scoutfs.hide.worm.v1_expiration -m - "$T_D0/file-1") + +echo "== test deletion of xattr 1 sec after setting" +sleep 1 +setfattr -x scoutfs.hide.worm.v1_expiration "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== test setting xattr to a previous time after setting" +setfattr -n scoutfs.hide.worm.v1_expiration -v $SECS.$NSECS "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== test deletion before expiration" +rm -f "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== Try to move the file prior to expiration" +mv $T_D0/file-1 $T_D0/file-2 2>&1 | t_filter_fs + +echo "== Try to write to file before expiration" +date >> $T_D0/file-1 + +echo "== wait til expiration" +sleep $EXP_DELAY + +echo "== Try to write to file after expiration" +date >> $T_D0/file-1 + +echo "== Try to move the file after expiration" +mv $T_D0/file-1 $T_D0/file-2 +mv $T_D0/file-2 $T_D0/file-1 + +echo "== test deletion after expiration" +setfattr -x scoutfs.hide.worm.v1_expiration "$T_D0/file-1" + +echo "== test creation with non integer value of a.a" +setfattr -n scoutfs.hide.worm.v1_expiration -v a.a "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== test creation with non integer value of ...." +setfattr -n scoutfs.hide.worm.v1_expiration -v .... "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== test creation with non integer value of ..." +setfattr -n scoutfs.hide.worm.v1_expiration -v ... "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== test creation with no nsec value of 11." +setfattr -n scoutfs.hide.worm.v1_expiration -v 11. "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== test creation with no sec value of .11" +setfattr -n scoutfs.hide.worm.v1_expiration -v .11 "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== test creation with . at start and end value .11." +setfattr -n scoutfs.hide.worm.v1_expiration -v .11. "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== test creation with invalid format of two characters" +setfattr -n scoutfs.hide.worm.v1_expiration -v 11 "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== test creation with too large of a nsecs value 1.18446744073709551615" +setfattr -n scoutfs.hide.worm.v1_expiration -v 1.18446744073709551615 "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== test creation with nsecs > NSECS_PER_SEC value 1.1000000000" +setfattr -n scoutfs.hide.worm.v1_expiration -v 1.1000000000 "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== test creation with sec > U64_MAX value of 184467440737095516159.1" +setfattr -n scoutfs.hide.worm.v1_expiration -v 184467440737095516159.1 "$T_D0/file-1" 2>&1 | t_filter_fs + +echo "== removing files after expiration" +rm -f "$T_D0/file-1" + +t_pass