-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a bats tests suite for mounting and for failing to mount when the images are bad. Uses the ATOMFS_TEST_RUN_DIR env var to avoid polluting your host's /run/atomfs/meta dir. copies the guestmount test from the github yaml into bats and expands it a bit I apologize for the bash quoting situation, forgive me Missing cases: - testing `atomfs verify` on bad images: requires manufacturing a verity image that will mount OK but has a bad block that won't get read until later. I have tested verify with mounted bad images that I mounted with a purposely broken atomfs, but there should be a better way for CI. Signed-off-by: Michael McCracken <[email protected]>
- Loading branch information
1 parent
050bafb
commit 8d6f748
Showing
7 changed files
with
335 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Just a file to import into a scratch stacker image | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
test_base: | ||
from: | ||
type: scratch | ||
imports: | ||
- path: 1.README.md | ||
dest: / | ||
|
||
test: | ||
from: | ||
type: built | ||
tag: test_base | ||
imports: | ||
- path: random.txt | ||
dest: / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
|
||
if [ "$(id -u)" != "0" ]; then | ||
echo "you should be root to run this suite" | ||
exit 1 | ||
fi | ||
|
||
ROOT_D=$(dirname $BATS_TEST_FILENAME)/.. | ||
TOOLS_D=$ROOT_D/tools | ||
export PATH="$TOOLS_D/bin:$ROOT_D/bin:$PATH" | ||
|
||
build_image_at() { | ||
cd $1 | ||
stacker --oci-dir $1/oci --debug build -f $(dirname $BATS_TEST_FILENAME)/1.stacker.yaml --layer-type squashfs | ||
stacker --oci-dir $1/oci-no-verity --debug build -f $(dirname $BATS_TEST_FILENAME)/1.stacker.yaml --layer-type squashfs --no-squashfs-verity | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
load helpers | ||
load 'test_helper/bats-support/load' | ||
load 'test_helper/bats-assert/load' | ||
load 'test_helper/bats-file/load' | ||
|
||
function setup_file() { | ||
build_image_at $BATS_SUITE_TMPDIR | ||
export ATOMFS_TEST_RUN_DIR=${BATS_SUITE_TMPDIR}/run/atomfs | ||
mkdir -p $ATOMFS_TEST_RUN_DIR | ||
export MY_MNTNSNAME=$(readlink /proc/self/ns/mnt | cut -c 6-15) | ||
} | ||
|
||
function setup() { | ||
export MP=${BATS_TEST_TMPDIR}/testmountpoint | ||
mkdir -p $MP | ||
} | ||
|
||
@test "RO mount/umount and verify of good image works" { | ||
run atomfs --debug mount ${BATS_SUITE_TMPDIR}/oci:test-squashfs $MP | ||
assert_success | ||
assert_file_exists $MP/1.README.md | ||
assert_file_exists $MP/random.txt | ||
assert_dir_exists $ATOMFS_TEST_RUN_DIR/meta/$MY_MNTNSNAME/ | ||
|
||
run touch $MP/do-not-let-me | ||
assert_failure | ||
|
||
run atomfs verify $MP | ||
assert_success | ||
|
||
run atomfs --debug umount $MP | ||
assert_success | ||
|
||
# mount point and meta dir should exist but be empty: | ||
assert_dir_exists $MP | ||
assert [ -z $( ls -A $MP) ] | ||
assert_dir_exists $ATOMFS_TEST_RUN_DIR/meta/$MY_MNTNSNAME/ | ||
assert [ -z $( ls -A $ATOMFS_TEST_RUN_DIR/meta/$MY_MNTNSNAME/ ) ] | ||
|
||
} | ||
|
||
@test "mount with missing verity data fails" { | ||
run atomfs --debug mount ${BATS_SUITE_TMPDIR}/oci-no-verity:test-squashfs $MP | ||
assert_failure | ||
assert_line --partial "is missing verity data" | ||
|
||
# mount point and meta dir should exist but be empty: | ||
assert_dir_exists $MP | ||
assert [ -z $( ls -A $MP) ] | ||
assert_dir_exists $ATOMFS_TEST_RUN_DIR/meta/$MY_MNTNSNAME/ | ||
assert [ -z $( ls -A $ATOMFS_TEST_RUN_DIR/meta/$MY_MNTNSNAME/ ) ] | ||
|
||
} | ||
|
||
@test "mount with missing verity data passes if you ignore it" { | ||
run atomfs --debug mount --allow-missing-verity ${BATS_SUITE_TMPDIR}/oci-no-verity:test-squashfs $MP | ||
assert_success | ||
|
||
run atomfs --debug umount $MP | ||
assert_success | ||
|
||
# mount point and meta dir should exist but be empty: | ||
assert_dir_exists $MP | ||
assert [ -z $( ls -A $MP) ] | ||
assert_dir_exists $ATOMFS_TEST_RUN_DIR/meta/$MY_MNTNSNAME/ | ||
assert [ -z $( ls -A $ATOMFS_TEST_RUN_DIR/meta/$MY_MNTNSNAME/ ) ] | ||
|
||
} | ||
|
||
@test "mount/umount with writeable overlay" { | ||
run atomfs --debug mount --writeable ${BATS_SUITE_TMPDIR}/oci:test-squashfs $MP | ||
assert_success | ||
assert_file_exists $MP/1.README.md | ||
assert_file_exists $MP/random.txt | ||
assert_dir_exists $ATOMFS_TEST_RUN_DIR/meta/$MY_MNTNSNAME/ | ||
|
||
run touch $MP/this-time-let-me | ||
assert_success | ||
|
||
run cp $MP/1.README.md $MP/3.README.md | ||
assert_success | ||
|
||
run atomfs --debug umount $MP | ||
assert_success | ||
|
||
# mount point and meta dir should exist but be empty: | ||
assert_dir_exists $MP | ||
assert [ -z $( ls -A $MP) ] | ||
assert_dir_exists $ATOMFS_TEST_RUN_DIR/meta/$MY_MNTNSNAME/ | ||
assert [ -z $( ls -A $ATOMFS_TEST_RUN_DIR/meta/$MY_MNTNSNAME/ ) ] | ||
} | ||
|
||
@test "mount with writeable overlay in separate dir" { | ||
export PERSIST_DIR=${BATS_TEST_TMPDIR}/upperdir | ||
mkdir -p $PERSIST_DIR | ||
run atomfs --debug mount --persist=${PERSIST_DIR} ${BATS_SUITE_TMPDIR}/oci:test-squashfs $MP | ||
assert_success | ||
assert_file_exists $MP/1.README.md | ||
assert_file_exists $MP/random.txt | ||
|
||
run touch $MP/this-time-let-me | ||
assert_success | ||
run cp $MP/1.README.md $MP/3.README.md | ||
assert_success | ||
|
||
assert_file_exists $PERSIST_DIR/this-time-let-me | ||
assert_file_exists $PERSIST_DIR/3.README.md | ||
assert_file_not_exists $PERSIST_DIR/1.README.md | ||
|
||
run atomfs --debug umount $MP | ||
assert_success | ||
# mount point and meta dir should exist but be empty: | ||
assert_dir_exists $MP | ||
assert [ -z $( ls -A $MP) ] | ||
assert_dir_exists $ATOMFS_TEST_RUN_DIR/meta/$MY_MNTNSNAME/ | ||
assert [ -z $( ls -A $ATOMFS_TEST_RUN_DIR/meta/$MY_MNTNSNAME/) ] | ||
|
||
# but persist dir should still be there: | ||
assert_file_exists $PERSIST_DIR/this-time-let-me | ||
assert_file_exists $PERSIST_DIR/3.README.md | ||
} | ||
|
||
@test "guestmount works ignoring verity" { | ||
|
||
lxc-usernsexec -s <<EOF | ||
set -x | ||
export ATOMFS_TEST_RUN_DIR=$ATOMFS_TEST_RUN_DIR | ||
export PERSIST_DIR=${BATS_TEST_TMPDIR}/upperdir | ||
mkdir -p \$PERSIST_DIR | ||
export INNER_MNTNSNAME=\$(readlink /proc/self/ns/mnt | cut -c 6-15) | ||
set +e | ||
atomfs --debug mount --persist=\$PERSIST_DIR ${BATS_SUITE_TMPDIR}/oci:test-squashfs $MP | ||
[ \$? -eq 0 ] && { | ||
echo guestmount without allow-missing should fail, because we do not have verity | ||
exit 1 | ||
} | ||
set -e | ||
atomfs --debug mount --allow-missing-verity --persist=\$PERSIST_DIR ${BATS_SUITE_TMPDIR}/oci:test-squashfs $MP | ||
[ -f $MP/1.README.md ] | ||
[ -f $MP/random.txt ] | ||
touch $MP/let-me-write | ||
set +e | ||
atomfs --debug verify $MP | ||
[ \$? -eq 0 ] && { | ||
echo mount with squashfuse ignores verity, so verify should have failed, output should include warning | ||
exit 1 | ||
} | ||
set -e | ||
find $ATOMFS_TEST_RUN_DIR/meta/\$INNER_MNTNSNAME/ -name config.json|xargs cat | ||
find $ATOMFS_TEST_RUN_DIR/meta/\$INNER_MNTNSNAME/ | ||
atomfs --debug umount $MP | ||
[ -f \$PERSIST_DIR/let-me-write ] | ||
# mount point and meta dir should be empty: | ||
[ -d $MP ] | ||
[ -z \$( ls -A $MP) ] | ||
[ -d $ATOMFS_TEST_RUN_DIR/meta/\$INNER_MNTNSNAME/ ] | ||
[ -z \$( ls -A $ATOMFS_TEST_RUN_DIR/meta/\$INNER_MNTNSNAME/) ] | ||
EOF | ||
} | ||
|
||
|
||
@test "guestmount works on images without verity" { | ||
|
||
lxc-usernsexec -s <<EOF | ||
set -x | ||
export ATOMFS_TEST_RUN_DIR=$ATOMFS_TEST_RUN_DIR | ||
export PERSIST_DIR=${BATS_TEST_TMPDIR}/upperdir | ||
mkdir -p \$PERSIST_DIR | ||
export INNER_MNTNSNAME=\$(readlink /proc/self/ns/mnt | cut -c 6-15) | ||
atomfs --debug mount --allow-missing-verity --persist=\$PERSIST_DIR ${BATS_SUITE_TMPDIR}/oci-no-verity:test-squashfs $MP | ||
[ -f $MP/1.README.md ] | ||
[ -f $MP/random.txt ] | ||
touch $MP/let-me-write | ||
set +e | ||
atomfs --debug verify $MP | ||
[ \$? -eq 0 ] && { | ||
echo mount with squashfuse ignores verity, so verify should have failed, output should include warning | ||
exit 1 | ||
} | ||
set -e | ||
atomfs --debug umount $MP | ||
[ -f \$PERSIST_DIR/let-me-write ] | ||
[ -d $MP ] | ||
[ -z \$( ls -A $MP) ] | ||
[ -d $ATOMFS_TEST_RUN_DIR/meta/\$INNER_MNTNSNAME/ ] | ||
[ -z \$( ls -A $ATOMFS_TEST_RUN_DIR/meta/\$INNER_MNTNSNAME/) ] | ||
EOF | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
load helpers | ||
load 'test_helper/bats-support/load' | ||
load 'test_helper/bats-assert/load' | ||
load 'test_helper/bats-file/load' | ||
|
||
function setup_file() { | ||
export ATOMFS_TEST_RUN_DIR=${BATS_SUITE_TMPDIR}/run/atomfs | ||
mkdir -p $ATOMFS_TEST_RUN_DIR | ||
} | ||
|
||
@test "mounting tampered small images fails immediately" { | ||
build_image_at $BATS_TEST_TMPDIR | ||
|
||
sha256sum $BATS_TEST_TMPDIR/oci/blobs/sha256/* > initialsums | ||
|
||
# write some bad data onto the squash blobs to make them invalid | ||
for blob in $BATS_TEST_TMPDIR/oci/blobs/sha256/* ; do | ||
file $blob | grep "Squashfs filesystem" || continue | ||
dd if=/dev/random of=$blob conv=notrunc seek=100 count=100 | ||
done | ||
|
||
sha256sum $BATS_TEST_TMPDIR/oci/blobs/sha256/* > finalsums | ||
|
||
# the sums should be different, so assert that diff finds diffs: | ||
run diff initialsums finalsums | ||
assert_failure | ||
|
||
mkdir -p mountpoint | ||
run atomfs --debug mount ${BATS_TEST_TMPDIR}/oci:test-squashfs mountpoint | ||
assert_failure | ||
|
||
} | ||
|
||
@test "TODO: check atomfs verify on a mounted image that isn't detected immediately" { | ||
echo TODO | ||
} |