123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #!/bin/sh -ex
- # vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
- #
- # Copyright (c) 2016 Red Hat, Inc.
- # Author: Nathaniel McCallum <npmccallum@redhat.com>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- fetch() {
- curl -sfg "http://127.0.0.1:${PORT}${1}"
- }
- ver() {
- jose jws ver -i- -k "${1}"
- }
- random_port() {
- if [ -n "${TANG_BSD}" ]; then
- jot -r 1 1024 65536
- else
- shuf -i 1024-65536 -n 1
- fi
- }
- check_if_port_listening() {
- if [ -n "${TANG_BSD}" ]; then
- sockstat -l|grep "[\:\.]${1}" >/dev/null 2>&1
- else
- ss -anl|grep "[\:\.]${1}"|grep LISTEN >/dev/null 2>&1
- fi
- }
- wait_for_port()
- {
- local port="${1}"
- sleep 1
- local i=0
- while [ "${i}" -lt 90 ]; do
- check_if_port_listening "${port}" && return 0
- i=$((i + 1))
- echo "try ${i}: waiting for port" >&2
- sleep 1
- done
- return 1
- }
- start_server() {
- "${SOCAT}" TCP-LISTEN:"${1}",bind=127.0.0.1,fork SYSTEM:"${VALGRIND} tangd ${TMP}/db" &
- }
- start_standalone_server() {
- ${VALGRIND} tangd -p ${1} -l ${TMP}/db &
- }
- on_exit() {
- if [ "${PID}" ]; then
- kill "${PID}" || true
- wait "${PID}" || true
- fi
- [ -d "${TMP}" ] && rm -rf "${TMP}"
- }
- validate() {
- if ! _jwks="$(jose fmt --json="${1}" -Og payload -SyOg keys \
- -AUo- 2>/dev/null)"; then
- echo "Advertisement is malformed" >&2
- exit 1
- fi
- _ver="$(printf '%s' "${_jwks}" | jose jwk use -i- -r -u verify -o-)"
- if ! printf '%s' "${_ver}" | jose jws ver -i "${1}" -k- -a; then
- echo "Advertisement is missing signatures" >&2
- exit 1
- fi
- }
- validate_sig() {
- jose fmt --json "${1}" --output=- | jose jwk use --input=- --required \
- --use verify 2>/dev/null
- }
- validate_exc() {
- jose fmt --json "${1}" --output=- | jose jwk use --input=- --required \
- --use deriveKey 2>/dev/null
- }
- sanity_check() {
- # Skip test if socat is not available.
- [ -n "${SOCAT}" ] || exit 77
- }
- die() {
- echo "${1}" >&2
- exit 1
- }
- valid_key_perm() {
- if [ -n "${TANG_BSD}" ]; then
- _perm="$(stat -f %Lp "${1}")"
- else
- _perm="$(stat -c %a "${1}")"
- fi
- [ "${_perm}" = "440" ]
- }
- expected_fail () {
- echo "Test was expected to fail" >&2
- exit 1
- }
|