]> git.tuebingen.mpg.de Git - paraslash.git/blob - t/t0004-server.sh
paraslash 0.7.3
[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 declare -a oggs=($result)
25 declare -a oggs_base=(${oggs[@]##*/})
26
27 declare -a commands=() cmdline=() required_objects=() good=() bad=() \
28         expect_failure=()
29 i=0
30 commands[$i]="help"
31 cmdline[$i]="help -l"
32 good[$i]='help \{1,\}----'
33
34 let i++
35 commands[$i]="init"
36 cmdline[$i]="init"
37 good[$i]='^successfully'
38 bad[$i]='!^successfully'
39
40 let i++
41 commands[$i]='add_dir'
42 required_objects[$i]='ogg_afh'
43 cmdline[$i]="add -v $test_audio_file_dir"
44 good[$i]='^adding'
45
46 let i++
47 commands[$i]='rm'
48 required_objects[$i]='ogg_afh'
49 cmdline[$i]="rm -v $test_audio_file_dir/*"
50 good[$i]='^removing'
51
52 let i++
53 commands[$i]="add_ogg"
54 required_objects[$i]='ogg_afh'
55 cmdline[$i]="add ${oggs[@]}"
56 bad[$i]='.'
57
58 let i++
59 commands[$i]="ls_ogg"
60 required_objects[$i]='ogg_afh'
61 cmdline[$i]="ls -l=v -b ${oggs_base[@]}"
62 good[$i]='^basename:'
63
64 let i++
65 commands[$i]='addatt'
66 required_objects[$i]=''
67 cmdline[$i]="addatt $(seq 64 | tr '\n' ' ')"
68 bad[$i]='.'
69
70 let i++
71 commands[$i]='lsatt'
72 required_objects[$i]=''
73 cmdline[$i]="lsatt"
74 good[$i]='^1$'
75
76 let i++
77 commands[$i]='setatt'
78 required_objects[$i]='ogg_afh'
79 cmdline[$i]="setatt 33+ ${oggs[@]}"
80 bad[$i]='.'
81
82 let i++
83 commands[$i]="ls"
84 required_objects[$i]='ogg_afh'
85 cmdline[$i]="ls -l=v ${oggs[@]}"
86 good[$i]='^attributes_txt: 33'
87
88 let i++
89 commands[$i]='addmood'
90 cmdline[$i]="addmood test-mood"
91
92 let i++
93 commands[$i]='empty-mood-parameter'
94 cmdline[$i]="select m/"
95 expect_failure[$i]='true'
96
97 let i++
98 commands[$i]="term"
99 cmdline[$i]="term"
100 bad[$i]='.'
101
102 test_require_objects "server"
103 missing_objects="$result"
104 test_require_executables "ssh-keygen"
105 missing_executables="$result"
106
107 if [[ -z "$missing_objects" && -z "$missing_executables" ]]; then
108         ssh-keygen -q -t rsa -b 2048 -N "" -m PEM -f $privkey
109         key_gen_result=$?
110
111         read &>/dev/null < /dev/tcp/localhost/$port
112         check_port_result=$?
113
114         cat > $user_list << EOF
115         user $LOGNAME $pubkey AFS_READ,AFS_WRITE,VSS_READ,VSS_WRITE
116 EOF
117
118         # para_server sends this signal to all processes in the current process group.
119         trap "" SIGUSR1
120
121
122         $PARA_SERVER \
123                 --logfile "$serverlog" \
124                 --config-file /dev/null \
125                 --daemon \
126                 --loglevel $loglevel \
127                 --port $port \
128                 --afs-database-dir "$db" \
129                 --afs-socket "$sock" \
130                 --user-list "$user_list" \
131                 --http-port "$stream_port" \
132                 --dccp-port "$stream_port"
133         (($? != 0)) && exit 1
134 fi
135
136 for ((i=0; i < ${#commands[@]}; i++)); do
137         command=${commands[$i]}
138         if [[ -n "$missing_objects" ]]; then
139                 test_skip "$command" "missing object(s): $missing_objects"
140                 continue
141         fi
142         if [[ -n "$missing_executables" ]]; then
143                 test_skip "$command" \
144                         "missing executables(s): $missing_executables"
145                 continue
146         fi
147         if (($key_gen_result != 0)); then
148                 test_skip "$command" "ssh-keygen failed"
149                 continue
150         fi
151         if (($check_port_result == 0)); then
152                 test_skip "$command" "port $port already in use"
153                 continue
154         fi
155         if [[ -n "${required_objects[$i]}" ]]; then
156                 test_require_objects "${required_objects[$i]}"
157                 if [[ -n "$result" ]]; then
158                         test_skip "$command" "requires object $result"
159                         continue
160                 fi
161         fi
162         if [[ -n "${expect_failure[$i]}" ]]; then
163                 f=test_expect_failure
164         else
165                 f=test_expect_success
166         fi
167         $f "$command" "
168         $PARA_CLIENT \
169                 --loglevel $loglevel \
170                 --server-port $port \
171                 --key-file $privkey \
172                 --config-file /dev/null \
173                 -- \
174                 ${cmdline[$i]} > $command.out < /dev/null &&
175                 { [[ -z \"${good[$i]}\" ]] || grep \"${good[$i]}\"; } < $command.out &&
176                 { [[ -z \"${bad[$i]}\" ]]  || ! grep \"${bad[$i]}\"; } < $command.out
177         "
178 done
179
180 trap SIGUSR1 # reset to the value it had upon entrance to the shell
181 test_done