mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-12-04 14:46:30 -05:00
First try at tests with autotools stuff
This commit is contained in:
parent
fa86f2de73
commit
f9c50e841d
7
.gitignore
vendored
7
.gitignore
vendored
@ -27,3 +27,10 @@ missing
|
||||
mkinstalldirs
|
||||
*.tar.gz
|
||||
config.h.in~
|
||||
|
||||
# Ignore test output files
|
||||
/tests/*.log
|
||||
/tests/*.trs
|
||||
|
||||
# Ignore auxiliary files
|
||||
/tap-driver.sh
|
||||
|
@ -3,7 +3,7 @@
|
||||
AUTOMAKE_OPTIONS = foreign dist-zip
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
SUBDIRS = src conf doc web admin win32 examples
|
||||
SUBDIRS = src conf doc web admin win32 examples tests
|
||||
|
||||
EXTRA_DIST = README.md HACKING m4/acx_pthread.m4 m4/ogg.m4 \
|
||||
m4/theora.m4 m4/vorbis.m4 m4/speex.m4 \
|
||||
|
@ -3,6 +3,7 @@ AC_INIT([Icecast], [2.4.99.1], [icecast@xiph.org])
|
||||
AC_PREREQ([2.54])
|
||||
AC_CONFIG_SRCDIR([src/main.c])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
AC_REQUIRE_AUX_FILE([tap-driver.sh])
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
|
||||
AM_INIT_AUTOMAKE
|
||||
@ -10,6 +11,7 @@ AM_CONFIG_HEADER([config.h])
|
||||
AM_MAINTAINER_MODE
|
||||
|
||||
AC_PROG_CC
|
||||
AC_PROG_AWK
|
||||
AC_CANONICAL_HOST
|
||||
AC_PROG_LIBTOOL
|
||||
AC_SYS_LARGEFILE
|
||||
@ -165,4 +167,4 @@ src/common/net/Makefile src/common/timing/Makefile doc/Makefile doc/img/Makefile
|
||||
doc/assets/Makefile doc/assets/css/Makefile doc/assets/font/Makefile
|
||||
doc/assets/img/Makefile web/Makefile web/assets/Makefile web/assets/css/Makefile
|
||||
web/assets/font/Makefile admin/Makefile admin/includes/Makefile win32/Makefile
|
||||
examples/Makefile])
|
||||
examples/Makefile tests/Makefile])
|
||||
|
13
tests/Makefile.am
Normal file
13
tests/Makefile.am
Normal file
@ -0,0 +1,13 @@
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
|
||||
$(top_srcdir)/tap-driver.sh
|
||||
|
||||
TESTS = \
|
||||
startup.test
|
||||
|
||||
EXTRA_DIST = $(TESTS)
|
||||
|
||||
EXTRA_DIST += \
|
||||
icecast.xml \
|
||||
on-connect.sh
|
@ -4,7 +4,7 @@ testdir=$(dirname "$0")
|
||||
test -n "$testdir" && cd "$testdir" || exit
|
||||
|
||||
ICECAST_BASE_URL="http://localhost:8000/"
|
||||
|
||||
counter=1
|
||||
RETURN=0
|
||||
MOUNT_LISTENER_AUTH="foo.ogg"
|
||||
MOUNT_SOURCE_AUTH="test.ogg"
|
||||
@ -17,81 +17,104 @@ L_USER="foo"
|
||||
L_PASS="bar"
|
||||
L_AUTH="$L_USER:$L_PASS"
|
||||
|
||||
echo "Starting Icecast"
|
||||
echo "# Starting Icecast"
|
||||
../src/icecast -c ./icecast.xml 2> /dev/null &
|
||||
ICECAST_PID=$!
|
||||
sleep 5
|
||||
|
||||
echo "Starting Source client on /$MOUNT_LISTENER_AUTH"
|
||||
echo "# Starting Source client on /$MOUNT_LISTENER_AUTH"
|
||||
ffmpeg -loglevel panic -re -f lavfi -i "sine=frequency=1000" -content_type application/ogg "icecast://$AUTH_SOURCE@127.0.0.1:8000/$MOUNT_LISTENER_AUTH" &
|
||||
SOURCE1_PID=$!
|
||||
|
||||
echo "Starting Source client on /$MOUNT_SOURCE_AUTH"
|
||||
echo "# Starting Source client on /$MOUNT_SOURCE_AUTH"
|
||||
ffmpeg -loglevel panic -re -f lavfi -i "sine=frequency=1000" -content_type application/ogg "icecast://$AUTH_MOUNT@127.0.0.1:8000/$MOUNT_SOURCE_AUTH" &
|
||||
SOURCE2_PID=$!
|
||||
|
||||
function test_endpoint {
|
||||
echo " CURL $1"
|
||||
echo "# CURL $1"
|
||||
if test "x$3" == "x"; then
|
||||
res=$(curl -m 5 -o /dev/null -D - "$ICECAST_BASE_URL$1" 2>/dev/null | head -n 1 | cut -d$' ' -f2- | tr -d '\r\n')
|
||||
else
|
||||
res=$(curl -m 5 -u "$3" -o /dev/null -D - "$ICECAST_BASE_URL$1" 2>/dev/null | head -n 1 | cut -d$' ' -f2- | tr -d '\r\n')
|
||||
fi
|
||||
if test "$(echo "$res" | cut -d$' ' -f1)" -eq "$2"; then
|
||||
printf " \e[92mOK\e[39m"
|
||||
echo " [$res]"
|
||||
#printf " \e[92mOK\e[39m"
|
||||
#echo " [$res]"
|
||||
echo "ok $counter - foo"
|
||||
else
|
||||
printf " \e[91mFAIL\e[39m"
|
||||
echo " [$res] Expected: $2"
|
||||
#printf " \e[91mFAIL\e[39m"
|
||||
#echo " [$res] Expected: $2"
|
||||
echo "not ok $counter - foo"
|
||||
RETURN=1
|
||||
fi
|
||||
((counter++))
|
||||
}
|
||||
|
||||
echo
|
||||
echo "Testing admin/manageauth endpoint"
|
||||
function test_sourcing {
|
||||
echo "# CURL $1"
|
||||
if test "x$3" == "x"; then
|
||||
res=$(curl -X PUT -m 5 -d /dev/random -o /dev/null -D - "$ICECAST_BASE_URL$1" 2>/dev/null | head -n 1 | cut -d$' ' -f2- | tr -d '\r\n')
|
||||
else
|
||||
res=$(dd if=/dev/urandom bs=8 count=32 2>/dev/null | curl -X PUT -m 5 -H "Content-Type: application/octet-stream" --data-binary "@-" -v -u "$3" -o /dev/null -D - "$ICECAST_BASE_URL$1" 2>curl-log.txt | head -n 1 | cut -d$' ' -f2- | tr -d '\r\n')
|
||||
fi
|
||||
if test "$(echo "$res" | cut -d$' ' -f1)" -eq "$2"; then
|
||||
#printf " \e[92mOK\e[39m"
|
||||
#echo " [$res]"
|
||||
echo "ok $counter - foo"
|
||||
else
|
||||
#printf " \e[91mFAIL\e[39m"
|
||||
#echo " [$res] Expected: $2"
|
||||
echo "not ok $counter - foo"
|
||||
RETURN=1
|
||||
fi
|
||||
((counter++))
|
||||
}
|
||||
|
||||
echo "#"
|
||||
echo "# Testing admin/manageauth endpoint"
|
||||
test_endpoint "admin/manageauth?id=4&username=$L_USER&password=$L_PASS&action=add" 401
|
||||
test_endpoint "admin/manageauth?id=99&username=$L_USER&password=$L_PASS&action=add" 401
|
||||
test_endpoint "admin/manageauth?id=99&username=$L_USER&password=$L_PASS&action=add" 404 "$AUTH_ADMIN"
|
||||
test_endpoint "admin/manageauth?id=4&username=$L_USER&password=$L_PASS&action=add" 200 "$AUTH_ADMIN"
|
||||
|
||||
echo
|
||||
echo "Testing admin/buildm3u endpoint"
|
||||
echo "#"
|
||||
echo "# Testing admin/buildm3u endpoint"
|
||||
test_endpoint "admin/buildm3u?username=$L_USER&password=$L_PASS&mount=%2F$MOUNT_LISTENER_AUTH" 200
|
||||
test_endpoint "admin/buildm3u?username=something&password=foo&mount=%2F$MOUNT_LISTENER_AUTH" 200
|
||||
|
||||
echo
|
||||
echo "Testing admin/stats endpoint"
|
||||
echo "#"
|
||||
echo "# Testing admin/stats endpoint"
|
||||
test_endpoint "admin/stats" 401
|
||||
test_endpoint "admin/stats" 401 "$AUTH_SOURCE"
|
||||
test_endpoint "admin/stats" 401 "$L_AUTH"
|
||||
test_endpoint "admin/stats" 200 "$AUTH_ADMIN"
|
||||
|
||||
echo
|
||||
echo "Testing admin/listclients endpoint"
|
||||
echo "#"
|
||||
echo "# Testing admin/listclients endpoint"
|
||||
test_endpoint "admin/listclients" 401
|
||||
test_endpoint "admin/listclients" 401 "$AUTH_SOURCE"
|
||||
test_endpoint "admin/listclients" 401 "$L_AUTH"
|
||||
test_endpoint "admin/listclients" 400 "$AUTH_ADMIN"
|
||||
test_endpoint "admin/listclients?mount=%2F$MOUNT_LISTENER_AUTH" 200 "$AUTH_ADMIN"
|
||||
|
||||
echo
|
||||
echo "Testing admin/moveclients endpoint"
|
||||
echo "#"
|
||||
echo "# Testing admin/moveclients endpoint"
|
||||
test_endpoint "admin/moveclients" 401
|
||||
test_endpoint "admin/moveclients" 401 "$AUTH_SOURCE"
|
||||
test_endpoint "admin/moveclients" 401 "$L_AUTH"
|
||||
test_endpoint "admin/moveclients" 400 "$AUTH_ADMIN"
|
||||
test_endpoint "admin/moveclients?mount=%2F$MOUNT_LISTENER_AUTH" 200 "$AUTH_ADMIN"
|
||||
|
||||
echo
|
||||
echo "Testing admin/updatemetadata endpoint"
|
||||
echo "#"
|
||||
echo "# Testing admin/updatemetadata endpoint"
|
||||
test_endpoint "admin/updatemetadata" 401
|
||||
test_endpoint "admin/updatemetadata" 401 "$AUTH_SOURCE"
|
||||
test_endpoint "admin/updatemetadata" 401 "$L_AUTH"
|
||||
test_endpoint "admin/updatemetadata" 400 "$AUTH_ADMIN"
|
||||
test_endpoint "admin/updatemetadata?mount=%2F$MOUNT_LISTENER_AUTH" 200 "$AUTH_ADMIN"
|
||||
|
||||
echo
|
||||
echo "Testing admin/metadata endpoint"
|
||||
echo "#"
|
||||
echo "# Testing admin/metadata endpoint"
|
||||
test_endpoint "admin/metadata" 401
|
||||
test_endpoint "admin/metadata" 401 "$AUTH_SOURCE"
|
||||
test_endpoint "admin/metadata" 401 "$L_AUTH"
|
||||
@ -102,49 +125,67 @@ test_endpoint "admin/metadata?mount=%2F$MOUNT_SOURCE_AUTH&mode=updinfo&charset=U
|
||||
test_endpoint "admin/metadata?mount=%2F$MOUNT_SOURCE_AUTH&mode=updinfo&charset=UTF-8&song=Test2" 200 "$AUTH_ADMIN"
|
||||
test_endpoint "admin/metadata?mount=%2F$MOUNT_SOURCE_AUTH&mode=updinfo&charset=UTF-8&song=Test3" 200 "$AUTH_MOUNT"
|
||||
|
||||
echo
|
||||
echo "Testing admin/listmounts endpoint"
|
||||
echo "#"
|
||||
echo "# Testing admin/listmounts endpoint"
|
||||
test_endpoint "admin/listmounts" 401
|
||||
test_endpoint "admin/listmounts" 401 "$AUTH_SOURCE"
|
||||
test_endpoint "admin/listmounts" 401 "$L_AUTH"
|
||||
test_endpoint "admin/listmounts" 200 "$AUTH_ADMIN"
|
||||
test_endpoint "admin/listmounts?mount=%2F$MOUNT_LISTENER_AUTH" 400 "$AUTH_ADMIN"
|
||||
|
||||
echo
|
||||
echo "Testing mountpoint which requires auth"
|
||||
echo "#"
|
||||
echo "# Testing mountpoint which requires auth"
|
||||
test_endpoint "$MOUNT_LISTENER_AUTH" 401
|
||||
test_endpoint "$MOUNT_LISTENER_AUTH" 401 "$AUTH_SOURCE"
|
||||
test_endpoint "$MOUNT_LISTENER_AUTH" 200 "$L_AUTH"
|
||||
test_endpoint "$MOUNT_LISTENER_AUTH" 401 "$AUTH_ADMIN"
|
||||
|
||||
echo
|
||||
echo "Testing mountpoint which doesn't require auth"
|
||||
echo "#"
|
||||
echo "# Testing mountpoint which doesn't require auth"
|
||||
test_endpoint "$MOUNT_SOURCE_AUTH" 200
|
||||
test_endpoint "$MOUNT_SOURCE_AUTH" 200 "$AUTH_SOURCE"
|
||||
test_endpoint "$MOUNT_SOURCE_AUTH" 200 "$L_AUTH"
|
||||
test_endpoint "$MOUNT_SOURCE_AUTH" 200 "$AUTH_ADMIN"
|
||||
|
||||
echo
|
||||
echo "Testing admin/killsource endpoint"
|
||||
echo "#"
|
||||
echo "# Testing admin/killsource endpoint"
|
||||
test_endpoint "admin/killsource" 401
|
||||
test_endpoint "admin/killsource" 401 "$AUTH_SOURCE"
|
||||
test_endpoint "admin/killsource" 401 "$L_AUTH"
|
||||
test_endpoint "admin/killsource" 400 "$AUTH_ADMIN"
|
||||
test_endpoint "admin/killsource?mount=%2F$MOUNT_LISTENER_AUTH" 200 "$AUTH_ADMIN"
|
||||
|
||||
echo
|
||||
echo "All tests done"
|
||||
echo
|
||||
echo "#"
|
||||
echo "# Testing on-connect handling with probing"
|
||||
test_sourcing "test-on-connect.ogg" 401
|
||||
if [ -f "on-connect-success" ]; then
|
||||
echo "#FAIL: on-connect triggered even though it should not!"
|
||||
rm "on-connect-success"
|
||||
fi
|
||||
test_sourcing "test-on-connect.ogg" 200 "$AUTH_SOURCE"
|
||||
if [ -f "on-connect-success" ]; then
|
||||
echo "#OK: on-connect triggered!"
|
||||
rm "on-connect-success"
|
||||
else
|
||||
echo "#FAIL: on-connect not triggered!"
|
||||
fi
|
||||
|
||||
echo "#"
|
||||
echo "#All tests done, cleanup..."
|
||||
echo "#"
|
||||
|
||||
rm "myauth"
|
||||
|
||||
if kill $SOURCE1_PID; then
|
||||
echo "Terminated SOURCE1"
|
||||
echo "#Terminated SOURCE1"
|
||||
fi
|
||||
if kill $SOURCE2_PID; then
|
||||
echo "Terminated SOURCE2"
|
||||
echo "#Terminated SOURCE2"
|
||||
fi
|
||||
|
||||
if kill $ICECAST_PID; then
|
||||
echo "Terminated Icecast"
|
||||
echo "#Terminated Icecast"
|
||||
fi
|
||||
|
||||
echo "1..(($counter-1))" # Number of tests to be executed.
|
||||
exit $RETURN
|
||||
|
@ -41,6 +41,11 @@
|
||||
<password>hackmemore</password>
|
||||
</mount>
|
||||
|
||||
<mount type="normal">
|
||||
<mount-name>/test-on-connect.ogg</mount-name>
|
||||
<on-connect>on-connect.sh</on-connect>
|
||||
</mount>
|
||||
|
||||
<mount type="normal">
|
||||
<mount-name>/foo.ogg</mount-name>
|
||||
<authentication type="htpasswd">
|
||||
|
3
tests/on-connect.sh
Executable file
3
tests/on-connect.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
touch "on-connect-success"
|
||||
exit 0
|
19
tests/startup.test
Executable file
19
tests/startup.test
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
../src/icecast -c ./icecast.xml 2> /dev/null &
|
||||
ICECAST_PID=$!
|
||||
echo 'ok 1 - Icecast started'
|
||||
sleep 3
|
||||
|
||||
if kill -0 $ICECAST_PID > /dev/null 2>&1; then
|
||||
echo 'ok 2 - Icecast running'
|
||||
else
|
||||
echo 'not ok 2 - Icecast not running'
|
||||
fi
|
||||
|
||||
if kill $ICECAST_PID > /dev/null 2>&1; then
|
||||
echo 'ok 3 - Icecast stopped'
|
||||
else
|
||||
echo 'not ok 3 - Icecast not stopped'
|
||||
fi
|
||||
|
||||
echo 1..3 # Number of tests to be executed.
|
Loading…
Reference in New Issue
Block a user