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
|
test_description='Check the shipped about-render extension'
CGIT_TEST_NO_CREATE_REPOS=YesPlease
. ./setup.sh
. "$TEST_OUTPUT_DIRECTORY/extensions/lib.sh"
for lua in $interpreters
do
test_expect_success "unit checks under $lua" "
'$lua' '$EXT_TEST_DIRECTORY/test-about-render.lua' '$EXTENSIONS_DIRECTORY/about-render.lua'
"
test_expect_success "fallback checks without lpeg under $lua" "
'$lua' '$EXT_TEST_DIRECTORY/test-about-render.lua' '$EXTENSIONS_DIRECTORY/about-render.lua' nolpeg
"
done
test_expect_success 'create a repository with a markdown readme' '
test_create_repo repos/md &&
(
cd repos/md &&
cat >README.md <<-\EOF &&
# The Title
A **bold** claim and a <script>alert(1)</script> attempt.
See the [roadmap](ROADMAP.md#plan).
EOF
cat >tool.1 <<-\EOF &&
.TH TOOL 1
.SH NAME
tool \- does one thing \(em well
.SH OPTIONS
.TP
.B \-v
Be \fIverbose\fR.
.nf
tool \-v <file>
.fi
EOF
echo "Plain <b>notes</b> & more" >NOTES &&
git add README.md tool.1 NOTES &&
git commit -m "add readme" &&
git branch next
)
'
test_expect_success 'point cgit at it through the about filter' '
cat >cgitrc <<-EOF
virtual-root=/
cache-size=0
repo.url=md
repo.path=$PWD/repos/md/.git
repo.readme=:README.md
repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua
repo.url=man
repo.path=$PWD/repos/md/.git
repo.readme=:tool.1
repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua
repo.url=txt
repo.path=$PWD/repos/md/.git
repo.readme=:NOTES
repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua
EOF
'
if cgit_lua_probe "$PWD/repos/md/.git" lpeg
then
test_set_prereq CGIT_LUA_LPEG
elif test "$CGIT_HAS_LUA" -eq 1
then
test_set_prereq CGIT_LUA_NOLPEG
say 'cgit lua has no lpeg, expecting the plain text fallback'
fi
test_expect_success CGIT_LUA_LPEG 'the about page renders the markdown' '
cgit_url "md/about/" >tmp &&
grep "<h1 id=.the-title.>The Title</h1>" tmp &&
grep "<strong>bold</strong>" tmp
'
test_expect_success CGIT_LUA_LPEG 'readme markup reaches the page escaped' '
cgit_url "md/about/" >tmp &&
grep "<script>alert(1)</script>" tmp &&
! grep "<script>alert(1)" tmp
'
test_expect_success CGIT_LUA_LPEG 'a relative link leads into the tree' '
cgit_url "md/about/" >tmp &&
grep "<a href=./md/tree/ROADMAP.md#plan.>roadmap</a>" tmp
'
test_expect_success CGIT_LUA_LPEG 'the link stays on the branch shown' '
cgit_url "md/about/&h=next" >tmp &&
grep "<a href=./md/tree/ROADMAP.md?h=next#plan.>roadmap</a>" tmp
'
test_expect_success CGIT_LUA_LPEG 'the about page renders a man page' '
cgit_url "man/about/" >tmp &&
grep "<div class=.markdown.><h2 id=.name.>NAME</h2>" tmp &&
grep "tool - does one thing — well" tmp &&
grep "<strong>-v</strong><br>" tmp &&
grep "<pre><code>tool -v <file>" tmp &&
! grep "\\\\f" tmp
'
test_expect_success CGIT_LUA 'the about page shows plain text as it is' '
cgit_url "txt/about/" >tmp &&
grep "<pre class=.plaintext.>Plain <b>notes</b> & more" tmp
'
test_expect_success CGIT_LUA_NOLPEG 'without lpeg the readme is served escaped' '
cgit_url "md/about/" >tmp &&
grep "<pre class=.plaintext.>" tmp &&
grep "# The Title" tmp &&
cgit_url "man/about/" >tmp &&
grep "<pre class=.plaintext.>" tmp &&
grep ".SH NAME" tmp
'
test_done
|