Skip to content

Instantly share code, notes, and snippets.

@seanstickle
Forked from RichardBronosky/README.txt
Created June 4, 2012 18:02
Show Gist options
  • Save seanstickle/2869898 to your computer and use it in GitHub Desktop.
Save seanstickle/2869898 to your computer and use it in GitHub Desktop.
Apache mod_rewrite unit tests
ReUnit - Unit tests for HTTP Redirects.
# ATTENTION: Please do not think badly of me for this code!
# I REALLY WANT TO REDO THIS IN PYTHON AND USE YAML!!!
# It started out as a oneliner! https://gist.github.com/1158733/2f9aa7e2db9ccfbda4669c2102daebacf8a04284#L6
Contents:
reunit.sh - This is the main script and the purpose of this repo. It reads a text file full of tests.
tests.txt - This holds the tests that will be run. It's format is Identical to the output of reunit.sh an urltest
urltest - This is the test utility used by reunit.sh. It was extracted into an executable so that it could be used for single tests or creating entries for tests.txt
Examples:
./reunit.sh tests.txt
./urltest http://google.com
# Define this for your convenience...
urltest() { for url in $@; do ./urltest $url; done }
# Then you don't have to use ./ and you can test multiple domains
urltest http://example.com http://google.com
#!/usr/bin/env bash
# ATTENTION: Please do not think badly of me for this code!
# I REALLY WANT TO REDO THIS IN PYTHON AND USE YAML!!!
# It started out as a oneliner! https://gist.github.com/1158733/2f9aa7e2db9ccfbda4669c2102daebacf8a04284#L6
cat > /dev/stderr << EOF
# The first line in each block tells you the URL requested.
# The rest begin with the response's HTTP status code. (301=Permanent Redirect, 302=Temporary Redirect, etc.)
# The lines with 300 class responses have the URL of the Location header.
# The lines with 200, 400, or 500 class responses have the URL requested.
# I REALLY WANT TO REDO THIS IN PYTHON AND USE YAML!!!
EOF
rm /tmp/reunit.latest.txt /tmp/cookies.*.txt
echo "#### $(date) ####" > /tmp/reunit.latest.txt
while read line; do
# skip lines that do not begin with http
echo "$line" | grep -qE '^\s*http' || continue;
url="$line"
./urltest "$url" | tee -a /tmp/reunit.latest.txt
done < $1
#diff -u $1 /tmp/reunit.latest.txt | tee /tmp/reunit.diff
vimdiff -n $1 /tmp/reunit.latest.txt
# the following command is useful for replacing an env component with a variable
# :.,$s/test\./${env}/
#awk '/^http/{sub(".*://",""); sub("/.*",""); printf "%s ", $0}' tests.txt
#### Test Homepages ####
http://www.test.palmbeachpost.com/
# Checking Firefox...
> 200 http://www.test.palmbeachpost.com/
# Checking iPhone...
> 302 http://wap.pbpost.com/
> 302 http://wap.pbpost.com/post/index.htm
> 200 http://wap.pbpost.com/post/index.htm
http://test.palmbeachpost.com/
# Checking Firefox...
> 302 http://www.test.palmbeachpost.com/
> 200 http://www.test.palmbeachpost.com/
# Checking iPhone...
> 302 http://wap.pbpost.com/post/
> 200 http://wap.pbpost.com/post/
http://www.test.pbpost.com
# Checking Firefox...
> 301 http://www.test.palmbeachpost.com/
> 200 http://www.test.palmbeachpost.com/
# Checking iPhone...
> 301 http://www.test.palmbeachpost.com/
> 302 http://wap.pbpost.com/
> 302 http://wap.pbpost.com/post/index.htm
> 200 http://wap.pbpost.com/post/index.htm
http://m.test.pbpost.com
# Checking Firefox...
> 301 http://www.test.palmbeachpost.com/
> 200 http://www.test.palmbeachpost.com/
# Checking iPhone...
> 301 http://www.test.palmbeachpost.com/
> 302 http://wap.pbpost.com/post/
> 200 http://wap.pbpost.com/post/
http://www.test.pbpulse.com/
# Checking Firefox...
> 200 http://www.test.pbpulse.com/
# Checking iPhone...
> 302 http://wap.pbpulse.com/
> 302 http://wap.pbpulse.com/pulse/index.htm
> 200 http://wap.pbpulse.com/pulse/index.htm
http://test.pbpulse.com/
# Checking Firefox...
> 302 http://www.test.pbpulse.com/
> 200 http://www.test.pbpulse.com/
# Checking iPhone...
> 302 http://wap.pbpulse.com/pulse/
> 200 http://wap.pbpulse.com/pulse/
#### Test story redirects ####
http://www.test.palmbeachpost.com/ap/ap/top-news/hurricane-warning-issued-for-mexico-ahead-of-bud/nN7LP/
# Checking Firefox...
> 200 http://www.test.palmbeachpost.com/ap/ap/top-news/hurricane-warning-issued-for-mexico-ahead-of-bud/nN7LP/
# Checking iPhone...
> 302 http://wap.pbpost.com/site.htm?targetUrl=http://www.test.palmbeachpost.com/ap/ap/top-news/hurricane-warning-issued-for-mexico-ahead-of-bud/nN7LP/
> 302 http://wap.pbpost.com/post/pm_115686/contentdetail.htm?contentguid=oiiomTIX
> 200 http://wap.pbpost.com/post/pm_115686/contentdetail.htm?contentguid=oiiomTIX
http://test.palmbeachpost.com/ap/ap/top-news/hurricane-warning-issued-for-mexico-ahead-of-bud/nN7LP/
# Checking Firefox...
> 302 http://www.test.palmbeachpost.com/ap/ap/top-news/hurricane-warning-issued-for-mexico-ahead-of-bud/nN7LP/
> 200 http://www.test.palmbeachpost.com/ap/ap/top-news/hurricane-warning-issued-for-mexico-ahead-of-bud/nN7LP/
# Checking iPhone...
> 302 http://wap.pbpost.com/site.htm?targetUrl=http://www.test.palmbeachpost.com/ap/ap/top-news/hurricane-warning-issued-for-mexico-ahead-of-bud/nN7LP/
> 302 http://wap.pbpost.com/post/pm_115686/contentdetail.htm?contentguid=oiiomTIX
> 200 http://wap.pbpost.com/post/pm_115686/contentdetail.htm?contentguid=oiiomTIX
http://www.test.pbpulse.com/news/lifestyles/health/thymes-time-acne-remedy-may-be-coming-soon/nMYJF/
# Checking Firefox...
> 200 http://www.test.pbpulse.com/news/lifestyles/health/thymes-time-acne-remedy-may-be-coming-soon/nMYJF/
# Checking iPhone...
> 302 http://wap.pbpulse.com/site.htm?targetUrl=http://www.test.pbpulse.com/news/lifestyles/health/thymes-time-acne-remedy-may-be-coming-soon/nMYJF/
> 302 http://wap.pbpulse.com/pulse/pm_20569/contentdetail.htm?contentguid=Dy3khUhj
> 200 http://wap.pbpulse.com/pulse/pm_20569/contentdetail.htm?contentguid=Dy3khUhj
http://test.pbpulse.com/news/lifestyles/health/thymes-time-acne-remedy-may-be-coming-soon/nMYJF/
# Checking Firefox...
> 302 http://www.test.pbpulse.com/news/lifestyles/health/thymes-time-acne-remedy-may-be-coming-soon/nMYJF/
> 200 http://www.test.pbpulse.com/news/lifestyles/health/thymes-time-acne-remedy-may-be-coming-soon/nMYJF/
# Checking iPhone...
> 302 http://wap.pbpulse.com/site.htm?targetUrl=http://www.test.pbpulse.com/news/lifestyles/health/thymes-time-acne-remedy-may-be-coming-soon/nMYJF/
> 302 http://wap.pbpulse.com/pulse/pm_20569/contentdetail.htm?contentguid=Dy3khUhj
> 200 http://wap.pbpulse.com/pulse/pm_20569/contentdetail.htm?contentguid=Dy3khUhj
#### Test site preference cookie ####
http://test.palmbeachpost.com/mobilesite?return=/
# Checking Firefox...
# The combination of Firefox and mobilesite is really a contrived test. I don't care if it has a cookie or not.
> 302 http://m.test.palmbeachpost.com/ Set-Cookie: nmredir=false;
> 302 http://wap.pbpost.com/post/
> 200 http://wap.pbpost.com/post/
# Checking iPhone...
> 302 http://wap.pbpost.com/post/
> 200 http://wap.pbpost.com/post/
http://test.palmbeachpost.com/fullsite?return=/
# Checking Firefox...
> 302 http://www.test.palmbeachpost.com/?nmredir=true Set-Cookie: nmredir=true;
> 200 http://www.test.palmbeachpost.com/?nmredir=true
# Checking iPhone...
> 302 http://www.test.palmbeachpost.com/?nmredir=true Set-Cookie: nmredir=true;
> 200 http://www.test.palmbeachpost.com/?nmredir=true
# NOTICE: This is the 2nd mobile site check & should set a cookie
http://test.palmbeachpost.com/mobilesite?return=/
# Checking Firefox...
# The combination of Firefox and mobilesite is really a contrived test. I don't care if it has a cookie or not.
> 302 http://m.test.palmbeachpost.com/ Set-Cookie: nmredir=false;
> 302 http://wap.pbpost.com/post/
> 200 http://wap.pbpost.com/post/
# Checking iPhone...
> 302 http://m.test.palmbeachpost.com/ Set-Cookie: nmredir=false;
> 302 http://wap.pbpost.com/post/
> 200 http://wap.pbpost.com/post/
http://test.pbpulse.com/mobilesite?return=/
# Checking Firefox...
# The combination of Firefox and mobilesite is really a contrived test. I don't care if it has a cookie or not.
> 302 http://m.test.pbpulse.com/ Set-Cookie: nmredir=false;
> 302 http://wap.pbpulse.com/pulse/
> 200 http://wap.pbpulse.com/pulse/
# Checking iPhone...
> 302 http://wap.pbpulse.com/pulse/
> 200 http://wap.pbpulse.com/pulse/
http://test.pbpulse.com/fullsite?return=/
# Checking Firefox...
> 302 http://www.test.pbpulse.com/?nmredir=true Set-Cookie: nmredir=true;
> 200 http://www.test.pbpulse.com/?nmredir=true
# Checking iPhone...
> 302 http://www.test.pbpulse.com/?nmredir=true Set-Cookie: nmredir=true;
> 200 http://www.test.pbpulse.com/?nmredir=true
# NOTICE: This is the 2nd mobile site check & should set a cookie
http://test.pbpulse.com/mobilesite?return=/
# Checking Firefox...
# The combination of Firefox and mobilesite is really a contrived test. I don't care if it has a cookie or not.
> 302 http://m.test.pbpulse.com/ Set-Cookie: nmredir=false;
> 302 http://wap.pbpulse.com/pulse/
> 200 http://wap.pbpulse.com/pulse/
# Checking iPhone...
> 302 http://m.test.pbpulse.com/ Set-Cookie: nmredir=false;
> 302 http://wap.pbpulse.com/pulse/
> 200 http://wap.pbpulse.com/pulse/
#### Test m-dot redirects ####
http://m.test.palmbeachpost.com
# Checking Firefox...
> 302 http://wap.pbpost.com/post/
> 200 http://wap.pbpost.com/post/
# Checking iPhone...
> 302 http://wap.pbpost.com/post/
> 200 http://wap.pbpost.com/post/
http://m.test.pbpost.com
# Checking Firefox...
> 301 http://www.test.palmbeachpost.com/
> 200 http://www.test.palmbeachpost.com/
# Checking iPhone...
> 301 http://www.test.palmbeachpost.com/
> 302 http://wap.pbpost.com/post/
> 200 http://wap.pbpost.com/post/
http://m.test.palmbeachpost.com/ap/ap/top-news/hurricane-warning-issued-for-mexico-ahead-of-bud/nN7LP/
# Checking Firefox...
> 302 http://wap.pbpost.com/post/
> 200 http://wap.pbpost.com/post/
# Checking iPhone...
> 302 http://wap.pbpost.com/site.htm?targetUrl=http://www.test.palmbeachpost.com/ap/ap/top-news/hurricane-warning-issued-for-mexico-ahead-of-bud/nN7LP/
> 302 http://wap.pbpost.com/post/pm_115686/contentdetail.htm?contentguid=oiiomTIX
> 200 http://wap.pbpost.com/post/pm_115686/contentdetail.htm?contentguid=oiiomTIX
http://m.test.pbpulse.com
# Checking Firefox...
> 302 http://wap.pbpulse.com/pulse/
> 200 http://wap.pbpulse.com/pulse/
# Checking iPhone...
> 302 http://wap.pbpulse.com/pulse/
> 200 http://wap.pbpulse.com/pulse/
#### Test Radio ####
http://test.wsbradio.com/fullsite?return=%2Fap%2Fap%2Fgeorgia%2Frainy-memorial-day-forecast-for-southeast-coast%2FnN7xr%2F
# Checking Firefox...
> 302 http://www.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/?nmredir=true Set-Cookie: nmredir=true;
> 200 http://www.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/?nmredir=true
# Checking iPhone...
> 302 http://www.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/?nmredir=true Set-Cookie: nmredir=true;
> 200 http://www.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/?nmredir=true
http://test.wsbradio.com/mobilesite?return=%2Fap%2Fap%2Fgeorgia%2Frainy-memorial-day-forecast-for-southeast-coast%2FnN7xr%2F
# Checking Firefox...
# The combination of Firefox and mobilesite is really a contrived test. I don't care if it has a cookie or not.
> 302 http://m.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/ Set-Cookie: nmredir=false;
> 200 http://m.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/
# Checking iPhone...
> 302 http://m.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/ Set-Cookie: nmredir=false;
> 200 http://m.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/
http://test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/
# Checking Firefox...
> 302 http://www.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/
> 200 http://www.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/
# Checking iPhone...
> 302 http://m.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/
> 200 http://m.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/
http://www.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/
# Checking Firefox...
> 200 http://www.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/
# Checking iPhone...
> 302 http://m.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/
> 200 http://m.test.wsbradio.com/ap/ap/georgia/rainy-memorial-day-forecast-for-southeast-coast/nN7xr/
#### Test Clark Howard ####
http://www.test.clarkhoward.com/
# Checking Firefox...
> 200 http://www.test.clarkhoward.com/
# Checking iPhone...
> 200 http://www.test.clarkhoward.com/
http://m.test.clarkhoward.com/
# Checking Firefox...
> 302 http://m.test.clarkhoward.com/mobile/
> 200 http://m.test.clarkhoward.com/mobile/
# Checking iPhone...
> 302 http://m.test.clarkhoward.com/mobile/
> 200 http://m.test.clarkhoward.com/mobile/
http://test.clarkhoward.com/
# Checking Firefox...
> 302 http://www.test.clarkhoward.com/
> 200 http://www.test.clarkhoward.com/
# Checking iPhone...
> 302 http://m.test.clarkhoward.com/
> 302 http://m.test.clarkhoward.com/mobile/
> 200 http://m.test.clarkhoward.com/mobile/
# Clark doesn't use mobilesite/fullsite. This this is merely an indicator of configs being included that shouldn't be.
http://test.clarkhoward.com/fullsite?return=/
# Checking Firefox...
> 404 http://test.clarkhoward.com/fullsite?return=/
# Checking iPhone...
> 404 http://test.clarkhoward.com/fullsite?return=/
http://www.test.clarkhoward.com/news/clark-howard/health-health-care/costco-sell-individual-health-insurance-mortgages/nNy2X/
# Checking Firefox...
> 200 http://www.test.clarkhoward.com/news/clark-howard/health-health-care/costco-sell-individual-health-insurance-mortgages/nNy2X/
# Checking iPhone...
> 200 http://www.test.clarkhoward.com/news/clark-howard/health-health-care/costco-sell-individual-health-insurance-mortgages/nNy2X/
#### Test TV ####
http://www.test.whiotv.com/
# Checking Firefox...
> 200 http://www.test.whiotv.com/
# Checking iPhone...
> 302 http://m.test.whiotv.com/
> 302 http://wap.whiotv.com/?targetUrl=http://www.test.whiotv.com/
> 302 http://wap.whiotv.com/
> 302 http://wap.whiotv.com/wap/pda/stations/4/
> 200 http://wap.whiotv.com/wap/pda/stations/4/
http://test.whiotv.com/
# Checking Firefox...
> 302 http://www.test.whiotv.com/
> 200 http://www.test.whiotv.com/
# Checking iPhone...
> 302 http://wap.whiotv.com
> 302 http://wap.whiotv.com/wap/pda/stations/4/
> 200 http://wap.whiotv.com/wap/pda/stations/4/
# To mimic production, the first 302 should have site.htm in it (see reference #2 below)
# I have proven that it works without site.html (see reference #1 below)
# However, the 302 should go directly to wap.whiotv.com without going through m.test.whiotv.com. I don't know how it will affect production the way it is.
#
http://www.test.whiotv.com/news/news/local/2-men-taken-custody-after-beavercreek-crash/nNz8j/
# Checking Firefox...
> 200 http://www.test.whiotv.com/news/news/local/2-men-taken-custody-after-beavercreek-crash/nNz8j/
# Checking iPhone...
> 302 http://m.test.whiotv.com/news/news/local/2-men-taken-custody-after-beavercreek-crash/nNz8j/
> 302 http://wap.whiotv.com/?targetUrl=http://www.test.whiotv.com/news/news/local/2-men-taken-custody-after-beavercreek-crash/nNz8j/
> 302 http://wap.whiotv.com/
> 302 http://wap.whiotv.com/wap/pda/stations/4/
> 200 http://wap.whiotv.com/wap/pda/stations/4/
#### This is just for reference ####
#1
http://wap.whiotv.com/?targetUrl=http://www.whiotv.com/news/news/local/police-get-mixed-bag-ovi-checkpoint/nPFyW/
# Checking Firefox...
> 200 http://wap.whiotv.com/?targetUrl=http://www.whiotv.com/news/news/local/police-get-mixed-bag-ovi-checkpoint/nPFyW/
# Checking iPhone...
> 200 http://wap.whiotv.com/?targetUrl=http://www.whiotv.com/news/news/local/police-get-mixed-bag-ovi-checkpoint/nPFyW/
#2
http://www.whiotv.com/news/news/local/police-get-mixed-bag-ovi-checkpoint/nPFyW/
# Checking Firefox...
> 200 http://www.whiotv.com/news/news/local/police-get-mixed-bag-ovi-checkpoint/nPFyW/
# Checking iPhone...
> 302 http://wap.whiotv.com/site.htm?targetUrl=http://www.whiotv.com/news/news/local/police-get-mixed-bag-ovi-checkpoint/nPFyW/
> 200 http://wap.whiotv.com/site.htm?targetUrl=http://www.whiotv.com/news/news/local/police-get-mixed-bag-ovi-checkpoint/nPFyW/
#3
http://www.whiotv.com/news/news/local/not/found/story/
# Checking Firefox...
> 404 http://www.whiotv.com/news/news/local/not/found/story/
# Checking iPhone...
> 302 http://wap.whiotv.com/site.htm?targetUrl=http://www.whiotv.com/news/news/local/not/found/story/
> 302 http://wap.whiotv.com/
> 302 http://wap.whiotv.com/wap/pda/stations/4/
> 200 http://wap.whiotv.com/wap/pda/stations/4/
#!/usr/bin/env bash
# ATTENTION: Please do not think badly of me for this code!
# I REALLY WANT TO REDO THIS IN PYTHON AND USE YAML!!!
# It started out as a oneliner! https://gist.github.com/1158733/2f9aa7e2db9ccfbda4669c2102daebacf8a04284#L6
# In the interest of easy of use, I highly suggest defining and using this function at your shell
# urltest() { for url in $@; do ./urltest $url; done }
# Use that function like so...
# urltest http://example.com http://google.com
check(){
curl -sL -o /dev/null -D /dev/stdout -b /tmp/cookies.$1.txt -c /tmp/cookies.$1.txt -A $* | \
# remove dos line endings
tr -d '\r' | \
# simplify the output
awk -v url="${@: -1}" '
tolower($1) ~ /^http\// {
status=$2
};
tolower($1) ~ /^location/ {
url=$2
};
tolower($1) ~ /^set-cookie/ {
cookie=$2
};
/^$/{
#print "########################################";
if(match(cookie,"nmredir")){
output=" Set-Cookie: " cookie;
}else{
output=""
};
#print "status: " status;
#print "url: " url;
#print "output: " output;
print " > " status " " url " " output;
#status=""
cookie=""
};
'
}
docheck(){
url="${@}"
echo $url;
for agent in Firefox iPhone; do
echo " # Checking $agent...";
check $agent $url
done
echo;
}
docheck "${@}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment