summaryrefslogtreecommitdiffstats
path: root/debian/htdig/htdig-3.2.0b6/test/t_htdig_local
blob: 8405ee074faaf47f6abc30116d48ebbf98a2e31d (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#
# Part of the ht://Dig package   <http://www.htdig.org/>
# Copyright (c) 1999-2004 The ht://Dig Group
# For copyright details, see the file COPYING in your distribution
# or the GNU Library General Public License (LGPL) version 2 or later
# <http://www.gnu.org/copyleft/lgpl.html>
#
# $Id: t_htdig_local,v 1.10 2004/05/28 13:15:30 lha Exp $
#

# Tests the following config attributes:
#	bad_local_extensions
#	check_unique_md5
#	content_classifier
#	database_dir
#	exclude_urls
#	limit_normalized
#	limit_urls_to
#	local_extensions
#	local_urls
#	local_urls_only
#	local_user_urls
#	max_hop_count
#	md5_db
#	mime_types
#	remove_default_doc
#	server_aliases
#	start_url

test_functions_action=--start-apache
. ./test_functions

# set up config file with chosen non-default values
config=$testdir/conf/htdig.conf.tmp
cp $testdir/conf/htdig.conf2 $config

################################################################################
#test for local-file-system access to <http://...> URLs

/bin/rm -f var/htdig2/*
set_attr start_url "http://localhost:7400/set1/ http://localhost:7400/set1/title.html?site3.html http://localhost:7400/set1/title.html?site4.html"
# ban  ite3.htm from query, but not from main URL.
# Allow site3.html, but not title.html?site3.html
set_attr bad_querystr ite3.htm
expected='bad_local.htm'
got=`$htdig "$@" -t -i -vv -c $config | grep "Bad local extension:" | sed -e"s-.*/--"`
if [ "$expected" != "$got" ]
then
	fail "first htdig: expected 
$expected
but got
$got"
fi

expected='db.docdb
db.docs
db.docs.index
db.excerpts
db.worddump
db.words.db
db.words.db_weakcmpr'
got=`/bin/ls var/htdig2`
if [ "$expected" != "$got" ]
then
	fail "created files: expected 
$expected
but got
$got"
fi

$htpurge -c $config

# should  http://localhost:7400/set1/sub%2520dir  be purged?
expected='http://localhost:7400/set1/
http://localhost:7400/set1/bad_local.htm
http://localhost:7400/set1/script.html
http://localhost:7400/set1/site%201.html
http://localhost:7400/set1/site2.html
http://localhost:7400/set1/site3.html
http://localhost:7400/set1/site4.html
http://localhost:7400/set1/sub%2520dir/
http://localhost:7400/set1/sub%2520dir/empty%20file.html
http://localhost:7400/set1/title.html
http://localhost:7400/set1/title.html?site4.html'

got=`./document -c $config -u | sort`

if [ "$expected" != "$got" ]
then
	fail "first document: expected 
$expected
but got
$got"
fi

set_attr bad_query_str


################################################################################
# limit_urls_to applies before server alias expansion
set_attr start_url http://myhost/set1/index.html
set_attr limit_urls_to "http://myhost/set1/"
set_attr server_aliases myhost=localhost:7400
$htdig "$@" -t -i -c $config	|| fail "couldn't dig second time"
$htpurge -c $config		|| fail "couldn't purge second time"
# only start_url uses alias, so only it passes the  limit_urls_to  test
expected='http://localhost:7400/set1/'

got=`./document -c $config -u | sort`

if [ "$expected" != "$got" ]
then
	fail "second document: expected 
$expected
but got
$got"
fi



################################################################################
# Check remote URLs not retrieved if  local_urls_only  specified
set_attr local_urls_only true
set_attr remove_default_doc site2.html
# Note: local_urls_only  doesn't handle directories without a default doc
set_attr local_default_doc "site2.html empty%20file.html"
set_attr start_url http://myhost/set1/index.html
# don't care what the aliased URL is; only check the normalized one
set_attr limit_urls_to
set_attr limit_normalized "http://localhost:7400/set1/"
set_attr server_aliases myhost=localhost:7400
$htdig "$@" -t -i -c $config	|| fail "couldn't dig third time"
$htpurge -c $config		|| fail "couldn't purge third time"
expected='http://localhost:7400/set1/
http://localhost:7400/set1/index.html
http://localhost:7400/set1/script.html
http://localhost:7400/set1/site%201.html
http://localhost:7400/set1/site3.html
http://localhost:7400/set1/site4.html
http://localhost:7400/set1/sub%2520dir/
http://localhost:7400/set1/title.html'

got=`./document -c $config -u | sort`

if [ "$expected" != "$got" ]
then
	fail "third document: expected 
$expected
but got
$got"
fi
set_attr remove_default_doc index.html
set_attr local_urls_only false
set_attr limit_normalized


################################################################################
#test for  <file:///...> URLs

expected=''	# no "bad local" extensions for file:///
# Check only one "title.html" found...
set_attr check_unique_md5 true
set_attr start_url "http://localhost:7400/set1/title.html file://$PWD/htdocs/set1/"
set_attr limit_urls_to '${start_url}'
got=`$htdig "$@" -t -i -vv -c $config | grep "Bad local extension:" | sed -e"s-.*/--"`
if [ "$expected" != "$got" ]
then
	fail "fourth htdig: expected 
$expected
but got
$got"
fi

expected='db.docdb
db.docs
db.docs.index
db.excerpts
db.md5hash.db
db.worddump
db.words.db
db.words.db_weakcmpr'
got=`/bin/ls var/htdig2`
if [ "$expected" != "$got" ]
then
	fail "fourth created files: expected 
$expected
but got
$got"
fi

$htpurge -c $config || fail "couldn't purge fourth time"

expected='file:///set1/bad_local.htm
file:///set1/index.html
file:///set1/script.html
file:///set1/site%201.html
file:///set1/site2.html
file:///set1/site3.html
file:///set1/site4.html
file:///set1/sub%2520dir/empty%20file.html
/title.html'

got=`./document -c $config -u | sed "s#${PWD}/htdocs##" | sort | sed "s#.*/title.html#/title.html#"`

if [ "$expected" != "$got" ]
then
	fail "fourth document: expected 
$expected
but got
$got"
fi


################################################################################
#test mime types handling

expected=''	# no "bad local" extensions for file:///
set_attr max_hop_count 1	# removes "empty%20file.html"
set_attr exclude_urls "site4.html script.html site[3].html"
set_attr bad_extensions .foo
set_attr local_urls_only false

rm -f var/htdig2/db.md5hash.db
set_attr md5_db '${database_base}.md5.db'

set_attr mime_types $PWD/mime-without-htm
set_attr content_classifier $PWD/say-text
echo 'text/html	html' > mime-without-htm
echo '#!/bin/sh
      echo text/plain' > say-text
chmod 700 say-text
got=`$htdig "$@" -t -i -vv -c $config | grep "MIME type:" | sed -e"s-.*/--"`
if [ "$expected" != "$got" ]
then
	fail "fifth htdig: expected 
$expected
but got
$got"
fi

expected='db.docdb
db.docs
db.docs.index
db.excerpts
db.md5.db
db.worddump
db.words.db
db.words.db_weakcmpr'
got=`/bin/ls var/htdig2`
if [ "$expected" != "$got" ]
then
	fail "fifth created files: expected 
$expected
but got
$got"
fi

$htpurge -c $config || fail "couldn't purge fifth time"

expected='file:///set1/bad_local.htm
file:///set1/index.html
file:///set1/nph-location.cgi
file:///set1/site%201.html
file:///set1/site2.html
file:///set1/site3.html
file:///set1/title.html'

got=`./document -c $config -u | sed "s#${PWD}/htdocs##" | sort`

if [ "$expected" != "$got" ]
then
	fail "fifth document: expected 
$expected
but got
$got"
fi

################################################################################
expected=''	# no "bad local" extensions for file:///
set_attr max_hop_count 	# removes "empty%20file.html"
set_attr exclude_urls /CVS/
set_attr valid_extensions ".foo .html"
set_attr bad_extensions

set_attr mime_types $PWD/mime-without-htm
set_attr content_classifier $PWD/say-text
echo 'text/html	html' > mime-without-htm
echo '#!/bin/sh
      echo text/plain' > say-text
chmod 700 say-text
got=`$htdig "$@" -t -i -vv -c $config | grep "MIME type:" | sed -e"s-.*/--"`
if [ "$expected" != "$got" ]
then
	fail "sixth htdig: expected 
$expected
but got
$got"
fi

$htpurge -c $config || fail "couldn't purge sixth time"

expected='file:///set1/index.html
file:///set1/nph-location.foo
file:///set1/script.html
file:///set1/site%201.html
file:///set1/site2.html
file:///set1/site3.html
file:///set1/site4.html
file:///set1/sub%2520dir/empty%20file.html
file:///set1/title.html'

got=`./document -c $config -u | sed "s#${PWD}/htdocs##" | sort`

if [ "$expected" != "$got" ]
then
	fail "sixth document: expected 
$expected
but got
$got"
fi


################################################################################
set_attr local_urls_only
set_attr local_urls "http://somewhere/=$PWD/htdocs/"
set_attr local_user_urls "http://somewhere/=$PWD/,/set1/"
set_attr start_url "http://somewhere/~htdocs/"

set_attr valid_extensions
set_attr  local_default_doc index.html
set_attr remove_default_doc index.html

$htdig "$@" -t -i -c $config || fail "couldn't dig seventh time"
$htpurge -c $config || fail "couldn't purge seventh time"

#local_urls_only can't handle .../~htdocs/sub%2520dir/empty%20file.html
expected='http://somewhere/~htdocs/
http://somewhere/~htdocs/script.html
http://somewhere/~htdocs/site%201.html
http://somewhere/~htdocs/site2.html
http://somewhere/~htdocs/site3.html
http://somewhere/~htdocs/site4.html
http://somewhere/~htdocs/title.html'

got=`./document -c $config -u | sort`

if [ "$expected" != "$got" ]
then
	fail "seventh document: expected 
$expected
but got
$got"
fi


/bin/rm mime-without-htm say-text

test_functions_action=--stop-apache
. ./test_functions