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
|
test_description='Check content on plain page'
. ./setup.sh
test_expect_success 'generate foo/plain/file-1' '
cgit_url "foo/plain/file-1" >tmp
'
test_expect_success 'a text file is served as text/plain' '
head -n 1 tmp | grep "Status: 200 OK" &&
sed "/^$/q" tmp | grep "^Content-Type: text/plain; charset=UTF-8$"
'
test_expect_success 'the body carries the blob byte for byte' '
strip_headers <tmp >body &&
git -C repos/foo show master:file-1 >expect &&
test_cmp expect body
'
test_expect_success 'a missing path is a 404' '
cgit_url "foo/plain/no-such-file" >tmp &&
head -n 1 tmp | grep "Status: 404"
'
test_expect_success 'a directory answers with a listing of links' '
cgit_url "foo/plain" >tmp &&
grep "<li><a href=" tmp &&
grep "file-1" tmp &&
grep "file-5" tmp
'
test_expect_success 'a blob whose bytes look binary is served as octet-stream' '
(
cd repos/foo &&
printf "\000\001\002" >blob.bin &&
git add blob.bin &&
git commit -m binary
) &&
cgit_url "foo/plain/blob.bin" >tmp &&
sed "/^$/q" tmp | grep "^Content-Type: application/octet-stream$"
'
test_expect_success 'only text and xml types carry a charset' '
(
cd repos/foo &&
printf "PK" >doc.docx &&
printf "<svg/>" >pic.svg &&
git add doc.docx pic.svg &&
git commit -m types
) &&
docx=application/vnd.openxmlformats-officedocument. &&
docx=${docx}wordprocessingml.document &&
{
echo "enable-html-serving=1" &&
echo "mimetype.docx=$docx" &&
echo "mimetype.svg=image/svg+xml" &&
cat cgitrc
} >typesrc &&
CGIT_CONFIG="$PWD/typesrc" QUERY_STRING="url=foo/plain/doc.docx" cgit >tmp &&
sed "/^$/q" tmp | grep "^Content-Type: $docx$" &&
CGIT_CONFIG="$PWD/typesrc" QUERY_STRING="url=foo/plain/pic.svg" cgit >tmp &&
sed "/^$/q" tmp | grep "^Content-Type: image/svg+xml; charset=UTF-8$"
'
test_done
|