]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:tests: Add a test to check json output of smbstatus profile
authorJule Anger <janger@samba.org>
Thu, 31 Mar 2022 12:40:17 +0000 (14:40 +0200)
committerJule Anger <janger@samba.org>
Mon, 8 Aug 2022 14:01:45 +0000 (14:01 +0000)
Signed-off-by: Jule Anger <janger@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Jule Anger <janger@samba.org>
Autobuild-Date(master): Mon Aug  8 14:01:45 UTC 2022 on sn-devel-184

source3/script/tests/test_smbstatus.sh

index 6b58580f0b9f0318893b3712941a33c03ad8ce9e..0eb186e3d8689c0b47df6708b5d94daa5c7d0203 100755 (executable)
@@ -392,6 +392,91 @@ EOF
 
        return 0
 }
+test_smbstatus_json_profile()
+{
+       local status_json=smbstatus_output_json_profile
+
+       cmd="UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $SMBSTATUS --json --profile > $PREFIX/$status_json"
+       out=$(eval $cmd)
+       ret=$?
+
+       if [ $ret -ne 0 ]; then
+               echo "Failed to run smbstatus -jP with error $ret"
+               echo "$out"
+               return 1
+       fi
+
+       echo $out | grep -c 'JSON support not available, please install lib Jansson'
+       ret=$?
+       if [ $ret -eq 0 ]; then
+               subunit_start_test "test_smbstatus_json_profile"
+               subunit_skip_test "test_smbstatus_json_profile" <<EOF
+Test needs Jansson
+EOF
+               return 0
+       fi
+
+       out=$(cat $PREFIX/$status_json)
+       ret=$?
+       if [ $ret -ne 0 ]; then
+               echo "Failed: Could not print json profile output with error $ret"
+               echo "$out"
+               return 1
+       fi
+
+       out=$(cat $PREFIX/$status_json | jq ".")
+       echo $out | grep -c 'jq: not found'
+       ret=$?
+       if [ $ret -eq 0 ]; then
+               subunit_start_test "test_smbstatus_json_profile"
+               subunit_skip_test "test_smbstatus_json_profile" <<EOF
+Test needs jq
+EOF
+               return 0
+       fi
+
+       out=$(cat $PREFIX/$status_json | jq ".")
+       ret=$?
+       if [ $ret -ne 0 ]; then
+               echo "Failed: Could not parse json output from smbstatus -jP with error $ret"
+               echo "$out"
+               return 1
+       fi
+
+       # keys in --json --profile
+       expected='["ACL Calls","NT Transact Calls","SMB Calls","SMB2 Calls","SMBD loop","Stat Cache","System Calls","Trans2 Calls","smb_conf","timestamp","version"]'
+       out=$(cat $PREFIX/$status_json | jq keys -c)
+       if [ "$expected" != "$out" ]; then
+               echo "Failed: Unexpected keys in smbstatus -jP"
+               echo "Expected: $expected"
+               echo "Output: $out"
+               return 1
+       fi
+
+       # keys in ACL Calls
+       expected='["fget_nt_acl","fset_nt_acl","get_nt_acl","get_nt_acl_at"]'
+       out=$(cat $PREFIX/$status_json | jq -c '."ACL Calls"|keys')
+       if [ "$expected" != "$out" ]; then
+               echo "Failed: Unexpected keys in smbstatus -jP"
+               echo "Expected: $expected"
+               echo "Output: $out"
+               return 1
+       fi
+
+       # keys in ACL Calls, fget_nt_acl
+       expected='["count","time"]'
+       out=$(cat $PREFIX/$status_json | jq -c '."ACL Calls"."fget_nt_acl"|keys')
+       if [ "$expected" != "$out" ]; then
+               echo "Failed: Unexpected keys in smbstatus -jP"
+               echo "Expected: $expected"
+               echo "Output: $out"
+               return 1
+       fi
+
+       rm $PREFIX/$status_json
+
+       return 0
+}
 
 testit "plain" \
        test_smbstatus ||
@@ -409,4 +494,8 @@ testit "test_json" \
        test_smbstatus_json || \
        failed=`expr $failed + 1`
 
+testit "test_json_profile" \
+       test_smbstatus_json_profile || \
+       failed=`expr $failed + 1`
+
 testok $0 $failed