Austin Schuh | 0a0a827 | 2021-12-08 13:19:32 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -euo pipefail |
| 4 | |
| 5 | result=0 |
| 6 | verify() { |
| 7 | local thisresult=0 |
| 8 | local family |
| 9 | local address |
| 10 | family=$(echo "$output" | grep -Po '\] Family [^ ]+' | cut -f3 -d' ') |
| 11 | address=$(echo "$output" | grep -Po '\] Address [^ ]+' | cut -f3 -d' ') |
| 12 | if [[ "${family}" != "${1}" ]]; then |
| 13 | echo "Expected family ${1}, got ${family}" >&2 |
| 14 | thisresult=1 |
| 15 | result=1 |
| 16 | fi |
| 17 | if [[ ! "${address}" =~ ${2} ]]; then |
| 18 | echo "Expected address ${2}, got ${address}" >&2 |
| 19 | thisresult=1 |
| 20 | result=1 |
| 21 | fi |
| 22 | return $thisresult |
| 23 | } |
| 24 | |
| 25 | run_test() { |
| 26 | local has_ipv6 |
| 27 | has_ipv6="${1}" |
| 28 | export has_ipv6 |
| 29 | shift |
| 30 | LD_PRELOAD="${SHIM}" "${BINARY}" --host=localhost "$@" 2>&1 |
| 31 | } |
| 32 | |
| 33 | BINARY="$1" |
| 34 | SHIM="$2" |
| 35 | |
| 36 | output=$(run_test y) |
| 37 | verify AF_INET6 "(::ffff:127.0.0.1|::)" || echo "IPv6 allowed with no arguments failed" >&2 |
| 38 | |
| 39 | output=$(run_test n) |
| 40 | verify AF_INET "127\\.0\\.0\\.1" || echo "IPv6 disallowed with no arguments failed" >&2 |
| 41 | |
| 42 | output=$(run_test y --disable_ipv6) |
| 43 | verify AF_INET "127\\.0\\.0\\.1" || echo "IPv6 allowed with --disable_ipv6 failed" >&2 |
| 44 | |
| 45 | exit $result |