Skip to content

Commit

Permalink
Prevent Address in use error
Browse files Browse the repository at this point in the history
Use dynamic listening port (assigned from system), detect it from process
by calling lsof.
  • Loading branch information
oldium committed May 8, 2024
1 parent d579f02 commit a7de265
Show file tree
Hide file tree
Showing 24 changed files with 121 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/install-dependencies
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -ex

COMMON="meson curl git make file bzip2 jose tang cryptsetup keyutils jq socat ${CC}"
COMMON="meson curl git make file bzip2 jose tang cryptsetup keyutils jq socat lsof ${CC}"

case "${DISTRO}" in
debian:*|ubuntu:*)
Expand Down Expand Up @@ -33,7 +33,7 @@ debian:*|ubuntu:*)
printf 'max_parallel_downloads=10\nfastestmirror=1\n' >> /etc/dnf/dnf.conf
dnf -y clean all
dnf -y --setopt=deltarpm=0 update
dnf -y install dnf-utils jq socat cryptsetup keyutils cracklib-dicts
dnf -y install dnf-utils jq socat cryptsetup keyutils cracklib-dicts lsof
dnf -y builddep clevis
;;

Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/assume-yes
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ trap 'on_exit' ERR

TMP="$(mktemp -d)"

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
cfg=$(printf '{"url":"%s"}' "$url")
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/assume-yes-luks2
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ trap 'on_exit' ERR

TMP="$(mktemp -d)"

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
cfg=$(printf '{"url":"%s"}' "$url")
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/bind-binary-keyfile-luks1
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ trap 'on_exit' EXIT

TMP="$(mktemp -d)"

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
ADV="${TMP}/adv.jws"
Expand Down
5 changes: 3 additions & 2 deletions src/luks/tests/bind-luks1-avoid-luksmeta-corruption
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ DEV="${TMP}/luks1-device"
new_device "luks1" "${DEV}"

# TANG server specifics
port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"

# Initial binding to ensure luksmeta gets corrupted
Expand Down
8 changes: 4 additions & 4 deletions src/luks/tests/edit-tang-luks1
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ trap 'on_exit' ERR

TMP="$(mktemp -d)"

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"

Expand All @@ -64,9 +64,9 @@ fi

# Now let's have another tang instance running and change the config to use
# the new one.
port2=$(tang_new_random_port)
TMP2="$(mktemp -d)"
tang_run "${TMP2}" "${port2}"
tang_run "${TMP2}"
port2=$(tang_get_port "${TMP2}")
new_url="http://localhost:${port2}"
new_cfg=$(printf '{"url":"%s"}' "${new_url}")

Expand Down
8 changes: 4 additions & 4 deletions src/luks/tests/edit-tang-luks2
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ trap 'on_exit' ERR

TMP="$(mktemp -d)"

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"

Expand All @@ -64,9 +64,9 @@ fi

# Now let's have another tang instance running and change the config to use
# the new one.
port2=$(tang_new_random_port)
TMP2="$(mktemp -d)"
tang_run "${TMP2}" "${port2}"
tang_run "${TMP2}"
port2=$(tang_get_port "${TMP2}")
new_url="http://localhost:${port2}"
new_cfg=$(printf '{"url":"%s"}' "${new_url}")

Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/pass-tang-luks1
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ trap 'on_exit' EXIT

TMP=$(mktemp -d)

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
adv="${TMP}/adv"
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/pass-tang-luks2
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ trap 'on_exit' EXIT

TMP=$(mktemp -d)

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
adv="${TMP}/adv"
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/regen-inplace-luks1
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ trap 'on_exit' EXIT

TMP=$(mktemp -d)

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
adv="${TMP}/adv"
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/regen-inplace-luks2
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ trap 'on_exit' EXIT

TMP=$(mktemp -d)

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
adv="${TMP}/adv"
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/regen-not-inplace-luks1
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ trap 'on_exit' EXIT

export TMP=$(mktemp -d)

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
adv="${TMP}/adv"
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/regen-not-inplace-luks2
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ trap 'on_exit' EXIT

export TMP=$(mktemp -d)

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
adv="${TMP}/adv"
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/report-sss-luks1
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ trap 'on_exit' EXIT

TMP=$(mktemp -d)

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
adv="${TMP}/adv"
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/report-sss-luks2
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ trap 'on_exit' EXIT

TMP=$(mktemp -d)

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
adv="${TMP}/adv"
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/report-tang-luks1
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ trap 'on_exit' EXIT

TMP=$(mktemp -d)

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
adv="${TMP}/adv"
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/report-tang-luks2
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ trap 'on_exit' EXIT

TMP=$(mktemp -d)

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
adv="${TMP}/adv"
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/unlock-arbitrary-parameter
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ trap 'on_exit' ERR

TMP="$(mktemp -d)"

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
adv="${TMP}/adv"
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/unlock-tang-luks1
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ trap 'on_exit' ERR

TMP="$(mktemp -d)"

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
adv="${TMP}/adv"
Expand Down
4 changes: 2 additions & 2 deletions src/luks/tests/unlock-tang-luks2
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ trap 'on_exit' ERR

TMP="$(mktemp -d)"

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
adv="${TMP}/adv"
Expand Down
4 changes: 2 additions & 2 deletions src/pins/tang/tests/default-thp-alg
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ trap 'on_exit' EXIT

TMP="$(mktemp -d)"

port=$(tang_new_random_port)
tang_run "${TMP}" "${port}"
tang_run "${TMP}"
port=$(tang_get_port "${TMP}")

url="http://localhost:${port}"
data="just a sample text"
Expand Down
5 changes: 2 additions & 3 deletions src/pins/tang/tests/pin-tang
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ trap 'on_exit' EXIT

TMP="$(mktemp -d)"

port=$(tang_new_random_port)

tang_run "${TMP}" "${port}" sig exc
tang_run "${TMP}" sig exc
port=$(tang_get_port "${TMP}")

thp="$(jose jwk thp -i "$TMP/db/sig.jwk")"
adv="${TMP}/adv.jws"
Expand Down
Loading

0 comments on commit a7de265

Please sign in to comment.