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