summary: smoke test for the tinyproxy profile
prepare: |
    # start a simple local web server which we will use later for functional
    # tests
    python3 -m http.server 1>/dev/null 2>&1 &
    echo $! > .http-server.pid

restore: |
    kill $(cat .http-server.pid)
    rm -f .http-server.pid

execute: |
    # restart tinyproxy service as it may already be running
    systemctl restart tinyproxy

    # wait for it to be running
    sleep 1

    # check is running
    systemctl is-active tinyproxy

    # check tinyproxy system service is confined
    cat /proc/$(pidof tinyproxy)/attr/apparmor/current | MATCH 'tinyproxy \(enforce\)'

    # also check the profile is attached based on the program path since in the
    # previous test it could possibly being done by systemd instead
    "$SPREAD_PATH"/tests/bin/actual-profile-of tinyproxy | MATCH 'tinyproxy \(enforce\)'

    # interact with local web server via tinyproxy to make sure it works and we
    # get the expected response headers
    env http_proxy=http://localhost:8888 curl -s -i http://localhost:8000/task.yaml | MATCH '^Via: .*tinyproxy'

    # also check we can get the statistics page
    env http_proxy=http://localhost:8888 curl -s http://tinyproxy.stats | MATCH 'tinyproxy .* statistics'
