]> git.tuebingen.mpg.de Git - paraslash.git/blob - t/t0004-server.sh
Merge branch 'maint'
[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 if [[ -z "$missing_objects" && -z "$missing_executables" ]]; then
61         ssh-keygen -q -t rsa -b 2048 -N "" -f $privkey
62         key_gen_result=$?
63
64         read &>/dev/null < /dev/tcp/localhost/$port
65         check_port_result=$?
66
67         cat > $user_list << EOF
68         user $LOGNAME $pubkey AFS_READ,AFS_WRITE,VSS_READ,VSS_WRITE
69 EOF
70
71         # para_server sends this signal to all processes in the current process group.
72         trap "" SIGUSR1
73
74
75         $PARA_SERVER \
76                 --logfile "$serverlog" \
77                 --config-file /dev/null \
78                 --daemon \
79                 --loglevel $loglevel \
80                 --port $port \
81                 --afs-database-dir "$db" \
82                 --afs-socket "$sock" \
83                 --user-list "$user_list" \
84                 --http-port "$stream_port" \
85                 --dccp-port "$stream_port"
86 fi
87
88 for ((i=0; i < ${#commands[@]}; i++)); do
89         command=${commands[$i]}
90         if [[ -n "$missing_objects" ]]; then
91                 test_skip "$command" "missing object(s): $missing_objects"
92                 continue
93         fi
94         if [[ -n "$missing_executables" ]]; then
95                 test_skip "$command" \
96                         "missing executables(s): $missing_executables"
97                 continue
98         fi
99         if (($key_gen_result != 0)); then
100                 test_skip "$command" "ssh-keygen failed"
101                 continue
102         fi
103         if (($check_port_result == 0)); then
104                 test_skip "$command" "port $port already in use"
105                 continue
106         fi
107         if [[ -n "${required_objects[$i]}" ]]; then
108                 test_require_objects "${required_objects[$i]}"
109                 if [[ -n "$result" ]]; then
110                         test_skip "$command" "requires object $result"
111                         continue
112                 fi
113         fi
114         test_expect_success "$command" "
115         $PARA_CLIENT \
116                 --loglevel $loglevel \
117                 --server-port $port \
118                 --key-file $privkey \
119                 --config-file /dev/null \
120                 -- \
121                 ${cmdline[$i]} > $command.out &&
122                 { [[ -z \"${good[$i]}\" ]] || grep \"${good[$i]}\"; } < $command.out &&
123                 { [[ -z \"${bad[$i]}\" ]]  || ! grep \"${bad[$i]}\"; } < $command.out
124         "
125 done
126
127 trap SIGUSR1 # reset to the value it had upon entrance to the shell
128 test_done