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