From patchwork Fri May 11 07:29:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Misono Tomohiro X-Patchwork-Id: 10393381 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ECDC16053A for ; Fri, 11 May 2018 07:27:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A566528D97 for ; Fri, 11 May 2018 07:27:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A3DB28E00; Fri, 11 May 2018 07:27:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D240828D97 for ; Fri, 11 May 2018 07:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752629AbeEKH1q (ORCPT ); Fri, 11 May 2018 03:27:46 -0400 Received: from mgwym03.jp.fujitsu.com ([211.128.242.42]:51939 "EHLO mgwym03.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752616AbeEKH1o (ORCPT ); Fri, 11 May 2018 03:27:44 -0400 Received: from yt-mxoi1.gw.nic.fujitsu.com (unknown [192.168.229.67]) by mgwym03.jp.fujitsu.com with smtp id 22d7_5766_a4c72ec1_bc8f_4f82_b34b_adf88c2139c3; Fri, 11 May 2018 16:27:40 +0900 Received: from g01jpfmpwkw02.exch.g01.fujitsu.local (g01jpfmpwkw02.exch.g01.fujitsu.local [10.0.193.56]) by yt-mxoi1.gw.nic.fujitsu.com (Postfix) with ESMTP id ECD89AC0263 for ; Fri, 11 May 2018 16:27:39 +0900 (JST) Received: from g01jpexchkw35.g01.fujitsu.local (unknown [10.0.193.4]) by g01jpfmpwkw02.exch.g01.fujitsu.local (Postfix) with ESMTP id 1E04C32881B for ; Fri, 11 May 2018 16:27:39 +0900 (JST) Received: from luna3.soft.fujitsu.com (10.124.196.199) by g01jpexchkw35.g01.fujitsu.local (10.0.193.50) with Microsoft SMTP Server id 14.3.352.0; Fri, 11 May 2018 16:27:38 +0900 From: Tomohiro Misono To: Subject: [PATCH 11/11] btrfs-porgs: test: Add cli-test/009 to check subvolume list for both root and normal user Date: Fri, 11 May 2018 16:29:49 +0900 Message-ID: <20180511072949.15269-12-misono.tomohiro@jp.fujitsu.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180511072949.15269-1-misono.tomohiro@jp.fujitsu.com> References: <20180511072949.15269-1-misono.tomohiro@jp.fujitsu.com> MIME-Version: 1.0 X-SecurityPolicyCheck-GC: OK by FENCE-Mail X-TM-AS-MML: disable Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Tomohiro Misono --- tests/cli-tests/009-subvolume-list/test.sh | 136 +++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100755 tests/cli-tests/009-subvolume-list/test.sh diff --git a/tests/cli-tests/009-subvolume-list/test.sh b/tests/cli-tests/009-subvolume-list/test.sh new file mode 100755 index 00000000..5f7b7919 --- /dev/null +++ b/tests/cli-tests/009-subvolume-list/test.sh @@ -0,0 +1,136 @@ +#!/bin/bash +# test for "subvolume list" both for root and normal user + +source "$TEST_TOP/common" + +check_testuser +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev + + +# test if the ids returned by "sub list" match expected ids +# $1 ... indicate run as root or test user +# $2 ... PATH to be specified by sub list command +# $3~ ... expected return ids +test_list() +{ + local SUDO + if [ $1 -eq 1 ]; then + SUDO=$SUDO_HELPER + else + SUDO="sudo -u progs-test" + fi + + result=$(run_check_stdout $SUDO "$TOP/btrfs" subvolume list "$2" | \ + awk '{print $2}' | xargs | sort -n) + + shift + shift + expected=($(echo "$@" | tr " " "\n" | sort -n)) + expected=$(IFS=" "; echo "${expected[*]}") + + if [ "$result" != "$expected" ]; then + echo "result : $result" + echo "expected: $expected" + _fail "ids returned by sub list does not match expected ids" + fi +} + +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev +cd "$TEST_MNT" + +# create subvolumes and directories and make some non-readable +# by user 'progs-test' +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create sub1 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create sub1/subsub1 +run_check $SUDO_HELPER mkdir sub1/dir + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create sub2 +run_check $SUDO_HELPER mkdir -p sub2/dir/dirdir +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create sub2/dir/subsub2 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create sub2/dir/dirdir/subsubX + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create sub3 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create sub3/subsub3 +run_check $SUDO_HELPER mkdir sub3/dir +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create sub3/dir/subsubY +run_check $SUDO_HELPER chmod o-r sub3 + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create sub4 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create sub4/subsub4 +run_check $SUDO_HELPER mkdir sub4/dir +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create sub4/dir/subsubZ +run_check $SUDO_HELPER setfacl -m u:progs-test:- sub4/dir + +run_check $SUDO_HELPER touch "file" + +# expected result for root at mount point: +# +# ID 256 gen 8 top level 5 path sub1 +# ID 258 gen 7 top level 256 path sub1/subsub1 +# ID 259 gen 10 top level 5 path sub2 +# ID 260 gen 9 top level 259 path sub2/dir/subsub2 +# ID 261 gen 10 top level 259 path sub2/dir/dirdir/subsubX +# ID 262 gen 14 top level 5 path sub3 +# ID 263 gen 12 top level 262 path sub3/subsub3 +# ID 264 gen 13 top level 262 path sub3/dir/subsubY +# ID 265 gen 17 top level 5 path sub4 +# ID 266 gen 15 top level 265 path sub4/subsub4 +# ID 267 gen 16 top level 265 path sub4/dir/subsubZ + +# check for root for both absolute/relative path +# always returns all subvolumes +all=(256 258 259 260 261 262 263 264 265 266 267) +test_list 1 "$TEST_MNT" "${all[@]}" +test_list 1 "$TEST_MNT/sub1" "256 258" +test_list 1 "$TEST_MNT/sub1/dir" "" +test_list 1 "$TEST_MNT/sub2" "259 260 261" +test_list 1 "$TEST_MNT/sub2/dir" "260 261" +test_list 1 "$TEST_MNT/sub3" "262 263 264" +test_list 1 "$TEST_MNT/sub4" "265 266 267" +run_mustfail "should fail for file" \ + $SUDO_HELPER "$TOP/btrfs" subvolume list "$TEST_MNT/file" + +test_list 1 "." "${all[@]}" +test_list 1 "sub1" "256 258" +test_list 1 "sub1/dir" "" +test_list 1 "sub2" "259 260 261" +test_list 1 "sub2/dir" "260 261" +test_list 1 "sub3" "262 263 264" +test_list 1 "sub4" "265 266 267" +run_mustfail "should fail for file" \ + $SUDO_HELPER "$TOP/btrfs" subvolume list "file" + +# check for normal user for both absolute/relative path +# only returns subvolumes under specified path +test_list 0 "$TEST_MNT" "256 258 259 260 261 265 266" +test_list 0 "$TEST_MNT/sub1" "256 258" +test_list 0 "$TEST_MNT/sub1/dir" "" +test_list 0 "$TEST_MNT/sub2" "259 260 261" +test_list 0 "$TEST_MNT/sub2/dir" "260 261" +run_mustfail "should raise permission error" \ + sudo -u progs-test "$TOP/btrfs" subvolume list "$TEST_MNT/sub3" +test_list 0 "$TEST_MNT/sub4" "265 266" +run_mustfail "should raise permission error" \ + sudo -u progs-test "$TOP/btrfs" subvolume list "$TEST_MNT/sub4/dir" +run_mustfail "should fail for file" \ + sudo -u progs-test "$TOP/btrfs" subvolume list "$TEST_MNT/file" + +test_list 0 "." "256 258 259 260 261 265 266" +test_list 0 "sub1/dir" "" +test_list 0 "sub2" "259 260 261" +test_list 0 "sub2/dir" "260 261" +run_mustfail "should raise permission error" \ + sudo -u progs-test "$TOP/btrfs" subvolume list "sub3" +test_list 0 "sub4" "265 266" +run_mustfail "should raise permission error" \ + sudo -u progs-test "$TOP/btrfs" subvolume list "sub4/dir" +run_mustfail "should fail for file" \ + sudo -u progs-test "$TOP/btrfs" subvolume list "file" + +cd .. +run_check_umount_test_dev