github.com/containers/podman/v5@v5.1.0-rc1/test/system/950-preexec-hooks.bats (about)

     1  #!/usr/bin/env bats
     2  #
     3  # Tests for podman preexec hooks
     4  #
     5  
     6  load helpers
     7  load helpers.network
     8  
     9  # The existence of this file allows preexec hooks to run.
    10  preexec_hook_ok_file=/etc/containers/podman_preexec_hooks.txt
    11  
    12  function setup() {
    13      basic_setup
    14  }
    15  
    16  function teardown() {
    17      if [[ -n "$preexec_hook_ok_file" ]]; then
    18          sudo -n rm -f $preexec_hook_ok_file || true
    19      fi
    20  
    21      basic_teardown
    22  }
    23  
    24  @test "podman preexec hook" {
    25      # This file does not exist on any CI system nor any developer system
    26      # nor actually anywhere in the universe except a small small set of
    27      # places with very specific requirements. If we find this file on
    28      # our test system, it could be a leftover from prior testing, or
    29      # basically just something very weird. So, fail loudly if we see it.
    30      # No podman developer ever wants this file to exist.
    31      if [[ -e $preexec_hook_ok_file ]]; then
    32          # Unset the variable, so we don't delete it in teardown
    33          msg="File already exists (it should not): $preexec_hook_ok_file"
    34          preexec_hook_ok_file=
    35  
    36          die "$msg"
    37      fi
    38  
    39      # Good. File does not exist. Now see if we can TEMPORARILY create it.
    40      sudo -n touch $preexec_hook_ok_file || skip "test requires sudo"
    41  
    42      preexec_hook_dir=$PODMAN_TMPDIR/auth
    43      mkdir -p $preexec_hook_dir
    44      preexec_hook_script=$preexec_hook_dir/pull_check.sh
    45  
    46      cat > $preexec_hook_script <<EOF
    47  #!/bin/sh
    48  if echo \$@ | grep "pull foobar"; then
    49      exit 42
    50  fi
    51  exit 43
    52  EOF
    53      chmod +x $preexec_hook_script
    54  
    55      PODMAN_PREEXEC_HOOKS_DIR=$preexec_hook_dir run_podman 42 pull foobar
    56      PODMAN_PREEXEC_HOOKS_DIR=$preexec_hook_dir run_podman 43 version
    57  
    58      sudo -n rm -f $preexec_hook_ok_file || true
    59  
    60      # no hooks-ok file, everything should now work again (HOOKS_DIR is ignored)
    61      PODMAN_PREEXEC_HOOKS_DIR=$preexec_hook_dir run_podman version
    62  }