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