1 |
#!/bin/sh |
2 |
# proxy.sh - test jscoverage-server --proxy |
3 |
# Copyright (C) 2008, 2009, 2010 siliconforks.com |
4 |
# |
5 |
# This program is free software; you can redistribute it and/or modify |
6 |
# it under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 2 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# This program is distributed in the hope that it will be useful, |
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License along |
16 |
# with this program; if not, write to the Free Software Foundation, Inc., |
17 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
18 |
|
19 |
set -e |
20 |
|
21 |
shutdown() { |
22 |
wget -q -O- --post-data= "http://127.0.0.1:${proxy_server_port}/jscoverage-shutdown" > /dev/null |
23 |
wait $proxy_server_pid |
24 |
} |
25 |
|
26 |
shutdown_perl() { |
27 |
wget -q -O- --post-data= http://127.0.0.1:8000/perl-shutdown > /dev/null |
28 |
wait $origin_server_pid |
29 |
} |
30 |
|
31 |
cleanup() { |
32 |
rm -fr EXPECTED ACTUAL DIR OUT |
33 |
shutdown |
34 |
shutdown_perl |
35 |
} |
36 |
|
37 |
trap 'cleanup' 0 1 2 3 15 |
38 |
|
39 |
export PATH=.:..:$PATH |
40 |
|
41 |
if [ -z "$VALGRIND" ] |
42 |
then |
43 |
delay=0.2 |
44 |
else |
45 |
delay=2 |
46 |
fi |
47 |
|
48 |
cd recursive |
49 |
perl ../server.pl > /dev/null 2> /dev/null & |
50 |
origin_server_pid=$! |
51 |
cd .. |
52 |
|
53 |
rm -fr DIR |
54 |
mkdir DIR |
55 |
$VALGRIND jscoverage-server --no-highlight --proxy --report-dir=DIR > OUT 2> ERR & |
56 |
proxy_server_pid=$! |
57 |
proxy_server_port=8080 |
58 |
|
59 |
sleep $delay |
60 |
|
61 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/index.html | diff recursive/index.html - |
62 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/style.css | diff recursive/style.css - |
63 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/unix.txt | diff recursive/unix.txt - |
64 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/windows.txt | diff recursive/windows.txt - |
65 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/image.png | diff recursive/image.png - |
66 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/x | diff recursive/x - |
67 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/1/1.html | diff recursive/1/1.html - |
68 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/1/1.css | diff recursive/1/1.css - |
69 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/1/2/2.html | diff recursive/1/2/2.html - |
70 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/1/2/2.css | diff recursive/1/2/2.css - |
71 |
|
72 |
# test localhost |
73 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://localhost:8000/index.html | diff recursive/index.html - |
74 |
|
75 |
# test actual hostname |
76 |
h=`hostname` |
77 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://${h}:8000/index.html | diff recursive/index.html - |
78 |
|
79 |
# test query string |
80 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/index.html?foo | diff recursive/index.html - |
81 |
|
82 |
# test POST |
83 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' --post-file=recursive/index.html http://127.0.0.1:8000/ | diff recursive/index.html - |
84 |
|
85 |
# test javascript |
86 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/script.js > OUT |
87 |
cat ../report.js recursive.expected/script.js | sed 's/@PREFIX@/http:\/\/127.0.0.1:8000\//g' | diff --strip-trailing-cr - OUT |
88 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/1/1.js > OUT |
89 |
cat ../report.js recursive.expected/1/1.js | sed 's/@PREFIX@/http:\/\/127.0.0.1:8000\//g' | diff --strip-trailing-cr - OUT |
90 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://127.0.0.1:8000/1/2/2.js > OUT |
91 |
cat ../report.js recursive.expected/1/2/2.js | sed 's/@PREFIX@/http:\/\/127.0.0.1:8000\//g' | diff --strip-trailing-cr - OUT |
92 |
|
93 |
## test jscoverage |
94 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://siliconforks.com/jscoverage.html | diff ../jscoverage.html - |
95 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://siliconforks.com/jscoverage.css | diff ../jscoverage.css - |
96 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://siliconforks.com/jscoverage-throbber.gif | diff ../jscoverage-throbber.gif - |
97 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' http://siliconforks.com/jscoverage.js > OUT |
98 |
echo 'jscoverage_isServer = true;' | cat ../jscoverage.js - | diff --strip-trailing-cr - OUT |
99 |
|
100 |
# load/store |
101 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8080/' --post-data='{}' http://siliconforks.com/jscoverage-store > /dev/null |
102 |
echo -n '{}' | diff - DIR/jscoverage.json |
103 |
diff ../jscoverage.html DIR/jscoverage.html |
104 |
diff ../jscoverage.css DIR/jscoverage.css |
105 |
diff ../jscoverage-throbber.gif DIR/jscoverage-throbber.gif |
106 |
echo 'jscoverage_isReport = true;' | cat ../jscoverage.js - | diff --strip-trailing-cr - DIR/jscoverage.js |
107 |
|
108 |
# send it an FTP request |
109 |
echo 400 > EXPECTED |
110 |
! curl -f -w '%{http_code}\n' -x 127.0.0.1:8080 ftp://ftp.example.com 2> /dev/null > ACTUAL |
111 |
diff EXPECTED ACTUAL |
112 |
|
113 |
# nonexistent domain |
114 |
echo 504 > EXPECTED |
115 |
! curl -f -w '%{http_code}\n' -x 127.0.0.1:8080 http://nonexistent 2> /dev/null > ACTUAL |
116 |
diff EXPECTED ACTUAL |
117 |
|
118 |
# 404 not found |
119 |
echo 404 > EXPECTED |
120 |
! curl -f -w '%{http_code}\n' -x 127.0.0.1:8080 http://127.0.0.1:8000/missing 2> /dev/null > ACTUAL |
121 |
diff EXPECTED ACTUAL |
122 |
echo 404 > EXPECTED |
123 |
! curl -f -w '%{http_code}\n' -x 127.0.0.1:8080 http://siliconforks.com/jscoverage-missing 2> /dev/null > ACTUAL |
124 |
diff EXPECTED ACTUAL |
125 |
|
126 |
## send it a server request |
127 |
#echo 400 > EXPECTED |
128 |
#! curl -f -w '%{http_code}\n' http://127.0.0.1:8080/ 2> /dev/null > ACTUAL |
129 |
#diff EXPECTED ACTUAL |
130 |
|
131 |
# kill $proxy_server_pid |
132 |
shutdown |
133 |
|
134 |
$VALGRIND jscoverage-server --no-highlight --port=8081 --proxy --report-dir=DIR --no-instrument=http://127.0.0.1:8000/1/ & |
135 |
proxy_server_pid=$! |
136 |
proxy_server_port=8081 |
137 |
|
138 |
sleep $delay |
139 |
|
140 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8081/' http://127.0.0.1:8000/script.js > OUT |
141 |
cat ../report.js recursive.expected/script.js | sed 's/@PREFIX@/http:\/\/127.0.0.1:8000\//g' | diff --strip-trailing-cr - OUT |
142 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8081/' http://127.0.0.1:8000/1/1.js | diff --strip-trailing-cr recursive/1/1.js - |
143 |
wget -q -O- -e 'http_proxy=http://127.0.0.1:8081/' http://127.0.0.1:8000/1/2/2.js | diff --strip-trailing-cr recursive/1/2/2.js - |