fd: Improve error handling of write_nonblock().
[paraslash.git] / t / t0004-server.sh
1 #!/usr/bin/env bash
2
3 test_description='Check if server command socket works.
4
5 A new ssh key pair is generated, para_server is started and some commands are
6 sent to the server by executing para_client. This is an implicit check of the
7 crypto functions.
8 '
9
10 . ${0%/*}/test-lib.sh
11
12 loglevel=debug
13 port=2991
14 stream_port=8001
15 # need absolute paths here because server cds to / in daemon mode
16 db=$(pwd)/db
17 sock=$(pwd)/sock
18 user_list=ul
19 privkey=key
20 pubkey=$privkey.pub
21 serverlog=server.log
22
23 get_audio_file_paths ogg
24 oggs="$result"
25
26 declare -a commands=() cmdline=() required_objects=() good=() bad=()
27 i=0
28 commands[$i]="help"
29 cmdline[$i]="help"
30 good[$i]='help  server  ----'
31
32 let i++
33 commands[$i]="init"
34 cmdline[$i]="init"
35 good[$i]='^successfully'
36 bad[$i]='!^successfully'
37
38 let i++
39 commands[$i]="add_ogg"
40 required_objects[$i]='ogg_afh'
41 cmdline[$i]="add $oggs"
42 bad[$i]='.'
43
44 let i++
45 commands[$i]="ls_ogg"
46 required_objects[$i]='ogg_afh'
47 cmdline[$i]="ls -lv -p $oggs"
48 good[$i]='^path:'
49
50 let i++
51 commands[$i]="term"
52 cmdline[$i]="term"
53 bad[$i]='.'
54
55 test_require_objects "server"
56 missing_objects="$result"
57 test_require_executables "ssh-keygen"
58 missing_executables="$result"
59
60 ssh-keygen -q -t rsa -b 2048 -N "" -f $privkey
61 key_gen_result=$?
62
63 read &>/dev/null < /dev/tcp/localhost/$port
64 check_port_result=$?
65
66 cat > $user_list << EOF
67 user $LOGNAME $pubkey AFS_READ,AFS_WRITE,VSS_READ,VSS_WRITE
68 EOF
69
70 # para_server sends this signal to all processes in the current process group.
71 trap "" SIGUSR1
72
73 $PARA_SERVER \
74         --logfile "$serverlog" \
75         --config_file /dev/null \
76         --daemon \
77         --loglevel $loglevel \
78         --port $port \
79         --afs_database_dir "$db" \
80         --afs_socket "$sock" \
81         --user_list "$user_list" \
82         --http_port "$stream_port" \
83         --dccp_port "$stream_port"
84
85 for ((i=0; i < ${#commands[@]}; i++)); do
86         command=${commands[$i]}
87         if [[ -n "$missing_objects" ]]; then
88                 test_skip "$command" "missing object(s): $missing_objects"
89                 continue
90         fi
91         if [[ -n "$missing_executables" ]]; then
92                 test_skip "$command" \
93                         "missing executables(s): $missing_executables"
94                 continue
95         fi
96         if (($key_gen_result != 0)); then
97                 test_skip "$command" "ssh-keygen failed"
98                 continue
99         fi
100         if (($check_port_result == 0)); then
101                 test_skip "$command" "port $port already in use"
102                 continue
103         fi
104         if [[ -n "${required_objects[$i]}" ]]; then
105                 test_require_objects "${required_objects[$i]}"
106                 if [[ -n "$result" ]]; then
107                         test_skip "$command" "requires object $result"
108                         continue
109                 fi
110         fi
111         test_expect_success "$command" "
112         $PARA_CLIENT \
113                 --loglevel $loglevel \
114                 --server_port $port \
115                 --key_file $privkey \
116                 --config_file /dev/null \
117                 -- \
118                 ${cmdline[$i]} > $command.out &&
119                 { [[ -z \"${good[$i]}\" ]] || grep \"${good[$i]}\"; } < $command.out &&
120                 { [[ -z \"${bad[$i]}\" ]]  || ! grep \"${bad[$i]}\"; } < $command.out
121         "
122 done
123
124 trap SIGUSR1 # reset to the value it had upon entrance to the shell
125 test_done