Merge branch 'refs/heads/t/attribute_fix'
[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]='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 -p ${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 fi
112
113 for ((i=0; i < ${#commands[@]}; i++)); do
114 command=${commands[$i]}
115 if [[ -n "$missing_objects" ]]; then
116 test_skip "$command" "missing object(s): $missing_objects"
117 continue
118 fi
119 if [[ -n "$missing_executables" ]]; then
120 test_skip "$command" \
121 "missing executables(s): $missing_executables"
122 continue
123 fi
124 if (($key_gen_result != 0)); then
125 test_skip "$command" "ssh-keygen failed"
126 continue
127 fi
128 if (($check_port_result == 0)); then
129 test_skip "$command" "port $port already in use"
130 continue
131 fi
132 if [[ -n "${required_objects[$i]}" ]]; then
133 test_require_objects "${required_objects[$i]}"
134 if [[ -n "$result" ]]; then
135 test_skip "$command" "requires object $result"
136 continue
137 fi
138 fi
139 test_expect_success "$command" "
140 $PARA_CLIENT \
141 --loglevel $loglevel \
142 --server-port $port \
143 --key-file $privkey \
144 --config-file /dev/null \
145 -- \
146 ${cmdline[$i]} > $command.out &&
147 { [[ -z \"${good[$i]}\" ]] || grep \"${good[$i]}\"; } < $command.out &&
148 { [[ -z \"${bad[$i]}\" ]] || ! grep \"${bad[$i]}\"; } < $command.out
149 "
150 done
151
152 trap SIGUSR1 # reset to the value it had upon entrance to the shell
153 test_done