File: 950-preexec-hooks.bats

package info (click to toggle)
podman 5.4.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 23,124 kB
  • sloc: sh: 6,119; perl: 2,710; python: 2,258; ansic: 1,556; makefile: 1,022; xml: 121; ruby: 42; awk: 12; csh: 8
file content (62 lines) | stat: -rw-r--r-- 1,846 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bats
#
# Tests for podman preexec hooks
#

load helpers
load helpers.network

# The existence of this file allows preexec hooks to run.
preexec_hook_ok_file=/etc/containers/podman_preexec_hooks.txt

function setup() {
    basic_setup
}

function teardown() {
    if [[ -n "$preexec_hook_ok_file" ]]; then
        sudo -n rm -f $preexec_hook_ok_file || true
    fi

    basic_teardown
}

@test "podman preexec hook" {
    # This file does not exist on any CI system nor any developer system
    # nor actually anywhere in the universe except a small small set of
    # places with very specific requirements. If we find this file on
    # our test system, it could be a leftover from prior testing, or
    # basically just something very weird. So, fail loudly if we see it.
    # No podman developer ever wants this file to exist.
    if [[ -e $preexec_hook_ok_file ]]; then
        # Unset the variable, so we don't delete it in teardown
        msg="File already exists (it should not): $preexec_hook_ok_file"
        preexec_hook_ok_file=

        die "$msg"
    fi

    # Good. File does not exist. Now see if we can TEMPORARILY create it.
    sudo -n touch $preexec_hook_ok_file || skip "test requires sudo"

    preexec_hook_dir=$PODMAN_TMPDIR/auth
    mkdir -p $preexec_hook_dir
    preexec_hook_script=$preexec_hook_dir/pull_check.sh

    cat > $preexec_hook_script <<EOF
#!/bin/sh
if echo \$@ | grep "pull foobar"; then
    exit 42
fi
exit 43
EOF
    chmod +x $preexec_hook_script

    PODMAN_PREEXEC_HOOKS_DIR=$preexec_hook_dir run_podman 42 pull foobar
    PODMAN_PREEXEC_HOOKS_DIR=$preexec_hook_dir run_podman 43 version

    sudo -n rm -f $preexec_hook_ok_file || true

    # no hooks-ok file, everything should now work again (HOOKS_DIR is ignored)
    PODMAN_PREEXEC_HOOKS_DIR=$preexec_hook_dir run_podman version
}