testsuite: Introduce a new test for para_server.
authorAndre Noll <maan@systemlinux.org>
Sun, 11 Sep 2011 00:45:23 +0000 (02:45 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 15 Oct 2011 19:22:53 +0000 (21:22 +0200)
This adds t0004-server.sh, a new test script which starts para_server
and tries to connect to it using the loopback device.

t/t0004-server.sh [new file with mode: 0755]

diff --git a/t/t0004-server.sh b/t/t0004-server.sh
new file mode 100755 (executable)
index 0000000..c79ea24
--- /dev/null
@@ -0,0 +1,125 @@
+#!/usr/bin/env bash
+
+test_description='Check if server command socket works.
+
+A new ssh key pair is generated, para_server is started and some commands are
+sent to the server by executing para_client. This is an implicit check of the
+crypto functions.
+'
+
+. ${0%/*}/test-lib.sh
+
+loglevel=debug
+port=2991
+stream_port=8001
+# need absolute paths here because server cds to / in daemon mode
+db=$(pwd)/db
+sock=$(pwd)/sock
+user_list=ul
+privkey=key
+pubkey=$privkey.pub
+serverlog=server.log
+
+get_audio_file_paths ogg
+oggs="$result"
+
+declare -a commands=() cmdline=() required_objects=() good=() bad=()
+i=0
+commands[$i]="help"
+cmdline[$i]="help"
+good[$i]='help server  ----'
+
+let i++
+commands[$i]="init"
+cmdline[$i]="init"
+good[$i]='^successfully'
+bad[$i]='!^successfully'
+
+let i++
+commands[$i]="add_ogg"
+required_objects[$i]='ogg_afh'
+cmdline[$i]="add $oggs"
+bad[$i]='.'
+
+let i++
+commands[$i]="ls_ogg"
+required_objects[$i]='ogg_afh'
+cmdline[$i]="ls -lv -p $oggs"
+good[$i]='^path:'
+
+let i++
+commands[$i]="term"
+cmdline[$i]="term"
+bad[$i]='.'
+
+test_require_objects "server"
+missing_objects="$result"
+test_require_executables "ssh-keygen"
+missing_executables="$result"
+
+ssh-keygen -q -t rsa -b 2048 -N "" -f $privkey
+key_gen_result=$?
+
+read &>/dev/null < /dev/tcp/localhost/$port
+check_port_result=$?
+
+cat > $user_list << EOF
+user $LOGNAME $pubkey AFS_READ,AFS_WRITE,VSS_READ,VSS_WRITE
+EOF
+
+# para_server sends this signal to all processes in the current process group.
+trap "" SIGUSR1
+
+$PARA_SERVER \
+       --logfile "$serverlog" \
+       --config_file /dev/null \
+       --daemon \
+       --loglevel $loglevel \
+       --port $port \
+       --afs_database_dir "$db" \
+       --afs_socket "$sock" \
+       --user_list "$user_list" \
+       --http_port "$stream_port" \
+       --dccp_port "$stream_port"
+
+for ((i=0; i < ${#commands[@]}; i++)); do
+       command=${commands[$i]}
+       if [[ -n "$missing_objects" ]]; then
+               test_skip "$command" "missing object(s): $missing_objects"
+               continue
+       fi
+       if [[ -n "$missing_executables" ]]; then
+               test_skip "$command" \
+                       "missing executables(s): $missing_executables"
+               continue
+       fi
+       if (($key_gen_result != 0)); then
+               test_skip "$command" "ssh-keygen failed"
+               continue
+       fi
+       if (($check_port_result == 0)); then
+               test_skip "$command" "port $port already in use"
+               continue
+       fi
+       if [[ -n "${required_objects[$i]}" ]]; then
+               test_require_objects "${required_objects[$i]}"
+               if [[ -n "$result" ]]; then
+                       test_skip "$command" "requires object $result"
+                       continue
+               fi
+       fi
+       test_expect_success "$command" "
+       $PARA_CLIENT \
+               --loglevel $loglevel \
+               --server_port $port \
+               --key_file $privkey \
+               --config_file /dev/null \
+               -- \
+               ${cmdline[$i]} > $command.out &&
+               { [[ -z \"${good[$i]}\" ]] || grep \"${good[$i]}\"; } < $command.out &&
+               { [[ -z \"${bad[$i]}\" ]]  || ! grep \"${bad[$i]}\"; } < $command.out
+       "
+done
+
+trap SIGUSR1 # reset to the value it had upon entrance to the shell
+test_done