From 0acf8e9fecc55718931a539df514de1cc54b1ee3 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Wed, 18 Jul 2018 21:47:41 +0200 Subject: [PATCH] tests: add test for shifting support Signed-off-by: Giuseppe Scrivano --- drivers/overlay/overlay.go | 3 +++ tests/helpers.bash | 2 +- tests/idmaps.bats | 42 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/overlay/overlay.go b/drivers/overlay/overlay.go index 1b807cd514..c36109fb53 100644 --- a/drivers/overlay/overlay.go +++ b/drivers/overlay/overlay.go @@ -990,6 +990,9 @@ func (d *Driver) UpdateLayerIDMap(id string, toContainer, toHost *idtools.IDMapp // SupportsShifting tells whether the driver support shifting of the UIDs/GIDs in an userNS func (d *Driver) SupportsShifting() bool { + if os.Getenv("_TEST_FORCE_SUPPORT_SHIFTING") == "yes-please" { + return true + } return d.options.mountProgram != "" } diff --git a/tests/helpers.bash b/tests/helpers.bash index 09fd9a5745..8b5536d8f0 100755 --- a/tests/helpers.bash +++ b/tests/helpers.bash @@ -2,7 +2,7 @@ STORAGE_BINARY=${STORAGE_BINARY:-$(dirname ${BASH_SOURCE})/../containers-storage} TESTSDIR=${TESTSDIR:-$(dirname ${BASH_SOURCE})} -STORAGE_DRIVER=${STORAGE_DRIVER:-vfs} +STORAGE_DRIVER=${STORAGE_DRIVER:-overlay} STORAGE_OPTION=${STORAGE_OPTION:-} PATH=$(dirname ${BASH_SOURCE})/..:${PATH} diff --git a/tests/idmaps.bats b/tests/idmaps.bats index 45cf654ccb..c6aac46b8f 100644 --- a/tests/idmaps.bats +++ b/tests/idmaps.bats @@ -753,3 +753,45 @@ load helpers echo ntops:$ntops [ $ntops -eq 1 ] } + +@test "idmaps-create-mapped-container-shifting" { + case "$STORAGE_DRIVER" in + overlay*) + ;; + *) + skip "not supported by driver $STORAGE_DRIVER" + ;; + esac + + run storage --debug=false create-layer + [ "$status" -eq 0 ] + [ "$output" != "" ] + layer="$output" + # Mount the layer. + run storage --debug=false mount $layer + [ "$status" -eq 0 ] + [ "$output" != "" ] + lowermount="$output" + # Put a file in the layer. + createrandom "$lowermount"/file + storage unmount $layer + + imagename=idmappedimage-shifting + storage create-image --name=$imagename $layer + + _TEST_FORCE_SUPPORT_SHIFTING=yes-please run storage --debug=false create-container --uidmap 0:1000:1000 --gidmap 0:1000:1000 $imagename + echo "$output" + [ "$status" -eq 0 ] + [ "$output" != "" ] + + container="$output" + + # Mount the container. + run storage --debug=false mount $container + echo "$output" + [ "$status" -eq 0 ] + dir="$output" + test "$(stat -c%u:%g $dir/file)" == "0:0" + run storage --debug=false unmount "$container" + [ "$status" -eq 0 ] +}