-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·31 lines (24 loc) · 870 Bytes
/
Copy pathtest.sh
File metadata and controls
executable file
·31 lines (24 loc) · 870 Bytes
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
#!/bin/sh
url=http://localhost:1234
do_test() {
"$@" && echo pass || echo fail "$@"
}
check_redirect() {
curl --silent --head "$url/$1" | do_test grep --quiet "Location: $2"
}
go run main.go -listen localhost:1234 -url http://localhost:1234 &
echo waiting for startup
while ! curl --silent "$url";
do
sleep 1
done
check_redirect '?q=123' 'https://duckduckgo.com/?q=123'
curl -X POST "$url/first?a=pref-a-&b=pref-b-"
check_redirect '?q=%21a+test' 'https://duckduckgo.com/?q=%21a+test'
check_redirect '/first?q=%21a+test' 'pref-a-test'
check_redirect '/first?q=%21b+test' 'pref-b-test'
curl -X POST "$url//second//?b=pref2-b-"
check_redirect '/first?q=%21b+test' 'pref-b-test'
check_redirect '/second?q=%21b+test' 'pref2-b-test'
check_redirect '/first/sub?q=%21b+test' 'pref-b-test'
kill $(netstat -tlp 2>/dev/null | grep -Po 'LISTEN\s+\K\d+(?=/main)')