#!/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.bash 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 declare -a oggs=($result) declare -a oggs_base=(${oggs[@]##*/}) declare -a commands=() cmdline=() required_objects=() good=() bad=() \ expect_failure=() i=0 commands[$i]="help" cmdline[$i]="help -l" good[$i]='help \{1,\}----' let i++ commands[$i]='add_mp3' required_objects[$i]='mp3_afh' cmdline[$i]="add -v $test_audio_file_dir" good[$i]='^adding' 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 -l=v -b ${oggs_base[@]}" good[$i]='^basename:' let i++ commands[$i]='addatt' required_objects[$i]='' cmdline[$i]="addatt $(seq 64 | tr '\n' ' ')" bad[$i]='.' let i++ commands[$i]='lsatt' required_objects[$i]='' cmdline[$i]="lsatt" good[$i]='^1$' let i++ commands[$i]='touch' required_objects[$i]='ogg_afh' cmdline[$i]="touch --set-attribute=33 ${oggs[@]}" bad[$i]='.' let i++ commands[$i]="ls" required_objects[$i]='ogg_afh' cmdline[$i]="ls -l=v ${oggs[@]}" good[$i]='^attributes_txt: 33' let i++ commands[$i]='rm_ogg' required_objects[$i]='ogg_afh' cmdline[$i]="rm -v ${oggs[@]}" good[$i]='^removing' let i++ commands[$i]='addmood' cmdline[$i]="addmood test-mood" let i++ commands[$i]='empty-mood-parameter' cmdline[$i]="select m/" expect_failure[$i]='true' 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" if [[ -z "$missing_objects" && -z "$missing_executables" ]]; then ssh-keygen -q -t rsa -b 2048 -N "" -m RFC4716 -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" \ --init \ --afs-socket "$sock" \ --user-list "$user_list" \ --http-port "$stream_port" (($? != 0)) && exit 1 fi 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 if [[ -n "${expect_failure[$i]}" ]]; then f=test_expect_failure else f=test_expect_success fi $f "$command" " $PARA_CLIENT \ --loglevel $loglevel \ --server-port $port \ --key-file $privkey \ --config-file /dev/null \ -- \ ${cmdline[$i]} > $command.out < /dev/null && { [[ -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