Skip to content

Commit

Permalink
Merge pull request #5802 from edsantiago/para-prep-mkcw
Browse files Browse the repository at this point in the history
tests: mkcw: bug fixes, refactor
  • Loading branch information
openshift-merge-bot[bot] authored Oct 30, 2024
2 parents 9665efd + 2797d22 commit 046ce42
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions tests/mkcw.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ load helpers

function mkcw_check_image() {
local imageID="$1"
local expectedEnv="$2"
# Mount the container and take a look at what it got from the image.
run_buildah from "$imageID"
local ctrID="$output"
Expand All @@ -28,9 +27,6 @@ function mkcw_check_image() {
mount /dev/mapper/"$uuid" "$TEST_SCRATCH_DIR"/mount
# Should have a not-empty config file with parts of an image's config.
test -s "$TEST_SCRATCH_DIR"/mount/.krun_config.json
if test -n "$expectedEnv" ; then
grep -q "expectedEnv" "$TEST_SCRATCH_DIR"/mount/.krun_config.json
fi
# Should have a /tmp directory, at least.
test -d "$TEST_SCRATCH_DIR"/mount/tmp
# Should have a /bin/sh file from the base image, at least.
Expand Down Expand Up @@ -66,16 +62,16 @@ function mkcw_check_image() {
# and the presence of the second layer, empty as it is, means the image still
# meets the test expectations.
_prefetch $SAFEIMAGE
createrandom randomfile1
createrandom randomfile2
createrandom ${TEST_SCRATCH_DIR}/randomfile1
createrandom ${TEST_SCRATCH_DIR}/randomfile2

echo -n mkcw-convert > "$TEST_SCRATCH_DIR"/key
# image has one layer, check with all-lower-case TEE type name
run_buildah mkcw --ignore-attestation-errors --type snp --passphrase=mkcw-convert --add-file randomfile1:/in-a-subdir/rnd1 busybox busybox-cw
mkcw_check_image busybox-cw "" randomfile1:in-a-subdir/rnd1
run_buildah mkcw --ignore-attestation-errors --type snp --passphrase=mkcw-convert --add-file ${TEST_SCRATCH_DIR}/randomfile1:/in-a-subdir/rnd1 busybox busybox-cw
mkcw_check_image busybox-cw ${TEST_SCRATCH_DIR}/randomfile1:in-a-subdir/rnd1
# image has multiple layers, check with all-upper-case TEE type name
run_buildah mkcw --ignore-attestation-errors --type SNP --passphrase=mkcw-convert --add-file randomfile2:rnd2 $SAFEIMAGE my-cw
mkcw_check_image my-cw "" randomfile2:/rnd2
run_buildah mkcw --ignore-attestation-errors --type SNP --passphrase=mkcw-convert --add-file ${TEST_SCRATCH_DIR}/randomfile2:rnd2 $SAFEIMAGE my-cw
mkcw_check_image my-cw ${TEST_SCRATCH_DIR}/randomfile2:/rnd2
}

@test "mkcw-commit" {
Expand All @@ -86,13 +82,17 @@ function mkcw_check_image() {
fi
_prefetch $SAFEIMAGE

echo -n "mkcw commit" > "$TEST_SCRATCH_DIR"/key
passphrase="mkcw commit $(random_string)"
echo -n "$passphrase" > "$TEST_SCRATCH_DIR"/key
run_buildah from $SAFEIMAGE
ctrID="$output"
run_buildah commit --iidfile "$TEST_SCRATCH_DIR"/iid --cw type=SEV,ignore_attestation_errors,passphrase="mkcw commit" "$ctrID"
mkcw_check_image $(cat "$TEST_SCRATCH_DIR"/iid)
run_buildah commit --iidfile "$TEST_SCRATCH_DIR"/iid --cw type=sev,ignore_attestation_errors,passphrase="mkcw commit" "$ctrID"
mkcw_check_image $(cat "$TEST_SCRATCH_DIR"/iid)

iidfile="$TEST_SCRATCH_DIR/iid"
run_buildah commit --iidfile $iidfile --cw type=SEV,ignore_attestation_errors,passphrase="$passphrase" "$ctrID"
mkcw_check_image $(< $iidfile)

run_buildah commit --iidfile $iidfile --cw type=sev,ignore_attestation_errors,passphrase="$passphrase" "$ctrID"
mkcw_check_image $(< $iidfile)
}

@test "mkcw build" {
Expand Down

1 comment on commit 046ce42

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.