|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# run with base url argument like "http://clue.localhost" or "https://user:[email protected]" |
| 4 | +base=${1:-http://clue.localhost/} |
| 5 | +base=${base%/} |
| 6 | + |
| 7 | +# base url with any userinfo removed |
| 8 | +redir=$(echo $base | sed "s,://.*@,://,g") |
| 9 | + |
| 10 | +n=0 |
| 11 | +curl() { |
| 12 | + out=$($(which curl) "$@" 2>&1); |
| 13 | +} |
| 14 | +match() { |
| 15 | + n=$[$n+1] |
| 16 | + echo "$out" | grep "$@" >/dev/null && echo -n . || \ |
| 17 | + (echo ""; echo "Error in test $n: Unable to \"grep $@\" this output:"; echo "$out"; exit 1) || exit 1 |
| 18 | +} |
| 19 | + |
| 20 | +curl -v $base/ |
| 21 | +match "HTTP/.* 200" |
| 22 | +match -iP "Content-Type: text/html[;\r\n]" |
| 23 | + |
| 24 | +curl -v $base/index.html |
| 25 | +match "HTTP/.* 302" |
| 26 | +match -iP "Location: $redir/[\r\n]" |
| 27 | + |
| 28 | +curl -v $base/index.html/ |
| 29 | +match "HTTP/.* 404" |
| 30 | + |
| 31 | +curl -v $base/index |
| 32 | +match "HTTP/.* 404" |
| 33 | + |
| 34 | +curl -v $base/blog |
| 35 | +match "HTTP/.* 200" |
| 36 | +match -iP "Content-Type: text/html[;\r\n]" |
| 37 | + |
| 38 | +curl -v $base/blog.html |
| 39 | +match "HTTP/.* 302" |
| 40 | +match -iP "Location: $redir/blog[\r\n]" |
| 41 | + |
| 42 | +curl -v $base/blog/ |
| 43 | +match "HTTP/.* 302" |
| 44 | +match -iP "Location: $redir/blog[\r\n]" |
| 45 | + |
| 46 | +curl -v $base/2019 |
| 47 | +match "HTTP/.* 302" |
| 48 | +match -iP "Location: $redir/blog#2019[\r\n]" |
| 49 | + |
| 50 | +curl -v $base/2019/ |
| 51 | +match "HTTP/.* 302" |
| 52 | +match -iP "Location: $redir/blog#2019[\r\n]" |
| 53 | + |
| 54 | +curl -v $base/2000 |
| 55 | +match "HTTP/.* 404" |
| 56 | + |
| 57 | +curl -v $base/2000/ |
| 58 | +match "HTTP/.* 404" |
| 59 | + |
| 60 | +curl -v $base/2018/hello-world |
| 61 | +match "HTTP/.* 200" |
| 62 | +match -iP "Content-Type: text/html[;\r\n]" |
| 63 | + |
| 64 | +curl -v $base/2018/hello-world/ |
| 65 | +match "HTTP/.* 302" |
| 66 | +match -iP "Location: $redir/2018/hello-world[\r\n]" |
| 67 | + |
| 68 | +curl -v $base/contact |
| 69 | +match "HTTP/.* 200" |
| 70 | +match -iP "Content-Type: text/html[;\r\n]" |
| 71 | + |
| 72 | +curl -v $base/contact -X POST |
| 73 | +match "HTTP/.* 400" |
| 74 | + |
| 75 | +curl -v $base/contact --data name=A --data [email protected] --data company=ACME --data budget=None --data message= "Let's get in touch!" |
| 76 | +match "HTTP/.* 400" # name length |
| 77 | + |
| 78 | +curl -v $base/contact --data name=Alice --data email=alice --data company=ACME --data budget=None --data message="Let's get in touch!" |
| 79 | +match "HTTP/.* 400" # email invalid |
| 80 | + |
| 81 | +curl -v $base/contact --data name=Alice --data [email protected] --data company=ACME --data budget=A --data message= "Let's get in touch!" |
| 82 | +match "HTTP/.* 400" # budget invalid |
| 83 | + |
| 84 | +# curl -v $base/contact --data name=Alice --data [email protected] --data company= --data budget=Yes --data message="Let's get in touch!!" |
| 85 | +# match "HTTP/.* 302" # valid without company |
| 86 | + |
| 87 | +# curl -v $base/contact --data name=Alice --data [email protected] --data company=ACME --data budget=Yes --data message="Let's get in touch!!" |
| 88 | +# match "HTTP/.* 302" # valid with company |
| 89 | + |
| 90 | +curl -v $base/contact.html |
| 91 | +match "HTTP/.* 302" |
| 92 | +match -iP "Location: $redir/contact[\r\n]" |
| 93 | + |
| 94 | +curl -v $base/contact.php |
| 95 | +match "HTTP/.* 302" |
| 96 | +match -iP "Location: $redir/contact[\r\n]" |
| 97 | + |
| 98 | +curl -v $base/contact/ |
| 99 | +match "HTTP/.* 302" |
| 100 | +match -iP "Location: $redir/contact[\r\n]" |
| 101 | + |
| 102 | +echo "OK ($n)" |
0 commit comments