From e9d67aca414101b26c8b29f10aded8b77ae34c9a Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Mon, 19 Feb 2018 15:47:25 +0000 Subject: [PATCH 01/19] tests: Switch from alpine:3.6 to alpine:3.7 Signed-off-by: Rolf Neugebauer --- tests/cases/020_pull/010_multiarch/test.ps1 | 2 +- tests/cases/020_pull/020_dct/test.ps1 | 2 +- tests/cases/030_build/010_simple/Dockerfile | 2 +- tests/cases/030_build/012_tag/Dockerfile | 2 +- tests/cases/030_build/014_iid/Dockerfile | 2 +- tests/cases/030_build/016_fail/Dockerfile | 2 +- tests/cases/030_build/020_build_arg/Dockerfile | 2 +- tests/cases/030_build/024_from_build_arg/test.ps1 | 2 +- tests/cases/030_build/026_workdir/Dockerfile | 2 +- tests/cases/030_build/030_multistage/Dockerfile | 6 +++--- tests/cases/030_build/032_multistage_scratch/Dockerfile | 4 ++-- tests/cases/060_volume/010_touch/test.ps1 | 2 +- 12 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/cases/020_pull/010_multiarch/test.ps1 b/tests/cases/020_pull/010_multiarch/test.ps1 index 06cb5a7..b0b8820 100755 --- a/tests/cases/020_pull/010_multiarch/test.ps1 +++ b/tests/cases/020_pull/010_multiarch/test.ps1 @@ -2,6 +2,6 @@ # LABELS: # REPEAT: -docker pull --platform linux alpine:3.6 +docker pull --platform linux alpine:3.7 if ($lastexitcode -ne 0) { exit 1 } exit 0 diff --git a/tests/cases/020_pull/020_dct/test.ps1 b/tests/cases/020_pull/020_dct/test.ps1 index c97e877..ce5ec09 100755 --- a/tests/cases/020_pull/020_dct/test.ps1 +++ b/tests/cases/020_pull/020_dct/test.ps1 @@ -3,6 +3,6 @@ # REPEAT: $env:DOCKER_CONTENT_TRUST=1 -docker pull --platform linux alpine:3.6 +docker pull --platform linux alpine:3.7 if ($lastexitcode -ne 0) { exit 1 } exit 0 diff --git a/tests/cases/030_build/010_simple/Dockerfile b/tests/cases/030_build/010_simple/Dockerfile index 7c1e05e..d887725 100644 --- a/tests/cases/030_build/010_simple/Dockerfile +++ b/tests/cases/030_build/010_simple/Dockerfile @@ -1,2 +1,2 @@ -FROM alpine:3.6 +FROM alpine:3.7 RUN touch /simple diff --git a/tests/cases/030_build/012_tag/Dockerfile b/tests/cases/030_build/012_tag/Dockerfile index 48c4aaf..55c45bd 100644 --- a/tests/cases/030_build/012_tag/Dockerfile +++ b/tests/cases/030_build/012_tag/Dockerfile @@ -1,2 +1,2 @@ -FROM alpine:3.6 +FROM alpine:3.7 RUN touch /tag diff --git a/tests/cases/030_build/014_iid/Dockerfile b/tests/cases/030_build/014_iid/Dockerfile index f6dbab6..037a947 100644 --- a/tests/cases/030_build/014_iid/Dockerfile +++ b/tests/cases/030_build/014_iid/Dockerfile @@ -1,2 +1,2 @@ -FROM alpine:3.6 +FROM alpine:3.7 RUN touch /iid diff --git a/tests/cases/030_build/016_fail/Dockerfile b/tests/cases/030_build/016_fail/Dockerfile index ff41e40..ef43223 100644 --- a/tests/cases/030_build/016_fail/Dockerfile +++ b/tests/cases/030_build/016_fail/Dockerfile @@ -1,2 +1,2 @@ -FROM alpine:3.6 +FROM alpine:3.7 RUN exit 1 diff --git a/tests/cases/030_build/020_build_arg/Dockerfile b/tests/cases/030_build/020_build_arg/Dockerfile index a66a293..c94ccf2 100644 --- a/tests/cases/030_build/020_build_arg/Dockerfile +++ b/tests/cases/030_build/020_build_arg/Dockerfile @@ -1,3 +1,3 @@ -FROM alpine:3.6 +FROM alpine:3.7 ARG ARGUMENT RUN echo ${ARGUMENT} diff --git a/tests/cases/030_build/024_from_build_arg/test.ps1 b/tests/cases/030_build/024_from_build_arg/test.ps1 index e79901e..2206d86 100755 --- a/tests/cases/030_build/024_from_build_arg/test.ps1 +++ b/tests/cases/030_build/024_from_build_arg/test.ps1 @@ -8,7 +8,7 @@ Set-PSDebug -Trace 2 $imageName = "build-from-build-arg" -docker build --platform linux -t $imageName --build-arg IMAGE=alpine:3.6 . +docker build --platform linux -t $imageName --build-arg IMAGE=alpine:3.7 . if ($lastexitcode -ne 0) { exit 1 } diff --git a/tests/cases/030_build/026_workdir/Dockerfile b/tests/cases/030_build/026_workdir/Dockerfile index 6281395..daa1ac6 100644 --- a/tests/cases/030_build/026_workdir/Dockerfile +++ b/tests/cases/030_build/026_workdir/Dockerfile @@ -1,3 +1,3 @@ -FROM alpine:3.6 +FROM alpine:3.7 WORKDIR /foo RUN touch workdir diff --git a/tests/cases/030_build/030_multistage/Dockerfile b/tests/cases/030_build/030_multistage/Dockerfile index 78c26dd..668bbb1 100644 --- a/tests/cases/030_build/030_multistage/Dockerfile +++ b/tests/cases/030_build/030_multistage/Dockerfile @@ -1,9 +1,9 @@ -FROM alpine:3.6 AS stage0 +FROM alpine:3.7 AS stage0 RUN touch /multi0 -FROM alpine:3.6 AS stage1 +FROM alpine:3.7 AS stage1 RUN touch /multi1 -FROM alpine:3.6 +FROM alpine:3.7 COPY --from=stage0 /multi0 / COPY --from=stage1 /multi1 / diff --git a/tests/cases/030_build/032_multistage_scratch/Dockerfile b/tests/cases/030_build/032_multistage_scratch/Dockerfile index 09a037d..7eeebc7 100644 --- a/tests/cases/030_build/032_multistage_scratch/Dockerfile +++ b/tests/cases/030_build/032_multistage_scratch/Dockerfile @@ -1,7 +1,7 @@ -FROM alpine:3.6 AS stage0 +FROM alpine:3.7 AS stage0 RUN touch /multi-scratch0 -FROM alpine:3.6 AS stage1 +FROM alpine:3.7 AS stage1 RUN touch /multi-scratch1 FROM scratch diff --git a/tests/cases/060_volume/010_touch/test.ps1 b/tests/cases/060_volume/010_touch/test.ps1 index 2de34ee..f660563 100755 --- a/tests/cases/060_volume/010_touch/test.ps1 +++ b/tests/cases/060_volume/010_touch/test.ps1 @@ -10,7 +10,7 @@ $fileName = "foobar" Remove-Item -Path $fileName -Force $p = [string]$pwd.Path -docker run --platform linux --rm -v $p`:/test alpine:3.6 touch /test/$fileName +docker run --platform linux --rm -v $p`:/test alpine:3.7 touch /test/$fileName if ($lastexitcode -ne 0) { exit 1 } From 3d4f1ea7f76089066eef3dd70363edc44fa0b6fe Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Tue, 27 Feb 2018 13:12:27 +0000 Subject: [PATCH 02/19] tests: Remove export test This command is not for docker images Signed-off-by: Rolf Neugebauer --- tests/cases/025_image/020_export/test.ps1 | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100755 tests/cases/025_image/020_export/test.ps1 diff --git a/tests/cases/025_image/020_export/test.ps1 b/tests/cases/025_image/020_export/test.ps1 deleted file mode 100755 index 2ced384..0000000 --- a/tests/cases/025_image/020_export/test.ps1 +++ /dev/null @@ -1,23 +0,0 @@ -# SUMMARY: Test docker image save -# LABELS: -# REPEAT: - -Set-PSDebug -Trace 2 - -$fileName = "hello-world.tar" - -docker pull --platform linux hello-world -if ($lastexitcode -ne 0) { - exit 1 -} - -docker image export -o $fileName hello-world -if ($lastexitcode -ne 0) { - exit 1 -} - -if (Test-Path $fileName) { - Remove-Item -Path $fileName -Force - exit 0 -} -exit 1 From 457f5d3ec4a545d280605dbb731993b86c41ce6b Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Mon, 19 Feb 2018 18:19:48 +0000 Subject: [PATCH 03/19] tests: Tweak touch test Signed-off-by: Rolf Neugebauer --- tests/cases/060_volume/010_touch/test.ps1 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/cases/060_volume/010_touch/test.ps1 b/tests/cases/060_volume/010_touch/test.ps1 index f660563..2e7fe0d 100755 --- a/tests/cases/060_volume/010_touch/test.ps1 +++ b/tests/cases/060_volume/010_touch/test.ps1 @@ -1,4 +1,4 @@ -# SUMMARY: Simple test that we can create (touch) a file on the host +# SUMMARY: Create (touch) a file on volume mount and check on the host # LABELS: # REPEAT: @@ -6,16 +6,18 @@ Set-PSDebug -Trace 2 $fileName = "foobar" -# Make sure the -Remove-Item -Path $fileName -Force +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} $p = [string]$pwd.Path -docker run --platform linux --rm -v $p`:/test alpine:3.7 touch /test/$fileName +docker run --platform linux --rm -v $p`:/test alpine:3.7 sh -c "touch /test/$fileName" if ($lastexitcode -ne 0) { exit 1 } -if (Test-Path $fileName) { +if (Test-Path $fileName -PathType leaf) { + Remove-Item -Path $fileName -Force exit 0 } exit 1 From 957132b2c51681225e65f8e7421881e979136ded Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Mon, 19 Feb 2018 17:57:53 +0000 Subject: [PATCH 04/19] tests: Create a file on a volume mount and read it from the host Signed-off-by: Rolf Neugebauer --- tests/cases/060_volume/015_echo/test.ps1 | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 tests/cases/060_volume/015_echo/test.ps1 diff --git a/tests/cases/060_volume/015_echo/test.ps1 b/tests/cases/060_volume/015_echo/test.ps1 new file mode 100755 index 0000000..9f6a0f7 --- /dev/null +++ b/tests/cases/060_volume/015_echo/test.ps1 @@ -0,0 +1,28 @@ +# SUMMARY: Create a file on mounted volume and check contents on the host +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$fileName = "foobar" + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} + +$p = [string]$pwd.Path +docker run --platform linux --rm -v $p`:/test alpine:3.7 sh -c "echo -n $fileName > /test/$fileName" +if ($lastexitcode -ne 0) { + exit 1 +} + +if (Test-Path $fileName -PathType leaf) { + $content = Get-Content $fileName -Raw + Remove-Item -Path $fileName -Force + if ($content -ne $fileName) { + $content + exit 1 + } + exit 0 +} +exit 1 From c5221092152de5f9d9943d52a6b3ca0ae8a5788a Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 21 Feb 2018 13:35:07 +0000 Subject: [PATCH 05/19] tests: Add test to check mkdir works on a volume mount Signed-off-by: Rolf Neugebauer --- tests/cases/060_volume/020_mkdir/test.ps1 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 tests/cases/060_volume/020_mkdir/test.ps1 diff --git a/tests/cases/060_volume/020_mkdir/test.ps1 b/tests/cases/060_volume/020_mkdir/test.ps1 new file mode 100755 index 0000000..7a20e8a --- /dev/null +++ b/tests/cases/060_volume/020_mkdir/test.ps1 @@ -0,0 +1,23 @@ +# SUMMARY: Create a directory on a mounted volume and check on the host +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$fileName = "foobar" + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} + +$p = [string]$pwd.Path +docker run --platform linux --rm -v $p`:/test alpine:3.7 sh -c "mkdir /test/$fileName" +if ($lastexitcode -ne 0) { + exit 1 +} + +if (Test-Path $fileName -PathType container) { + Remove-Item -Path $fileName -Force + exit 0 +} +exit 1 From ecb423825212a89a6da0bbd0d4f987da1682ae2d Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 21 Feb 2018 14:01:40 +0000 Subject: [PATCH 06/19] tests: Create directories on a mounted volume and check on the host Signed-off-by: Rolf Neugebauer --- tests/cases/060_volume/025_mkdir_p/test.ps1 | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 tests/cases/060_volume/025_mkdir_p/test.ps1 diff --git a/tests/cases/060_volume/025_mkdir_p/test.ps1 b/tests/cases/060_volume/025_mkdir_p/test.ps1 new file mode 100755 index 0000000..402efca --- /dev/null +++ b/tests/cases/060_volume/025_mkdir_p/test.ps1 @@ -0,0 +1,24 @@ +# SUMMARY: Create directories on a mounted volume and check on the host +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$fileName = "foo/bar" +$fileNameWin = "foo\bar" + +if (Test-Path $fileNameWin) { + Remove-Item -Path $fileNameWin -Force +} + +$p = [string]$pwd.Path +docker run --platform linux --rm -v $p`:/test alpine:3.7 sh -c "mkdir -p /test/$fileName" +if ($lastexitcode -ne 0) { + exit 1 +} + +if (Test-Path $fileNameWin -PathType container) { + Remove-Item -Path $fileNameWin -Force + exit 0 +} +exit 1 From 13dbc73d4554eba25becda529fbe729c1e8cf47e Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 21 Feb 2018 15:09:25 +0000 Subject: [PATCH 07/19] tests: Create a sub-directory on a mounted volume and check on the host Signed-off-by: Rolf Neugebauer --- .../cases/060_volume/022_mkdir_host/test.ps1 | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tests/cases/060_volume/022_mkdir_host/test.ps1 diff --git a/tests/cases/060_volume/022_mkdir_host/test.ps1 b/tests/cases/060_volume/022_mkdir_host/test.ps1 new file mode 100755 index 0000000..fe622a0 --- /dev/null +++ b/tests/cases/060_volume/022_mkdir_host/test.ps1 @@ -0,0 +1,26 @@ +# SUMMARY: Create a sub-directory on a mounted volume and check on the host +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$baseName = "foobar" +$fileName = "baz" + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force -Recurse +} + +New-Item -ItemType directory $baseName + +$p = [string]$pwd.Path +docker run --platform linux --rm -v $p`:/test alpine:3.7 sh -c "mkdir /test/$baseName/$fileName" +if ($lastexitcode -ne 0) { + exit 1 +} + +if (Test-Path $baseName\$fileName -PathType container) { + Remove-Item -Path $baseName -Force -Recurse + exit 0 +} +exit 1 From 3cda17c731ad3d89a44d9170d997ce916b25f2c0 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 21 Feb 2018 17:13:08 +0000 Subject: [PATCH 08/19] tests: Remove a subdir create on the host in a container Signed-off-by: Rolf Neugebauer --- .../cases/060_volume/030_rmdir_host/test.ps1 | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 tests/cases/060_volume/030_rmdir_host/test.ps1 diff --git a/tests/cases/060_volume/030_rmdir_host/test.ps1 b/tests/cases/060_volume/030_rmdir_host/test.ps1 new file mode 100755 index 0000000..403ba5b --- /dev/null +++ b/tests/cases/060_volume/030_rmdir_host/test.ps1 @@ -0,0 +1,25 @@ +# SUMMARY: Remove a subdir create on the host in a container +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$dirName = "foobar" + +if (Test-Path $dirName) { + Remove-Item -Path $dirName -Force -Recurse +} + +New-Item -ItemType directory $dirName + +$p = [string]$pwd.Path +docker run --platform linux --rm -v $p`:/test alpine:3.7 sh -c "rmdir /test/$dirName" +if ($lastexitcode -ne 0) { + exit 1 +} + +if (Test-Path $dirName) { + Remove-Item -Path $baseName -Force -Recurse + exit 1 +} +exit 0 From 703454396df35e1999deba8eaab07158dbe3c760 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 21 Feb 2018 16:59:27 +0000 Subject: [PATCH 09/19] tests: Try to remove a non-empty sub-directory on a mounted volume Signed-off-by: Rolf Neugebauer --- .../060_volume/035_rmdir_nonempty/Dockerfile | 3 +++ .../035_rmdir_nonempty/rmdir_test.sh | 15 +++++++++++++++ .../060_volume/035_rmdir_nonempty/test.ps1 | 19 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 tests/cases/060_volume/035_rmdir_nonempty/Dockerfile create mode 100644 tests/cases/060_volume/035_rmdir_nonempty/rmdir_test.sh create mode 100755 tests/cases/060_volume/035_rmdir_nonempty/test.ps1 diff --git a/tests/cases/060_volume/035_rmdir_nonempty/Dockerfile b/tests/cases/060_volume/035_rmdir_nonempty/Dockerfile new file mode 100644 index 0000000..b7ccb31 --- /dev/null +++ b/tests/cases/060_volume/035_rmdir_nonempty/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine:3.7 +COPY rmdir_test.sh / +RUN chmod ugo+x rmdir_test.sh diff --git a/tests/cases/060_volume/035_rmdir_nonempty/rmdir_test.sh b/tests/cases/060_volume/035_rmdir_nonempty/rmdir_test.sh new file mode 100644 index 0000000..d541701 --- /dev/null +++ b/tests/cases/060_volume/035_rmdir_nonempty/rmdir_test.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e +set -x + +DIR=$1 + +cd "$DIR" || exit 1 +rm -rf foo +mkdir foo +touch foo/bar +(rmdir foo 2> output || true) +cat output +rm -rf foo +grep "Directory not empty" output diff --git a/tests/cases/060_volume/035_rmdir_nonempty/test.ps1 b/tests/cases/060_volume/035_rmdir_nonempty/test.ps1 new file mode 100755 index 0000000..049092f --- /dev/null +++ b/tests/cases/060_volume/035_rmdir_nonempty/test.ps1 @@ -0,0 +1,19 @@ +# SUMMARY: Try to remove a non-empty sub-directory on a mounted volume +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$imageName = "rmdir-nonempty" + +docker build --platform linux -t $imageName . +if ($lastexitcode -ne 0) { + exit 1 +} + +$p = [string]$pwd.Path +docker run --rm -v $p`:/test $imageName /rmdir_test.sh /test +if ($lastexitcode -ne 0) { + exit 1 +} +exit 0 From 350927c20bb3bf6eb6b0a30f6bdf693e0ff041e5 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Mon, 19 Feb 2018 17:19:00 +0000 Subject: [PATCH 10/19] tests: Add a test for symlink on a volume mount Signed-off-by: Rolf Neugebauer --- .../060_volume/050_symlink_volume/Dockerfile | 3 ++ .../050_symlink_volume/symlink_test.sh | 21 +++++++++++ .../060_volume/050_symlink_volume/test.ps1 | 37 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 tests/cases/060_volume/050_symlink_volume/Dockerfile create mode 100644 tests/cases/060_volume/050_symlink_volume/symlink_test.sh create mode 100755 tests/cases/060_volume/050_symlink_volume/test.ps1 diff --git a/tests/cases/060_volume/050_symlink_volume/Dockerfile b/tests/cases/060_volume/050_symlink_volume/Dockerfile new file mode 100644 index 0000000..7f66e07 --- /dev/null +++ b/tests/cases/060_volume/050_symlink_volume/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine:3.7 +COPY symlink_test.sh / +RUN chmod ugo+x symlink_test.sh diff --git a/tests/cases/060_volume/050_symlink_volume/symlink_test.sh b/tests/cases/060_volume/050_symlink_volume/symlink_test.sh new file mode 100644 index 0000000..5703bba --- /dev/null +++ b/tests/cases/060_volume/050_symlink_volume/symlink_test.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +set -e +set -x + +FILE=$1 +LINK=$2 +CONTENT="foo" + +echo "$CONTENT" > $FILE +ln -s "$FILE" "$LINK" + +if [[ $(readlink "$LINK") != "$FILE" ]]; then + echo "Symlink $LINK is not pointing to $FILE" + exit 1 +fi + +if [[ $(cat "$LINK") != "$CONTENT" ]]; then + echo "Contents don't match" + exit 1 +fi diff --git a/tests/cases/060_volume/050_symlink_volume/test.ps1 b/tests/cases/060_volume/050_symlink_volume/test.ps1 new file mode 100755 index 0000000..d4922f5 --- /dev/null +++ b/tests/cases/060_volume/050_symlink_volume/test.ps1 @@ -0,0 +1,37 @@ +# SUMMARY: Create a symlink on a volume mount and check in container +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$imageName = "symlink-container" +$fileName = "foobar" +$linkName = "barfoo" + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} +if (Test-Path $linkName) { + Remove-Item -Path $linkName -Force +} + +docker build --platform linux -t $imageName . +if ($lastexitcode -ne 0) { + exit 1 +} + +$p = [string]$pwd.Path +docker run --rm -v $p`:/test $imageName /symlink_test.sh /test/$fileName /test/$linkName +if ($lastexitcode -ne 0) { + if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force + } + if (Test-Path $linkName) { + Remove-Item -Path $linkName -Force + } + exit 1 +} + +Remove-Item -Path $fileName -Force +Remove-Item -Path $linkName -Force +exit 0 From 03ea25c026a3246bd91e4a7e406799dd5f06c743 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 21 Feb 2018 14:21:36 +0000 Subject: [PATCH 11/19] tests: Create a hard link on a volume mount and check in container Signed-off-by: Rolf Neugebauer --- .../060_volume/055_hardlink_volume/Dockerfile | 3 ++ .../055_hardlink_volume/hardlink_test.sh | 31 ++++++++++++++++ .../060_volume/055_hardlink_volume/test.ps1 | 37 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 tests/cases/060_volume/055_hardlink_volume/Dockerfile create mode 100644 tests/cases/060_volume/055_hardlink_volume/hardlink_test.sh create mode 100755 tests/cases/060_volume/055_hardlink_volume/test.ps1 diff --git a/tests/cases/060_volume/055_hardlink_volume/Dockerfile b/tests/cases/060_volume/055_hardlink_volume/Dockerfile new file mode 100644 index 0000000..1775fac --- /dev/null +++ b/tests/cases/060_volume/055_hardlink_volume/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine:3.7 +COPY hardlink_test.sh / +RUN chmod ugo+x hardlink_test.sh diff --git a/tests/cases/060_volume/055_hardlink_volume/hardlink_test.sh b/tests/cases/060_volume/055_hardlink_volume/hardlink_test.sh new file mode 100644 index 0000000..65ea82e --- /dev/null +++ b/tests/cases/060_volume/055_hardlink_volume/hardlink_test.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +set -e +set -x + +FILE=$1 +LINK=$2 +CONTENT="foo" + +echo "$CONTENT" > $FILE +ln "$FILE" "$LINK" + +if [[ $(stat -c %h "$FILE") != $(stat -c %h "$LINK") ]]; then + echo "Number of hardlinks don't match" + exit 1 +fi + +if [[ $(stat -c %i "$FILE") != $(stat -c %i "$LINK") ]]; then + echo "Inode numbers don't match" + exit 1 +fi + +if [[ $(stat -c %h "$FILE") <= 1 ]]; then + echo "$FILE should Number of hardlinks greater than 1" + exit 1 +fi + +if [[ $(cat "$LINK") != "$CONTENT" ]]; then + echo "Contents don't match" + exit 1 +fi diff --git a/tests/cases/060_volume/055_hardlink_volume/test.ps1 b/tests/cases/060_volume/055_hardlink_volume/test.ps1 new file mode 100755 index 0000000..926ccff --- /dev/null +++ b/tests/cases/060_volume/055_hardlink_volume/test.ps1 @@ -0,0 +1,37 @@ +# SUMMARY: Create a hard link on a volume mount and check in container +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$imageName = "hardlink-container" +$fileName = "foobar" +$linkName = "barfoo" + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} +if (Test-Path $linkName) { + Remove-Item -Path $linkName -Force +} + +docker build --platform linux -t $imageName . +if ($lastexitcode -ne 0) { + exit 1 +} + +$p = [string]$pwd.Path +docker run --rm -v $p`:/test $imageName /hardlink_test.sh /test/$fileName /test/$linkName +if ($lastexitcode -ne 0) { + if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force + } + if (Test-Path $linkName) { + Remove-Item -Path $linkName -Force + } + exit 1 +} + +Remove-Item -Path $fileName -Force +Remove-Item -Path $linkName -Force +exit 0 From dd33f1e0d8f54ea30d01deb50c9d92d68ea59e80 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 21 Feb 2018 14:57:11 +0000 Subject: [PATCH 12/19] tests: Create a fifo on a volume mount and check in container Signed-off-by: Rolf Neugebauer --- .../060_volume/060_mkfifo_volume/Dockerfile | 3 ++ .../060_mkfifo_volume/mkfifo_test.sh | 14 +++++++++ .../060_volume/060_mkfifo_volume/test.ps1 | 29 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 tests/cases/060_volume/060_mkfifo_volume/Dockerfile create mode 100644 tests/cases/060_volume/060_mkfifo_volume/mkfifo_test.sh create mode 100755 tests/cases/060_volume/060_mkfifo_volume/test.ps1 diff --git a/tests/cases/060_volume/060_mkfifo_volume/Dockerfile b/tests/cases/060_volume/060_mkfifo_volume/Dockerfile new file mode 100644 index 0000000..fc7ea64 --- /dev/null +++ b/tests/cases/060_volume/060_mkfifo_volume/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine:3.7 +COPY mkfifo_test.sh / +RUN chmod ugo+x mkfifo_test.sh diff --git a/tests/cases/060_volume/060_mkfifo_volume/mkfifo_test.sh b/tests/cases/060_volume/060_mkfifo_volume/mkfifo_test.sh new file mode 100644 index 0000000..bbdd419 --- /dev/null +++ b/tests/cases/060_volume/060_mkfifo_volume/mkfifo_test.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -e +set -x + +FILE=$1 + +mkfifo "$FILE" + +TYPE=$(stat -c %F "$FILE") +if [ "$TYPE" != "fifo" ]; then + echo "$FILE is not a fifo: $TYPE != fifo" + exit 1 +fi diff --git a/tests/cases/060_volume/060_mkfifo_volume/test.ps1 b/tests/cases/060_volume/060_mkfifo_volume/test.ps1 new file mode 100755 index 0000000..56040c6 --- /dev/null +++ b/tests/cases/060_volume/060_mkfifo_volume/test.ps1 @@ -0,0 +1,29 @@ +# SUMMARY: Create a fifo on a volume mount and check in container +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$imageName = "mkfifo-container" +$fileName = "foobar" + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} + +docker build --platform linux -t $imageName . +if ($lastexitcode -ne 0) { + exit 1 +} + +$p = [string]$pwd.Path +docker run --rm -v $p`:/test $imageName /mkfifo_test.sh /test/$fileName +if ($lastexitcode -ne 0) { + if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force + } + exit 1 +} + +Remove-Item -Path $fileName -Force +exit 0 From 76dab42061f6b0ab1884d37effc5f4000975f904 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 21 Feb 2018 16:10:14 +0000 Subject: [PATCH 13/19] tests: Create a unix domain socket a volume mount and check in container Signed-off-by: Rolf Neugebauer --- .../060_volume/070_socket_volume/Dockerfile | 4 +++ .../070_socket_volume/socket_test.sh | 20 ++++++++++++ .../060_volume/070_socket_volume/test.ps1 | 31 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 tests/cases/060_volume/070_socket_volume/Dockerfile create mode 100644 tests/cases/060_volume/070_socket_volume/socket_test.sh create mode 100755 tests/cases/060_volume/070_socket_volume/test.ps1 diff --git a/tests/cases/060_volume/070_socket_volume/Dockerfile b/tests/cases/060_volume/070_socket_volume/Dockerfile new file mode 100644 index 0000000..f28204d --- /dev/null +++ b/tests/cases/060_volume/070_socket_volume/Dockerfile @@ -0,0 +1,4 @@ +FROM alpine:3.7 +RUN apk add --no-cache netcat-openbsd +COPY socket_test.sh / +RUN chmod ugo+x socket_test.sh diff --git a/tests/cases/060_volume/070_socket_volume/socket_test.sh b/tests/cases/060_volume/070_socket_volume/socket_test.sh new file mode 100644 index 0000000..5aab273 --- /dev/null +++ b/tests/cases/060_volume/070_socket_volume/socket_test.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +set -e +set -x + +FILE=$1 + +nc -lU "$FILE" & +pid=$! + +sleep 1 + +TYPE=$(stat -c %F "$FILE") + +kill "$pid" + +if [ "$TYPE" != "socket" ]; then + echo "$FILE is not a unix domain socket: $TYPE != socket" + exit 1 +fi diff --git a/tests/cases/060_volume/070_socket_volume/test.ps1 b/tests/cases/060_volume/070_socket_volume/test.ps1 new file mode 100755 index 0000000..829e2b9 --- /dev/null +++ b/tests/cases/060_volume/070_socket_volume/test.ps1 @@ -0,0 +1,31 @@ +# SUMMARY: Create a unix domain socket a volume mount and check in container +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$imageName = "socket-container" +$fileName = "foobar" + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} + +docker build --platform linux -t $imageName . +if ($lastexitcode -ne 0) { + exit 1 +} + +$p = [string]$pwd.Path +docker run --rm -v $p`:/test $imageName /socket_test.sh /test/$fileName +if ($lastexitcode -ne 0) { + if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force + } + exit 1 +} + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} +exit 0 From dc927c848ef84ca99e97e0d867d8171b4bc902e7 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Mon, 19 Feb 2018 16:23:36 +0000 Subject: [PATCH 14/19] tests: Add test for chown on files on a volume mount Signed-off-by: Rolf Neugebauer --- .../100_chown_file_volume/Dockerfile | 3 + .../100_chown_file_volume/chown_test.sh | 120 ++++++++++++++++++ .../060_volume/100_chown_file_volume/test.ps1 | 29 +++++ 3 files changed, 152 insertions(+) create mode 100644 tests/cases/060_volume/100_chown_file_volume/Dockerfile create mode 100644 tests/cases/060_volume/100_chown_file_volume/chown_test.sh create mode 100644 tests/cases/060_volume/100_chown_file_volume/test.ps1 diff --git a/tests/cases/060_volume/100_chown_file_volume/Dockerfile b/tests/cases/060_volume/100_chown_file_volume/Dockerfile new file mode 100644 index 0000000..78ec750 --- /dev/null +++ b/tests/cases/060_volume/100_chown_file_volume/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine:3.7 +COPY chown_test.sh / +RUN chmod ugo+x chown_test.sh diff --git a/tests/cases/060_volume/100_chown_file_volume/chown_test.sh b/tests/cases/060_volume/100_chown_file_volume/chown_test.sh new file mode 100644 index 0000000..aaac0ee --- /dev/null +++ b/tests/cases/060_volume/100_chown_file_volume/chown_test.sh @@ -0,0 +1,120 @@ +#!/bin/sh + +set -e +set -x + +# This script tests a number of combination of chown of files. It does +# *not* error on the first error, instead all tests are run. + +FILE=$1 +ret=0 + +echo +TEST="chown file uid only (nobody)" +rm -rf "$FILE" +touch "$FILE" +chown nobody "$FILE" +RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +EXPECTED="nobody:root" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +echo +TEST="chown file uid only (postgres)" +rm -rf "$FILE" +touch "$FILE" +chown postgres "$FILE" +RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +EXPECTED="postgres:root" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +echo +TEST="chown file uid only (root)" +rm -rf "$FILE" +touch "$FILE" +chown root "$FILE" +RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +EXPECTED="root:root" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +echo +TEST="chown file gid only (nobody)" +rm -rf "$FILE" +touch "$FILE" +chown :nobody "$FILE" +RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +EXPECTED="root:nobody" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +echo +TEST="chown file gid only (postgres)" +rm -rf "$FILE" +touch "$FILE" +chown :postgres "$FILE" +RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +EXPECTED="root:postgres" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +echo +TEST="chown file gid only (root)" +rm -rf "$FILE" +touch "$FILE" +chown :root "$FILE" +RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +EXPECTED="root:root" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +echo +TEST="chown file uid and gid (nobody)" +rm -rf "$FILE" +touch "$FILE" +chown nobody:nobody "$FILE" +RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +EXPECTED="nobody:nobody" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +echo +TEST="chown file uid and gid (postgres)" +rm -rf "$FILE" +touch "$FILE" +chown postgres:postgres "$FILE" +RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +EXPECTED="postgres:postgres" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +echo +TEST="chown file uid and gid (root)" +rm -rf "$FILE" +touch "$FILE" +chown root:root "$FILE" +RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +EXPECTED="root:root" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +exit $ret diff --git a/tests/cases/060_volume/100_chown_file_volume/test.ps1 b/tests/cases/060_volume/100_chown_file_volume/test.ps1 new file mode 100644 index 0000000..a0f3ad9 --- /dev/null +++ b/tests/cases/060_volume/100_chown_file_volume/test.ps1 @@ -0,0 +1,29 @@ +# SUMMARY: Check permutations of chown on a file on a volume mount in a container +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$imageName = "chown-container" +$fileName = "foobar" + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} + +docker build --platform linux -t $imageName . +if ($lastexitcode -ne 0) { + exit 1 +} + +$p = [string]$pwd.Path +docker run --rm -v $p`:/test $imageName /chown_test.sh /test/$fileName +if ($lastexitcode -ne 0) { + if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force + } + exit 1 +} + +Remove-Item -Path $fileName -Force +exit 0 From e0ed9b894c5ed1a9d8d97c7fab32e832e22e776d Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Wed, 21 Feb 2018 17:34:59 +0000 Subject: [PATCH 15/19] tests: Check permutations of chown on a symlink on a volume mount in a container Signed-off-by: Rolf Neugebauer --- .../105_chown_symlink_volume/Dockerfile | 3 + .../105_chown_symlink_volume/chown_test.sh | 171 ++++++++++++++++++ .../105_chown_symlink_volume/test.ps1 | 34 ++++ 3 files changed, 208 insertions(+) create mode 100644 tests/cases/060_volume/105_chown_symlink_volume/Dockerfile create mode 100644 tests/cases/060_volume/105_chown_symlink_volume/chown_test.sh create mode 100644 tests/cases/060_volume/105_chown_symlink_volume/test.ps1 diff --git a/tests/cases/060_volume/105_chown_symlink_volume/Dockerfile b/tests/cases/060_volume/105_chown_symlink_volume/Dockerfile new file mode 100644 index 0000000..78ec750 --- /dev/null +++ b/tests/cases/060_volume/105_chown_symlink_volume/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine:3.7 +COPY chown_test.sh / +RUN chmod ugo+x chown_test.sh diff --git a/tests/cases/060_volume/105_chown_symlink_volume/chown_test.sh b/tests/cases/060_volume/105_chown_symlink_volume/chown_test.sh new file mode 100644 index 0000000..d419f9c --- /dev/null +++ b/tests/cases/060_volume/105_chown_symlink_volume/chown_test.sh @@ -0,0 +1,171 @@ +#!/bin/sh + +set -e +set -x + +# This script tests a number of combination of chown of symlink. It does +# *not* error on the first error, instead all tests are run. + +FILE=$1 +LINK=$2 +ret=0 + +touch "$FILE" +# We use 'chown -h' below so expect only the symlink but not +# the real file to change. +FILE_EXPECTED=$(su -c "stat -c %U:%G $FILE" postgres) + +echo +TEST="chown symlink uid only (nobody)" +rm -rf "$LINK" +ln -s "$FILE" "$LINK" +chown -h nobody "$LINK" +RESULT=$(su -c "stat -c %U:%G $LINK" postgres) +EXPECTED="nobody:root" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi +FILE_RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +if [ "$FILE_EXPECTED" != "$FILE_RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT on real file" + ret=1 +fi + +echo +TEST="chown symlink uid only (postgres)" +rm -rf "$LINK" +ln -s "$FILE" "$LINK" +chown -h postgres "$LINK" +RESULT=$(su -c "stat -c %U:%G $LINK" postgres) +EXPECTED="postgres:root" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi +FILE_RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +if [ "$FILE_EXPECTED" != "$FILE_RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT on real file" + ret=1 +fi + +echo +TEST="chown symlink uid only (root)" +rm -rf "$LINK" +ln -s "$FILE" "$LINK" +chown -h root "$LINK" +RESULT=$(su -c "stat -c %U:%G $LINK" postgres) +EXPECTED="root:root" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi +FILE_RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +if [ "$FILE_EXPECTED" != "$FILE_RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT on real file" + ret=1 +fi + +echo +TEST="chown symlink gid only (nobody)" +rm -rf "$LINK" +ln -s "$FILE" "$LINK" +chown -h :nobody "$LINK" +RESULT=$(su -c "stat -c %U:%G $LINK" postgres) +EXPECTED="root:nobody" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi +FILE_RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +if [ "$FILE_EXPECTED" != "$FILE_RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT on real file" + ret=1 +fi + +echo +TEST="chown symlink gid only (postgres)" +rm -rf "$LINK" +ln -s "$FILE" "$LINK" +chown -h :postgres "$LINK" +RESULT=$(su -c "stat -c %U:%G $LINK" postgres) +EXPECTED="root:postgres" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi +FILE_RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +if [ "$FILE_EXPECTED" != "$FILE_RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT on real file" + ret=1 +fi + +echo +TEST="chown symlink gid only (root)" +rm -rf "$LINK" +ln -s "$FILE" "$LINK" +chown -h :root "$LINK" +RESULT=$(su -c "stat -c %U:%G $LINK" postgres) +EXPECTED="root:root" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi +FILE_RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +if [ "$FILE_EXPECTED" != "$FILE_RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT on real file" + ret=1 +fi + +echo +TEST="chown symlink uid and gid (nobody)" +rm -rf "$LINK" +ln -s "$FILE" "$LINK" +chown -h nobody:nobody "$LINK" +RESULT=$(su -c "stat -c %U:%G $LINK" postgres) +EXPECTED="nobody:nobody" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi +FILE_RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +if [ "$FILE_EXPECTED" != "$FILE_RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT on real file" + ret=1 +fi + +echo +TEST="chown symlink uid and gid (postgres)" +rm -rf "$LINK" +ln -s "$FILE" "$LINK" +chown -h postgres:postgres "$LINK" +RESULT=$(su -c "stat -c %U:%G $LINK" postgres) +EXPECTED="postgres:postgres" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi +FILE_RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +if [ "$FILE_EXPECTED" != "$FILE_RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT on real file" + ret=1 +fi + +echo +TEST="chown symlink uid and gid (root)" +rm -rf "$LINK" +ln -s "$FILE" "$LINK" +chown -h root:root "$LINK" +RESULT=$(su -c "stat -c %U:%G $LINK" postgres) +EXPECTED="root:root" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi +FILE_RESULT=$(su -c "stat -c %U:%G $FILE" postgres) +if [ "$FILE_EXPECTED" != "$FILE_RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT on real file" + ret=1 +fi + +exit $ret diff --git a/tests/cases/060_volume/105_chown_symlink_volume/test.ps1 b/tests/cases/060_volume/105_chown_symlink_volume/test.ps1 new file mode 100644 index 0000000..a7ff30e --- /dev/null +++ b/tests/cases/060_volume/105_chown_symlink_volume/test.ps1 @@ -0,0 +1,34 @@ +# SUMMARY: Check permutations of chown on a symlink on a volume mount in a container +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$imageName = "chown-symlink-container" +$fileName = "foobar" +$linkName = "barfoo" + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} + +docker build --platform linux -t $imageName . +if ($lastexitcode -ne 0) { + exit 1 +} + +$p = [string]$pwd.Path +docker run --rm -v $p`:/test $imageName /chown_test.sh /test/$fileName /test/$linkName +if ($lastexitcode -ne 0) { + if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force + } + if (Test-Path $linkName) { + Remove-Item -Path $linkName -Force + } + exit 1 +} + +Remove-Item -Path $fileName -Force +Remove-Item -Path $linkName -Force +exit 0 From 34c78e7f4524f7af0cf2eaf90a369357ad0bbbce Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Tue, 27 Feb 2018 15:02:39 +0000 Subject: [PATCH 16/19] tests: Test for chmod on file on a volume Note this test only checks that the mode changed, but *not* that it is enforced. Signed-off-by: Rolf Neugebauer --- .../110_chmod_file_mode_volume/Dockerfile | 3 + .../110_chmod_file_mode_volume/chmod_test.sh | 85 +++++++++++++++++++ .../110_chmod_file_mode_volume/test.ps1 | 29 +++++++ 3 files changed, 117 insertions(+) create mode 100644 tests/cases/060_volume/110_chmod_file_mode_volume/Dockerfile create mode 100644 tests/cases/060_volume/110_chmod_file_mode_volume/chmod_test.sh create mode 100644 tests/cases/060_volume/110_chmod_file_mode_volume/test.ps1 diff --git a/tests/cases/060_volume/110_chmod_file_mode_volume/Dockerfile b/tests/cases/060_volume/110_chmod_file_mode_volume/Dockerfile new file mode 100644 index 0000000..44f8720 --- /dev/null +++ b/tests/cases/060_volume/110_chmod_file_mode_volume/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine:3.7 +COPY chmod_test.sh / +RUN chmod ugo+x chmod_test.sh diff --git a/tests/cases/060_volume/110_chmod_file_mode_volume/chmod_test.sh b/tests/cases/060_volume/110_chmod_file_mode_volume/chmod_test.sh new file mode 100644 index 0000000..011e945 --- /dev/null +++ b/tests/cases/060_volume/110_chmod_file_mode_volume/chmod_test.sh @@ -0,0 +1,85 @@ +#!/bin/sh + +set -e +set -x + +# This script tests a number of combination of chmod of files. It does +# *not* error on the first error, instead all tests are run. + +FILE=$1 +CONTENT="foo" +ret=0 + +echo +TEST="chmod file r/w user only" +rm -rf "$FILE" +echo "CONTENT" > "$FILE" +chmod 0600 "$FILE" +RESULT=$(stat -c %a "$FILE") +EXPECTED="600" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +echo +TEST="chmod file r/x user only" +rm -rf "$FILE" +echo "CONTENT" > "$FILE" +chmod 0500 "$FILE" +RESULT=$(stat -c %a "$FILE") +EXPECTED="500" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +echo +TEST="chmod file r/w/x user r/x for group" +rm -rf "$FILE" +echo "CONTENT" > "$FILE" +chmod 0750 "$FILE" +RESULT=$(stat -c %a "$FILE") +EXPECTED="750" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +echo +TEST="chmod file r/w/x user r/x for group/other" +rm -rf "$FILE" +echo "CONTENT" > "$FILE" +chmod 0755 "$FILE" +RESULT=$(stat -c %a "$FILE") +EXPECTED="755" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +echo +TEST="chmod file setuid+r/w/x user r/x group/other" +rm -rf "$FILE" +echo "CONTENT" > "$FILE" +chmod 4755 "$FILE" +RESULT=$(stat -c %a "$FILE") +EXPECTED="4755" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +echo +TEST="chmod file setgid+r/w/x user r/x group/other" +rm -rf "$FILE" +echo "CONTENT" > "$FILE" +chmod 2755 "$FILE" +RESULT=$(stat -c %a "$FILE") +EXPECTED="2755" +if [ "$EXPECTED" != "$RESULT" ]; then + echo "$TEST: expected $EXPECTED got $RESULT" + ret=1 +fi + +exit $ret diff --git a/tests/cases/060_volume/110_chmod_file_mode_volume/test.ps1 b/tests/cases/060_volume/110_chmod_file_mode_volume/test.ps1 new file mode 100644 index 0000000..45de452 --- /dev/null +++ b/tests/cases/060_volume/110_chmod_file_mode_volume/test.ps1 @@ -0,0 +1,29 @@ +# SUMMARY: Check changes to a file mode (chmod) on a volume mount in a container +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$imageName = "chmod-container" +$fileName = "foobar" + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} + +docker build --platform linux -t $imageName . +if ($lastexitcode -ne 0) { + exit 1 +} + +$p = [string]$pwd.Path +docker run --rm -v $p`:/test $imageName /chmod_test.sh /test/$fileName +if ($lastexitcode -ne 0) { + if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force + } + exit 1 +} + +Remove-Item -Path $fileName -Force +exit 0 From 0fe21de8d15db147a89e13afd1d9a4d652b630c8 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Tue, 27 Feb 2018 16:02:23 +0000 Subject: [PATCH 17/19] tests: Check file access a volume mount in a container Signed-off-by: Rolf Neugebauer --- .../120_chmod_file_access_volume/Dockerfile | 3 + .../chmod_test.sh | 126 ++++++++++++++++++ .../120_chmod_file_access_volume/test.ps1 | 29 ++++ 3 files changed, 158 insertions(+) create mode 100644 tests/cases/060_volume/120_chmod_file_access_volume/Dockerfile create mode 100644 tests/cases/060_volume/120_chmod_file_access_volume/chmod_test.sh create mode 100644 tests/cases/060_volume/120_chmod_file_access_volume/test.ps1 diff --git a/tests/cases/060_volume/120_chmod_file_access_volume/Dockerfile b/tests/cases/060_volume/120_chmod_file_access_volume/Dockerfile new file mode 100644 index 0000000..44f8720 --- /dev/null +++ b/tests/cases/060_volume/120_chmod_file_access_volume/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine:3.7 +COPY chmod_test.sh / +RUN chmod ugo+x chmod_test.sh diff --git a/tests/cases/060_volume/120_chmod_file_access_volume/chmod_test.sh b/tests/cases/060_volume/120_chmod_file_access_volume/chmod_test.sh new file mode 100644 index 0000000..024fcc4 --- /dev/null +++ b/tests/cases/060_volume/120_chmod_file_access_volume/chmod_test.sh @@ -0,0 +1,126 @@ +#!/bin/sh + +set -e +set -x + +FILE=$1 +CONTENT="foo" +CONTENT2="foo2" +ret=0 + +adduser -D testuser +adduser -D testuser2 +adduser testuser daemon + +rm -rf "$FILE" +echo "$CONTENT" > "$FILE" +chmod 0600 "$FILE" +chown root:daemon "$FILE" + +echo +TEST="file r/w root user only. Read access as root" +RESULT=$(cat "$FILE") +if [ "$CONTENT" != "$RESULT" ]; then + echo "$TEST: expected $CONTENT got $RESULT" + ret=1 +fi + +echo +TEST="file r/w root user only. Write access as root" +echo "$CONTENT2" > "$FILE" +RESULT=$(cat "$FILE") +if [ "$CONTENT2" != "$RESULT" ]; then + echo "$TEST: expected $CONTENT2 got $RESULT" + ret=1 +fi + +echo +TEST="file r/w root user only. Read access as testuser" +set +e +su -c "cat $FILE" testuser +res=$? +set -e +if [ "$res" != "1" ]; then + echo "$TEST: expected it to fail" + ret=1 +fi + +echo +TEST="file r/w root user only. Write access as testuser" +set +e +su -c "echo $CONTENT > $FILE" testuser +res=$? +set -e +if [ "$res" != "1" ]; then + echo "$TEST: expected it to fail" + ret=1 +fi + +echo +TEST="file r/w root user only. Read access as testuser2" +set +e +su -c "cat $FILE" testuser2 +res=$? +set -e +if [ "$res" != "1" ]; then + echo "$TEST: expected it to fail" + ret=1 +fi + +echo +TEST="file r/w root user only. Write access as testuser2" +set +e +su -c "echo $CONTENT > $FILE" testuser2 +res=$? +set -e +if [ "$res" != "1" ]; then + echo "$TEST: expected it to fail" + ret=1 +fi + +# change to allow group access +rm -rf "$FILE" +echo "$CONTENT" > "$FILE" +chmod 0660 "$FILE" +chown root:daemon "$FILE" + +echo +TEST="file r/w user/group only. Read access as testuser" +RESULT=$(su -c "cat $FILE" testuser) +if [ "$CONTENT" != "$RESULT" ]; then + echo "$TEST: expected $CONTENT got $RESULT" + ret=1 +fi + +echo +TEST="file r/w user/group only. Write access as testuser" +su -c "echo $CONTENT2 > $FILE" testuser +RESULT=$(cat "$FILE") +if [ "$CONTENT2" != "$RESULT" ]; then + echo "$TEST: expected $CONTENT2 got $RESULT" + ret=1 +fi + +echo +TEST="file r/w root user only. Read access as testuser2" +set +e +su -c "cat $FILE" testuser2 +res=$? +set -e +if [ "$res" != "1" ]; then + echo "$TEST: expected it to fail" + ret=1 +fi + +echo +TEST="file r/w root user only. Write access as testuser2" +set +e +su -c "echo $CONTENT > $FILE" testuser2 +res=$? +set -e +if [ "$res" != "1" ]; then + echo "$TEST: expected it to fail" + ret=1 +fi + +exit $ret diff --git a/tests/cases/060_volume/120_chmod_file_access_volume/test.ps1 b/tests/cases/060_volume/120_chmod_file_access_volume/test.ps1 new file mode 100644 index 0000000..881e8ba --- /dev/null +++ b/tests/cases/060_volume/120_chmod_file_access_volume/test.ps1 @@ -0,0 +1,29 @@ +# SUMMARY: Check file access a volume mount in a container +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$imageName = "chmod-access-container" +$fileName = "foobar" + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} + +docker build --platform linux -t $imageName . +if ($lastexitcode -ne 0) { + exit 1 +} + +$p = [string]$pwd.Path +docker run --rm -v $p`:/test $imageName /chmod_test.sh /test/$fileName +if ($lastexitcode -ne 0) { + if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force + } + exit 1 +} + +Remove-Item -Path $fileName -Force +exit 0 From e5c25d42a9d28bb973d23489351d8d952731a151 Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Tue, 27 Feb 2018 16:36:41 +0000 Subject: [PATCH 18/19] tests: Verify that volume mounts implement statfs Signed-off-by: Rolf Neugebauer --- tests/cases/060_volume/200_statfs/Dockerfile | 3 + .../060_volume/200_statfs/statfs_test.sh | 57 +++++++++++++++++++ tests/cases/060_volume/200_statfs/test.ps1 | 20 +++++++ 3 files changed, 80 insertions(+) create mode 100644 tests/cases/060_volume/200_statfs/Dockerfile create mode 100644 tests/cases/060_volume/200_statfs/statfs_test.sh create mode 100755 tests/cases/060_volume/200_statfs/test.ps1 diff --git a/tests/cases/060_volume/200_statfs/Dockerfile b/tests/cases/060_volume/200_statfs/Dockerfile new file mode 100644 index 0000000..66d7913 --- /dev/null +++ b/tests/cases/060_volume/200_statfs/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine:3.7 +COPY statfs_test.sh / +RUN chmod ugo+x statfs_test.sh diff --git a/tests/cases/060_volume/200_statfs/statfs_test.sh b/tests/cases/060_volume/200_statfs/statfs_test.sh new file mode 100644 index 0000000..177266f --- /dev/null +++ b/tests/cases/060_volume/200_statfs/statfs_test.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +set -e +set -x + +DIR=$1 +ret=0 + +R=$(stat -f -c %t "$DIR") +if [ "$R" == "0" ]; then + echo "Volume does not support reporting type" + ret=1 +fi + +R=$(stat -f -c %s "$DIR") +if [ "$R" == "0" ]; then + echo "Volume does not support reporting blocksize" + ret=1 +fi + +R=$(stat -f -c %a "$DIR") +if [ "$R" == "0" ]; then + echo "Volume does not support reporting blocksize" + ret=1 +fi + +R=$(stat -f -c %b "$DIR") +if [ "$R" == "0" ]; then + echo "Volume does not support reporting total data blocks" + ret=1 +fi + +R=$(stat -f -c %c "$DIR") +if [ "$R" == "0" ]; then + echo "Volume does not support reporting total file nodes" + ret=1 +fi + +R=$(stat -f -c %d "$DIR") +if [ "$R" == "0" ]; then + echo "Volume does not support reporting free file nodes" + ret=1 +fi + +R=$(stat -f -c %f "$DIR") +if [ "$R" == "0" ]; then + echo "Volume does not support reporting free blocks" + ret=1 +fi + +R=$(stat -f -c %l "$DIR") +if [ "$R" == "0" ]; then + echo "Volume does not support reporting maximum length of filenames" + ret=1 +fi + +return $ret diff --git a/tests/cases/060_volume/200_statfs/test.ps1 b/tests/cases/060_volume/200_statfs/test.ps1 new file mode 100755 index 0000000..11075f3 --- /dev/null +++ b/tests/cases/060_volume/200_statfs/test.ps1 @@ -0,0 +1,20 @@ +# SUMMARY: Verify that volume mounts implement statfs +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$imageName = "statfs-container" + +docker build --platform linux -t $imageName . +if ($lastexitcode -ne 0) { + exit 1 +} + +$p = [string]$pwd.Path +docker run --rm -v $p`:/test $imageName /statfs_test.sh /test +if ($lastexitcode -ne 0) { + exit 1 +} + +exit 0 From e5c69ba9c1ea5d17be832bd647440eed230d396f Mon Sep 17 00:00:00 2001 From: Rolf Neugebauer Date: Tue, 27 Feb 2018 18:06:13 +0000 Subject: [PATCH 19/19] tests: Check that access times get propagated Signed-off-by: Rolf Neugebauer --- .../cases/060_volume/150_utime/check_time.sh | 12 +++++ tests/cases/060_volume/150_utime/foobar | 0 tests/cases/060_volume/150_utime/test.ps1 | 44 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 tests/cases/060_volume/150_utime/check_time.sh create mode 100644 tests/cases/060_volume/150_utime/foobar create mode 100644 tests/cases/060_volume/150_utime/test.ps1 diff --git a/tests/cases/060_volume/150_utime/check_time.sh b/tests/cases/060_volume/150_utime/check_time.sh new file mode 100644 index 0000000..8452c6c --- /dev/null +++ b/tests/cases/060_volume/150_utime/check_time.sh @@ -0,0 +1,12 @@ +#! /bin/sh + +set -e +set -x + +FILE=$1 + +ts=$(stat -c %Y "$FILE") +if [ "$ts" == "0" ]; then + exit 0 +fi +exit 1 diff --git a/tests/cases/060_volume/150_utime/foobar b/tests/cases/060_volume/150_utime/foobar new file mode 100644 index 0000000..e69de29 diff --git a/tests/cases/060_volume/150_utime/test.ps1 b/tests/cases/060_volume/150_utime/test.ps1 new file mode 100644 index 0000000..facff0d --- /dev/null +++ b/tests/cases/060_volume/150_utime/test.ps1 @@ -0,0 +1,44 @@ +# SUMMARY: Check file access time +# LABELS: +# REPEAT: + +Set-PSDebug -Trace 2 + +$fileName = "foobar" + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} + +# +# Create a file in a container and check on the host +# +$p = [string]$pwd.Path +docker run --rm -v $p`:/test -e TZ=UTC alpine touch -t 197002010000.00 /test/$fileName + +# check timestamp +$expected = Get-Date -Date "1970-02-01 00:00:00Z" +$result = [datetime](Get-ItemProperty -Path $fileName -Name LastWriteTime).lastwritetime +if ($expected -ne $result) { + exit 1 +} + +if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force +} + +# +# Create a file on the host and check in a container +# +$ts = Get-Date -Date "1970-01-01 00:00:00Z" +New-Item -ItemType File -Path $fileName +Set-ItemProperty -Path $fileName -Name LastWriteTime -Value $ts +# XXX This relies on the numeric time stamp being 0 +docker run --rm -v $p`:/test -e TZ=UTC alpine sh /test/check_time.sh /test/$fileName +if ($lastexitcode -ne 0) { + if (Test-Path $fileName) { + Remove-Item -Path $fileName -Force + } + exit 1 +} +exit 0