From ebf907fb453dcd26ed930e093a9f87e2bc34dfe8 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Thu, 18 Mar 2021 10:49:37 +0100 Subject: [PATCH] Add owner permissions tests --- tests/fixtures/owners/delta/build.yaml | 8 ++ tests/fixtures/owners/delta/definition.yaml | 3 + tests/fixtures/owners/unpack/build.yaml | 13 +++ tests/fixtures/owners/unpack/definition.yaml | 3 + tests/integration/26_owners.sh | 90 ++++++++++++++++++++ 5 files changed, 117 insertions(+) create mode 100644 tests/fixtures/owners/delta/build.yaml create mode 100644 tests/fixtures/owners/delta/definition.yaml create mode 100644 tests/fixtures/owners/unpack/build.yaml create mode 100644 tests/fixtures/owners/unpack/definition.yaml create mode 100755 tests/integration/26_owners.sh diff --git a/tests/fixtures/owners/delta/build.yaml b/tests/fixtures/owners/delta/build.yaml new file mode 100644 index 00000000..e21a412d --- /dev/null +++ b/tests/fixtures/owners/delta/build.yaml @@ -0,0 +1,8 @@ +image: "busybox" + +steps: +- adduser foo -D +- addgroup bar +- touch /foo +- chown foo:bar /foo +- chmod 500 /foo diff --git a/tests/fixtures/owners/delta/definition.yaml b/tests/fixtures/owners/delta/definition.yaml new file mode 100644 index 00000000..3c56a991 --- /dev/null +++ b/tests/fixtures/owners/delta/definition.yaml @@ -0,0 +1,3 @@ +category: "test" +name: "delta" +version: "1.0" diff --git a/tests/fixtures/owners/unpack/build.yaml b/tests/fixtures/owners/unpack/build.yaml new file mode 100644 index 00000000..913b99e6 --- /dev/null +++ b/tests/fixtures/owners/unpack/build.yaml @@ -0,0 +1,13 @@ +image: "busybox" + +steps: +- adduser baz -D +- addgroup ba +- touch /bar +- chown baz:ba /bar +- chmod 600 /bar +- ls -liah /bar +unpack: true + +includes: +- bar diff --git a/tests/fixtures/owners/unpack/definition.yaml b/tests/fixtures/owners/unpack/definition.yaml new file mode 100644 index 00000000..aca292e4 --- /dev/null +++ b/tests/fixtures/owners/unpack/definition.yaml @@ -0,0 +1,3 @@ +category: "test" +name: "unpack" +version: "1.0" diff --git a/tests/integration/26_owners.sh b/tests/integration/26_owners.sh new file mode 100755 index 00000000..06903c40 --- /dev/null +++ b/tests/integration/26_owners.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +export LUET_NOLOCK=true + +oneTimeSetUp() { +export tmpdir="$(mktemp -d)" +} + +oneTimeTearDown() { + rm -rf "$tmpdir" +} + +testBuild() { + [ "$LUET_BACKEND" == "img" ] && startSkipping + mkdir $tmpdir/testbuild + luet build --tree "$ROOT_DIR/tests/fixtures/owners" --destination $tmpdir/testbuild --compression gzip test/unpack test/delta + buildst=$? + assertEquals 'builds successfully' "$buildst" "0" + assertTrue 'create package unpack' "[ -e '$tmpdir/testbuild/unpack-test-1.0.package.tar.gz' ]" + assertTrue 'create package delta' "[ -e '$tmpdir/testbuild/delta-test-1.0.package.tar.gz' ]" +} + +testRepo() { + [ "$LUET_BACKEND" == "img" ] && startSkipping + assertTrue 'no repository' "[ ! -e '$tmpdir/testbuild/repository.yaml' ]" + luet create-repo --tree "$ROOT_DIR/tests/fixtures/owners" \ + --output $tmpdir/testbuild \ + --packages $tmpdir/testbuild \ + --name "test" \ + --descr "Test Repo" \ + --urls $tmpdir/testrootfs \ + --type disk > /dev/null + + createst=$? + assertEquals 'create repo successfully' "$createst" "0" + assertTrue 'create repository' "[ -e '$tmpdir/testbuild/repository.yaml' ]" +} + +testConfig() { + [ "$LUET_BACKEND" == "img" ] && startSkipping + mkdir $tmpdir/testrootfs + cat < $tmpdir/luet.yaml +general: + debug: true +system: + rootfs: $tmpdir/testrootfs + database_path: "/" + database_engine: "boltdb" +config_from_host: true +repositories: + - name: "main" + type: "disk" + enable: true + urls: + - "$tmpdir/testbuild" +EOF + luet config --config $tmpdir/luet.yaml + res=$? + assertEquals 'config test successfully' "$res" "0" +} + +testInstall() { + [ "$LUET_BACKEND" == "img" ] && startSkipping + luet install -y --config $tmpdir/luet.yaml test/unpack test/delta + installst=$? + assertEquals 'install test successfully' "$installst" "0" + fileUID=$(stat -c "%u" $tmpdir/testrootfs/foo) + fileGID=$(stat -c "%g" $tmpdir/testrootfs/foo) + filePerms=$(stat -c "%a" $tmpdir/testrootfs/foo) + assertEquals 'UID on /foo matches' "1000" "$fileUID" + assertEquals 'GID on /foo matches' "1001" "$fileGID" + assertEquals 'bits on /foo matches' "500" "$filePerms" + + fileUID=$(stat -c "%u" $tmpdir/testrootfs/bar) + fileGID=$(stat -c "%g" $tmpdir/testrootfs/bar) + filePerms=$(stat -c "%a" $tmpdir/testrootfs/bar) + assertEquals 'UID on /bar matches' "1000" "$fileUID" + assertEquals 'GID on /bar matches' "1001" "$fileGID" + assertEquals 'bits on /bar matches' "600" "$filePerms" +} + +testCleanup() { + [ "$LUET_BACKEND" == "img" ] && startSkipping + luet cleanup --config $tmpdir/luet.yaml + installst=$? + assertEquals 'cleanup test successfully' "$installst" "0" +} + +# Load shUnit2. +. "$ROOT_DIR/tests/integration/shunit2"/shunit2