| 1 |
# |
| •2 |
# Part of the ht://Dig package <https://htdig.sourceforge.net/> |
| 3 |
# Copyright (c) 1999-2004 The ht://Dig Group |
| 4 |
# For copyright details, see the file COPYING in your distribution |
| 5 |
# or the GNU Library General Public License (LGPL) version 2 or later |
| 6 |
# <http://www.gnu.org/copyleft/lgpl.html> |
| 7 |
# |
| 8 |
# $Id: t_htdig_local,v 1.10 2004/05/28 13:15:30 lha Exp $ |
| 9 |
# |
| 10 |
|
| 11 |
# Tests the following config attributes: |
| 12 |
# bad_local_extensions |
| 13 |
# check_unique_md5 |
| 14 |
# content_classifier |
| 15 |
# database_dir |
| 16 |
# exclude_urls |
| 17 |
# limit_normalized |
| 18 |
# limit_urls_to |
| 19 |
# local_extensions |
| 20 |
# local_urls |
| 21 |
# local_urls_only |
| 22 |
# local_user_urls |
| 23 |
# max_hop_count |
| 24 |
# md5_db |
| 25 |
# mime_types |
| 26 |
# remove_default_doc |
| 27 |
# server_aliases |
| 28 |
# start_url |
| 29 |
|
| 30 |
test_functions_action=--start-apache |
| 31 |
. ./test_functions |
| 32 |
|
| 33 |
# set up config file with chosen non-default values |
| 34 |
config=$testdir/conf/htdig.conf.tmp |
| 35 |
cp $testdir/conf/htdig.conf2 $config |
| 36 |
|
| 37 |
################################################################################ |
| 38 |
#test for local-file-system access to <http://...> URLs |
| 39 |
|
| 40 |
/bin/rm -f var/htdig2/* |
| 41 |
set_attr start_url "http://localhost:7400/set1/ http://localhost:7400/set1/title.html?site3.html http://localhost:7400/set1/title.html?site4.html" |
| 42 |
# ban ite3.htm from query, but not from main URL. |
| 43 |
# Allow site3.html, but not title.html?site3.html |
| 44 |
set_attr bad_querystr ite3.htm |
| 45 |
expected='bad_local.htm' |
| 46 |
got=`$htdig "$@" -t -i -vv -c $config | grep "Bad local extension:" | sed -e"s-.*/--"` |
| 47 |
if [ "$expected" != "$got" ] |
| 48 |
then |
| 49 |
fail "first htdig: expected |
| 50 |
$expected |
| 51 |
but got |
| 52 |
$got" |
| 53 |
fi |
| 54 |
|
| 55 |
expected='db.docdb |
| 56 |
db.docs |
| 57 |
db.docs.index |
| 58 |
db.excerpts |
| 59 |
db.worddump |
| 60 |
db.words.db |
| 61 |
db.words.db_weakcmpr' |
| 62 |
got=`/bin/ls var/htdig2` |
| 63 |
if [ "$expected" != "$got" ] |
| 64 |
then |
| 65 |
fail "created files: expected |
| 66 |
$expected |
| 67 |
but got |
| 68 |
$got" |
| 69 |
fi |
| 70 |
|
| 71 |
$htpurge -c $config |
| 72 |
|
| 73 |
# should http://localhost:7400/set1/sub%2520dir be purged? |
| 74 |
expected='http://localhost:7400/set1/ |
| 75 |
http://localhost:7400/set1/bad_local.htm |
| 76 |
http://localhost:7400/set1/script.html |
| 77 |
http://localhost:7400/set1/site%201.html |
| 78 |
http://localhost:7400/set1/site2.html |
| 79 |
http://localhost:7400/set1/site3.html |
| 80 |
http://localhost:7400/set1/site4.html |
| 81 |
http://localhost:7400/set1/sub%2520dir/ |
| 82 |
http://localhost:7400/set1/sub%2520dir/empty%20file.html |
| 83 |
http://localhost:7400/set1/title.html |
| 84 |
http://localhost:7400/set1/title.html?site4.html' |
| 85 |
|
| 86 |
got=`./document -c $config -u | sort` |
| 87 |
|
| 88 |
if [ "$expected" != "$got" ] |
| 89 |
then |
| 90 |
fail "first document: expected |
| 91 |
$expected |
| 92 |
but got |
| 93 |
$got" |
| 94 |
fi |
| 95 |
|
| 96 |
set_attr bad_query_str |
| 97 |
|
| 98 |
|
| 99 |
################################################################################ |
| 100 |
# limit_urls_to applies before server alias expansion |
| 101 |
set_attr start_url http://myhost/set1/index.html |
| 102 |
set_attr limit_urls_to "http://myhost/set1/" |
| 103 |
set_attr server_aliases myhost=localhost:7400 |
| 104 |
$htdig "$@" -t -i -c $config || fail "couldn't dig second time" |
| 105 |
$htpurge -c $config || fail "couldn't purge second time" |
| 106 |
# only start_url uses alias, so only it passes the limit_urls_to test |
| 107 |
expected='http://localhost:7400/set1/' |
| 108 |
|
| 109 |
got=`./document -c $config -u | sort` |
| 110 |
|
| 111 |
if [ "$expected" != "$got" ] |
| 112 |
then |
| 113 |
fail "second document: expected |
| 114 |
$expected |
| 115 |
but got |
| 116 |
$got" |
| 117 |
fi |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
################################################################################ |
| 122 |
# Check remote URLs not retrieved if local_urls_only specified |
| 123 |
set_attr local_urls_only true |
| 124 |
set_attr remove_default_doc site2.html |
| 125 |
# Note: local_urls_only doesn't handle directories without a default doc |
| 126 |
set_attr local_default_doc "site2.html empty%20file.html" |
| 127 |
set_attr start_url http://myhost/set1/index.html |
| 128 |
# don't care what the aliased URL is; only check the normalized one |
| 129 |
set_attr limit_urls_to |
| 130 |
set_attr limit_normalized "http://localhost:7400/set1/" |
| 131 |
set_attr server_aliases myhost=localhost:7400 |
| 132 |
$htdig "$@" -t -i -c $config || fail "couldn't dig third time" |
| 133 |
$htpurge -c $config || fail "couldn't purge third time" |
| 134 |
expected='http://localhost:7400/set1/ |
| 135 |
http://localhost:7400/set1/index.html |
| 136 |
http://localhost:7400/set1/script.html |
| 137 |
http://localhost:7400/set1/site%201.html |
| 138 |
http://localhost:7400/set1/site3.html |
| 139 |
http://localhost:7400/set1/site4.html |
| 140 |
http://localhost:7400/set1/sub%2520dir/ |
| 141 |
http://localhost:7400/set1/title.html' |
| 142 |
|
| 143 |
got=`./document -c $config -u | sort` |
| 144 |
|
| 145 |
if [ "$expected" != "$got" ] |
| 146 |
then |
| 147 |
fail "third document: expected |
| 148 |
$expected |
| 149 |
but got |
| 150 |
$got" |
| 151 |
fi |
| 152 |
set_attr remove_default_doc index.html |
| 153 |
set_attr local_urls_only false |
| 154 |
set_attr limit_normalized |
| 155 |
|
| 156 |
|
| 157 |
################################################################################ |
| 158 |
#test for <file:///...> URLs |
| 159 |
|
| 160 |
expected='' # no "bad local" extensions for file:/// |
| 161 |
# Check only one "title.html" found... |
| 162 |
set_attr check_unique_md5 true |
| 163 |
set_attr start_url "http://localhost:7400/set1/title.html file://$PWD/htdocs/set1/" |
| 164 |
set_attr limit_urls_to '${start_url}' |
| 165 |
got=`$htdig "$@" -t -i -vv -c $config | grep "Bad local extension:" | sed -e"s-.*/--"` |
| 166 |
if [ "$expected" != "$got" ] |
| 167 |
then |
| 168 |
fail "fourth htdig: expected |
| 169 |
$expected |
| 170 |
but got |
| 171 |
$got" |
| 172 |
fi |
| 173 |
|
| 174 |
expected='db.docdb |
| 175 |
db.docs |
| 176 |
db.docs.index |
| 177 |
db.excerpts |
| 178 |
db.md5hash.db |
| 179 |
db.worddump |
| 180 |
db.words.db |
| 181 |
db.words.db_weakcmpr' |
| 182 |
got=`/bin/ls var/htdig2` |
| 183 |
if [ "$expected" != "$got" ] |
| 184 |
then |
| 185 |
fail "fourth created files: expected |
| 186 |
$expected |
| 187 |
but got |
| 188 |
$got" |
| 189 |
fi |
| 190 |
|
| 191 |
$htpurge -c $config || fail "couldn't purge fourth time" |
| 192 |
|
| 193 |
expected='file:///set1/bad_local.htm |
| 194 |
file:///set1/index.html |
| 195 |
file:///set1/script.html |
| 196 |
file:///set1/site%201.html |
| 197 |
file:///set1/site2.html |
| 198 |
file:///set1/site3.html |
| 199 |
file:///set1/site4.html |
| 200 |
file:///set1/sub%2520dir/empty%20file.html |
| 201 |
/title.html' |
| 202 |
|
| 203 |
got=`./document -c $config -u | sed "s#${PWD}/htdocs##" | sort | sed "s#.*/title.html#/title.html#"` |
| 204 |
|
| 205 |
if [ "$expected" != "$got" ] |
| 206 |
then |
| 207 |
fail "fourth document: expected |
| 208 |
$expected |
| 209 |
but got |
| 210 |
$got" |
| 211 |
fi |
| 212 |
|
| 213 |
|
| 214 |
################################################################################ |
| 215 |
#test mime types handling |
| 216 |
|
| 217 |
expected='' # no "bad local" extensions for file:/// |
| 218 |
set_attr max_hop_count 1 # removes "empty%20file.html" |
| 219 |
set_attr exclude_urls "site4.html script.html site[3].html" |
| 220 |
set_attr bad_extensions .foo |
| 221 |
set_attr local_urls_only false |
| 222 |
|
| 223 |
rm -f var/htdig2/db.md5hash.db |
| 224 |
set_attr md5_db '${database_base}.md5.db' |
| 225 |
|
| 226 |
set_attr mime_types $PWD/mime-without-htm |
| 227 |
set_attr content_classifier $PWD/say-text |
| 228 |
echo 'text/html html' > mime-without-htm |
| 229 |
echo '#!/bin/sh |
| 230 |
echo text/plain' > say-text |
| 231 |
chmod 700 say-text |
| 232 |
got=`$htdig "$@" -t -i -vv -c $config | grep "MIME type:" | sed -e"s-.*/--"` |
| 233 |
if [ "$expected" != "$got" ] |
| 234 |
then |
| 235 |
fail "fifth htdig: expected |
| 236 |
$expected |
| 237 |
but got |
| 238 |
$got" |
| 239 |
fi |
| 240 |
|
| 241 |
expected='db.docdb |
| 242 |
db.docs |
| 243 |
db.docs.index |
| 244 |
db.excerpts |
| 245 |
db.md5.db |
| 246 |
db.worddump |
| 247 |
db.words.db |
| 248 |
db.words.db_weakcmpr' |
| 249 |
got=`/bin/ls var/htdig2` |
| 250 |
if [ "$expected" != "$got" ] |
| 251 |
then |
| 252 |
fail "fifth created files: expected |
| 253 |
$expected |
| 254 |
but got |
| 255 |
$got" |
| 256 |
fi |
| 257 |
|
| 258 |
$htpurge -c $config || fail "couldn't purge fifth time" |
| 259 |
|
| 260 |
expected='file:///set1/bad_local.htm |
| 261 |
file:///set1/index.html |
| 262 |
file:///set1/nph-location.cgi |
| 263 |
file:///set1/site%201.html |
| 264 |
file:///set1/site2.html |
| 265 |
file:///set1/site3.html |
| 266 |
file:///set1/title.html' |
| 267 |
|
| 268 |
got=`./document -c $config -u | sed "s#${PWD}/htdocs##" | sort` |
| 269 |
|
| 270 |
if [ "$expected" != "$got" ] |
| 271 |
then |
| 272 |
fail "fifth document: expected |
| 273 |
$expected |
| 274 |
but got |
| 275 |
$got" |
| 276 |
fi |
| 277 |
|
| 278 |
################################################################################ |
| 279 |
expected='' # no "bad local" extensions for file:/// |
| 280 |
set_attr max_hop_count # removes "empty%20file.html" |
| 281 |
set_attr exclude_urls /CVS/ |
| 282 |
set_attr valid_extensions ".foo .html" |
| 283 |
set_attr bad_extensions |
| 284 |
|
| 285 |
set_attr mime_types $PWD/mime-without-htm |
| 286 |
set_attr content_classifier $PWD/say-text |
| 287 |
echo 'text/html html' > mime-without-htm |
| 288 |
echo '#!/bin/sh |
| 289 |
echo text/plain' > say-text |
| 290 |
chmod 700 say-text |
| 291 |
got=`$htdig "$@" -t -i -vv -c $config | grep "MIME type:" | sed -e"s-.*/--"` |
| 292 |
if [ "$expected" != "$got" ] |
| 293 |
then |
| 294 |
fail "sixth htdig: expected |
| 295 |
$expected |
| 296 |
but got |
| 297 |
$got" |
| 298 |
fi |
| 299 |
|
| 300 |
$htpurge -c $config || fail "couldn't purge sixth time" |
| 301 |
|
| 302 |
expected='file:///set1/index.html |
| 303 |
file:///set1/nph-location.foo |
| 304 |
file:///set1/script.html |
| 305 |
file:///set1/site%201.html |
| 306 |
file:///set1/site2.html |
| 307 |
file:///set1/site3.html |
| 308 |
file:///set1/site4.html |
| 309 |
file:///set1/sub%2520dir/empty%20file.html |
| 310 |
file:///set1/title.html' |
| 311 |
|
| 312 |
got=`./document -c $config -u | sed "s#${PWD}/htdocs##" | sort` |
| 313 |
|
| 314 |
if [ "$expected" != "$got" ] |
| 315 |
then |
| 316 |
fail "sixth document: expected |
| 317 |
$expected |
| 318 |
but got |
| 319 |
$got" |
| 320 |
fi |
| 321 |
|
| 322 |
|
| 323 |
################################################################################ |
| 324 |
set_attr local_urls_only |
| 325 |
set_attr local_urls "http://somewhere/=$PWD/htdocs/" |
| 326 |
set_attr local_user_urls "http://somewhere/=$PWD/,/set1/" |
| 327 |
set_attr start_url "http://somewhere/~htdocs/" |
| 328 |
|
| 329 |
set_attr valid_extensions |
| 330 |
set_attr local_default_doc index.html |
| 331 |
set_attr remove_default_doc index.html |
| 332 |
|
| 333 |
$htdig "$@" -t -i -c $config || fail "couldn't dig seventh time" |
| 334 |
$htpurge -c $config || fail "couldn't purge seventh time" |
| 335 |
|
| 336 |
#local_urls_only can't handle .../~htdocs/sub%2520dir/empty%20file.html |
| 337 |
expected='http://somewhere/~htdocs/ |
| 338 |
http://somewhere/~htdocs/script.html |
| 339 |
http://somewhere/~htdocs/site%201.html |
| 340 |
http://somewhere/~htdocs/site2.html |
| 341 |
http://somewhere/~htdocs/site3.html |
| 342 |
http://somewhere/~htdocs/site4.html |
| 343 |
http://somewhere/~htdocs/title.html' |
| 344 |
|
| 345 |
got=`./document -c $config -u | sort` |
| 346 |
|
| 347 |
if [ "$expected" != "$got" ] |
| 348 |
then |
| 349 |
fail "seventh document: expected |
| 350 |
$expected |
| 351 |
but got |
| 352 |
$got" |
| 353 |
fi |
| 354 |
|
| 355 |
|
| 356 |
/bin/rm mime-without-htm say-text |
| 357 |
|
| 358 |
test_functions_action=--stop-apache |
| 359 |
. ./test_functions |