summaryrefslogtreecommitdiff
path: root/t/t0004-server.bash
blob: 2ace8e4f1330f044384078c0741ebec7bb541790 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env bash

test_description='Check if server command socket works.

A new ssh key pair is generated, para_server is started and some commands are
sent to the server by executing para_client. This is an implicit check of the
crypto functions.
'

. ${0%/*}/test-lib.bash

loglevel=debug
port=2991
stream_port=8001
# need absolute paths here because server cds to / in daemon mode
db=$(pwd)/db
sock=$(pwd)/sock
user_list=ul
privkey=key
pubkey=$privkey.pub
serverlog=server.log

get_audio_file_paths ogg
declare -a oggs=($result)
declare -a oggs_base=(${oggs[@]##*/})

declare -a commands=() cmdline=() required_objects=() good=() bad=() \
	expect_failure=()
i=0
commands[$i]="help"
cmdline[$i]="help -l"
good[$i]='help \{1,\}----'

let i++
commands[$i]='add_mp3'
required_objects[$i]='mp3_afh'
cmdline[$i]="add -v $test_audio_file_dir"
good[$i]='^adding'

let i++
commands[$i]="add_ogg"
required_objects[$i]='ogg_afh'
cmdline[$i]="add ${oggs[@]}"
bad[$i]='.'

let i++
commands[$i]="ls_ogg"
required_objects[$i]='ogg_afh'
cmdline[$i]="ls -l=v -b ${oggs_base[@]}"
good[$i]='^basename:'

let i++
commands[$i]='addatt'
required_objects[$i]=''
cmdline[$i]="addatt $(seq 64 | tr '\n' ' ')"
bad[$i]='.'

let i++
commands[$i]='lsatt'
required_objects[$i]=''
cmdline[$i]="lsatt"
good[$i]='^1$'

let i++
commands[$i]='touch'
required_objects[$i]='ogg_afh'
cmdline[$i]="touch --set-attribute=33 ${oggs[@]}"
bad[$i]='.'

let i++
commands[$i]="ls"
required_objects[$i]='ogg_afh'
cmdline[$i]="ls -l=v ${oggs[@]}"
good[$i]='^attributes_txt: 33'

let i++
commands[$i]='rm_ogg'
required_objects[$i]='ogg_afh'
cmdline[$i]="rm -v ${oggs[@]}"
good[$i]='^removing'

let i++
commands[$i]='addmood'
cmdline[$i]="addmood test-mood"

let i++
commands[$i]='empty-mood-parameter'
cmdline[$i]="select m/"
expect_failure[$i]='true'

let i++
commands[$i]="term"
cmdline[$i]="term"
bad[$i]='.'

test_require_objects "server"
missing_objects="$result"
test_require_executables "ssh-keygen"
missing_executables="$result"

if [[ -z "$missing_objects" && -z "$missing_executables" ]]; then
	ssh-keygen -q -t rsa -b 2048 -N "" -m RFC4716 -f $privkey
	key_gen_result=$?

	read &>/dev/null < /dev/tcp/localhost/$port
	check_port_result=$?

	cat > $user_list << EOF
	user $LOGNAME $pubkey AFS_READ,AFS_WRITE,VSS_READ,VSS_WRITE
EOF

	# para_server sends this signal to all processes in the current process group.
	trap "" SIGUSR1


	$PARA_SERVER \
		--logfile "$serverlog" \
		--config-file /dev/null \
		--daemon \
		--loglevel $loglevel \
		--port $port \
		--afs-database-dir "$db" \
		--init \
		--afs-socket "$sock" \
		--user-list "$user_list" \
		--http-port "$stream_port"
	(($? != 0)) && exit 1
fi

for ((i=0; i < ${#commands[@]}; i++)); do
	command=${commands[$i]}
	if [[ -n "$missing_objects" ]]; then
		test_skip "$command" "missing object(s): $missing_objects"
		continue
	fi
	if [[ -n "$missing_executables" ]]; then
		test_skip "$command" \
			"missing executables(s): $missing_executables"
		continue
	fi
	if (($key_gen_result != 0)); then
		test_skip "$command" "ssh-keygen failed"
		continue
	fi
	if (($check_port_result == 0)); then
		test_skip "$command" "port $port already in use"
		continue
	fi
	if [[ -n "${required_objects[$i]}" ]]; then
		test_require_objects "${required_objects[$i]}"
		if [[ -n "$result" ]]; then
			test_skip "$command" "requires object $result"
			continue
		fi
	fi
	if [[ -n "${expect_failure[$i]}" ]]; then
		f=test_expect_failure
	else
		f=test_expect_success
	fi
	$f "$command" "
	$PARA_CLIENT \
		--loglevel $loglevel \
		--server-port $port \
		--key-file $privkey \
		--config-file /dev/null \
		-- \
		${cmdline[$i]} > $command.out < /dev/null &&
		{ [[ -z \"${good[$i]}\" ]] || grep \"${good[$i]}\"; } < $command.out &&
		{ [[ -z \"${bad[$i]}\" ]]  || ! grep \"${bad[$i]}\"; } < $command.out
	"
done

trap SIGUSR1 # reset to the value it had upon entrance to the shell
test_done