#! /bin/bash

. ${0%/*}/test-lib.sh

require_richacls
require_getfattr
use_testdir

umask 022

ncheck "touch x"
ncheck "setrichacl --set 'everyone@:rwp::allow' x"
check "stat -c %A x" <<EOF
-rw-rw-rw-
EOF

check "getrichacl x" <<EOF
x:
 everyone@:rwp----------::allow
EOF

ncheck 'chmod 664 x'
check "stat -c %A x" <<EOF
-rw-rw-r--
EOF

check "getrichacl x" <<EOF
x:
    owner@:rwp----------::allow
    group@:rwp----------::allow
 everyone@:r------------::allow
EOF

# Note that unlike how the test cases look at first sight, we do *not* require
# a richacl-enabled version of ls here ...

ncheck "mkdir sub"
ncheck "setrichacl --set 'everyone@:rwpxd:fd:allow' sub"
check "stat -c %A+ sub" <<EOF
drwxrwxrwx+
EOF

#check 'getfattr sub | grep -e system\.richacl' <<EOF
check 'getfattr -m system\.richacl sub' <<EOF
# file: sub
system.richacl
EOF

ncheck "chmod 775 sub"
check "stat -c %A+ sub" <<EOF
drwxrwxr-x+
EOF

check 'getfattr -m system\.richacl sub' <<EOF
# file: sub
system.richacl
EOF

check "getrichacl sub" <<EOF
sub:
    owner@:rwpxd--------::allow
    group@:rwpxd--------::allow
 everyone@:rwpxd--------:fdi:allow
 everyone@:r--x---------::allow
EOF

ncheck "touch sub/f"
check "stat -c %A sub/f" <<EOF
-rw-rw-rw-
EOF

check "getrichacl sub/f" <<EOF
sub/f:
 everyone@:rwp----------::allow
EOF

ncheck "mkdir sub/sub2"
check "stat -c %A+ sub/sub2" <<EOF
drwxrwxrwx+
EOF

check "getrichacl sub/sub2" <<EOF
sub/sub2:
 everyone@:rwpxd--------:fd:allow
EOF

ncheck "mkdir -m 750 sub/sub3"
check "stat -c %A+ sub/sub3" <<EOF
drwxr-x---+
EOF

check "getrichacl sub/sub3" <<EOF
sub/sub3:
    owner@:rwpxd--------::allow
    group@:r--x---------::allow
 everyone@:rwpxd--------:fdi:allow
EOF
