From 06cea37b8655cc247e1ceb7e9fb0152eb5736695 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/idmaps.bats | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/overlay/overlay.go b/drivers/overlay/overlay.go index e86218e65e..323d7c2747 100644 --- a/drivers/overlay/overlay.go +++ b/drivers/overlay/overlay.go @@ -991,6 +991,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/idmaps.bats b/tests/idmaps.bats index 45cf654ccb..c6690a97d3 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 ] +}