Skip to content

Commit 04481ad

Browse files
Tarmigan Caseboltgitster
authored andcommitted
Smart-http tests: Break test t5560-http-backend into pieces
This should introduce no functional change in the tests or the amount of test coverage. Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Tarmigan Casebolt <tarmigan+git@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4301577 commit 04481ad

File tree

3 files changed

+173
-147
lines changed

3 files changed

+173
-147
lines changed

t/t5560-http-backend-noserver.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
3+
test_description='test git-http-backend-noserver'
4+
. ./test-lib.sh
5+
6+
HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY"
7+
8+
run_backend() {
9+
REQUEST_METHOD=GET \
10+
GIT_PROJECT_ROOT="$HTTPD_DOCUMENT_ROOT_PATH" \
11+
PATH_INFO="$1" \
12+
git http-backend >act.out 2>act.err
13+
}
14+
15+
GET() {
16+
return 0
17+
}
18+
19+
POST() {
20+
return 0
21+
}
22+
23+
log_div() {
24+
return 0
25+
}
26+
27+
. "$TEST_DIRECTORY"/t556x_common
28+
29+
expect_aliased() {
30+
if test $1 = 0; then
31+
run_backend "$2"
32+
else
33+
run_backend "$2" &&
34+
echo "fatal: '$2': aliased" >exp.err &&
35+
test_cmp exp.err act.err
36+
fi
37+
}
38+
39+
test_expect_success 'http-backend blocks bad PATH_INFO' '
40+
config http.getanyfile true &&
41+
42+
expect_aliased 0 /repo.git/HEAD &&
43+
44+
expect_aliased 1 /repo.git/../HEAD &&
45+
expect_aliased 1 /../etc/passwd &&
46+
expect_aliased 1 ../etc/passwd &&
47+
expect_aliased 1 /etc//passwd &&
48+
expect_aliased 1 /etc/./passwd &&
49+
expect_aliased 1 //domain/data.txt
50+
'
51+
52+
test_done
Lines changed: 2 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,10 @@ if test -n "$NO_CURL"; then
88
test_done
99
fi
1010

11-
LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5560'}
11+
LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5561'}
1212
. "$TEST_DIRECTORY"/lib-httpd.sh
1313
start_httpd
1414

15-
find_file() {
16-
cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
17-
find $1 -type f |
18-
sed -e 1q
19-
}
20-
21-
config() {
22-
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" config $1 $2
23-
}
24-
2515
GET() {
2616
curl --include "$HTTPD_URL/$SMART/repo.git/$1" >out 2>/dev/null &&
2717
tr '\015' Q <out |
@@ -52,142 +42,7 @@ log_div() {
5242
echo "###" >>"$HTTPD_ROOT_PATH"/access.log
5343
}
5444

55-
test_expect_success 'setup repository' '
56-
echo content >file &&
57-
git add file &&
58-
git commit -m one &&
59-
60-
mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
61-
(cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
62-
git --bare init &&
63-
: >objects/info/alternates &&
64-
: >objects/info/http-alternates
65-
) &&
66-
git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
67-
git push public master:master &&
68-
69-
(cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
70-
git repack -a -d
71-
) &&
72-
73-
echo other >file &&
74-
git add file &&
75-
git commit -m two &&
76-
git push public master:master &&
77-
78-
LOOSE_URL=$(find_file objects/??) &&
79-
PACK_URL=$(find_file objects/pack/*.pack) &&
80-
IDX_URL=$(find_file objects/pack/*.idx)
81-
'
82-
83-
get_static_files() {
84-
GET HEAD "$1" &&
85-
GET info/refs "$1" &&
86-
GET objects/info/packs "$1" &&
87-
GET objects/info/alternates "$1" &&
88-
GET objects/info/http-alternates "$1" &&
89-
GET $LOOSE_URL "$1" &&
90-
GET $PACK_URL "$1" &&
91-
GET $IDX_URL "$1"
92-
}
93-
94-
SMART=smart
95-
test_expect_success 'direct refs/heads/master not found' '
96-
log_div "refs/heads/master"
97-
GET refs/heads/master "404 Not Found"
98-
'
99-
test_expect_success 'static file is ok' '
100-
log_div "getanyfile default"
101-
get_static_files "200 OK"
102-
'
103-
SMART=smart_noexport
104-
test_expect_success 'no export by default' '
105-
log_div "no git-daemon-export-ok"
106-
get_static_files "404 Not Found"
107-
'
108-
test_expect_success 'export if git-daemon-export-ok' '
109-
log_div "git-daemon-export-ok"
110-
(cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
111-
touch git-daemon-export-ok
112-
) &&
113-
get_static_files "200 OK"
114-
'
115-
SMART=smart
116-
test_expect_success 'static file if http.getanyfile true is ok' '
117-
log_div "getanyfile true"
118-
config http.getanyfile true &&
119-
get_static_files "200 OK"
120-
'
121-
test_expect_success 'static file if http.getanyfile false fails' '
122-
log_div "getanyfile false"
123-
config http.getanyfile false &&
124-
get_static_files "403 Forbidden"
125-
'
126-
127-
test_expect_success 'http.uploadpack default enabled' '
128-
log_div "uploadpack default"
129-
GET info/refs?service=git-upload-pack "200 OK" &&
130-
POST git-upload-pack 0000 "200 OK"
131-
'
132-
test_expect_success 'http.uploadpack true' '
133-
log_div "uploadpack true"
134-
config http.uploadpack true &&
135-
GET info/refs?service=git-upload-pack "200 OK" &&
136-
POST git-upload-pack 0000 "200 OK"
137-
'
138-
test_expect_success 'http.uploadpack false' '
139-
log_div "uploadpack false"
140-
config http.uploadpack false &&
141-
GET info/refs?service=git-upload-pack "403 Forbidden" &&
142-
POST git-upload-pack 0000 "403 Forbidden"
143-
'
144-
145-
test_expect_success 'http.receivepack default disabled' '
146-
log_div "receivepack default"
147-
GET info/refs?service=git-receive-pack "403 Forbidden" &&
148-
POST git-receive-pack 0000 "403 Forbidden"
149-
'
150-
test_expect_success 'http.receivepack true' '
151-
log_div "receivepack true"
152-
config http.receivepack true &&
153-
GET info/refs?service=git-receive-pack "200 OK" &&
154-
POST git-receive-pack 0000 "200 OK"
155-
'
156-
test_expect_success 'http.receivepack false' '
157-
log_div "receivepack false"
158-
config http.receivepack false &&
159-
GET info/refs?service=git-receive-pack "403 Forbidden" &&
160-
POST git-receive-pack 0000 "403 Forbidden"
161-
'
162-
run_backend() {
163-
REQUEST_METHOD=GET \
164-
GIT_PROJECT_ROOT="$HTTPD_DOCUMENT_ROOT_PATH" \
165-
PATH_INFO="$1" \
166-
git http-backend >act.out 2>act.err
167-
}
168-
169-
expect_aliased() {
170-
if test $1 = 0; then
171-
run_backend "$2"
172-
else
173-
run_backend "$2" &&
174-
echo "fatal: '$2': aliased" >exp.err &&
175-
test_cmp exp.err act.err
176-
fi
177-
}
178-
179-
test_expect_success 'http-backend blocks bad PATH_INFO' '
180-
config http.getanyfile true &&
181-
182-
expect_aliased 0 /repo.git/HEAD &&
183-
184-
expect_aliased 1 /repo.git/../HEAD &&
185-
expect_aliased 1 /../etc/passwd &&
186-
expect_aliased 1 ../etc/passwd &&
187-
expect_aliased 1 /etc//passwd &&
188-
expect_aliased 1 /etc/./passwd &&
189-
expect_aliased 1 //domain/data.txt
190-
'
45+
. "$TEST_DIRECTORY"/t556x_common
19146

19247
cat >exp <<EOF
19348

t/t556x_common

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/sh
2+
3+
find_file() {
4+
cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
5+
find $1 -type f |
6+
sed -e 1q
7+
}
8+
9+
config() {
10+
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" config $1 $2
11+
}
12+
13+
test_expect_success 'setup repository' '
14+
echo content >file &&
15+
git add file &&
16+
git commit -m one &&
17+
18+
mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
19+
(cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
20+
git --bare init &&
21+
: >objects/info/alternates &&
22+
: >objects/info/http-alternates
23+
) &&
24+
git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
25+
git push public master:master &&
26+
27+
(cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
28+
git repack -a -d
29+
) &&
30+
31+
echo other >file &&
32+
git add file &&
33+
git commit -m two &&
34+
git push public master:master &&
35+
36+
LOOSE_URL=$(find_file objects/??) &&
37+
PACK_URL=$(find_file objects/pack/*.pack) &&
38+
IDX_URL=$(find_file objects/pack/*.idx)
39+
'
40+
41+
get_static_files() {
42+
GET HEAD "$1" &&
43+
GET info/refs "$1" &&
44+
GET objects/info/packs "$1" &&
45+
GET objects/info/alternates "$1" &&
46+
GET objects/info/http-alternates "$1" &&
47+
GET $LOOSE_URL "$1" &&
48+
GET $PACK_URL "$1" &&
49+
GET $IDX_URL "$1"
50+
}
51+
52+
SMART=smart
53+
test_expect_success 'direct refs/heads/master not found' '
54+
log_div "refs/heads/master"
55+
GET refs/heads/master "404 Not Found"
56+
'
57+
test_expect_success 'static file is ok' '
58+
log_div "getanyfile default"
59+
get_static_files "200 OK"
60+
'
61+
SMART=smart_noexport
62+
test_expect_success 'no export by default' '
63+
log_div "no git-daemon-export-ok"
64+
get_static_files "404 Not Found"
65+
'
66+
test_expect_success 'export if git-daemon-export-ok' '
67+
log_div "git-daemon-export-ok"
68+
(cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
69+
touch git-daemon-export-ok
70+
) &&
71+
get_static_files "200 OK"
72+
'
73+
SMART=smart
74+
test_expect_success 'static file if http.getanyfile true is ok' '
75+
log_div "getanyfile true"
76+
config http.getanyfile true &&
77+
get_static_files "200 OK"
78+
'
79+
test_expect_success 'static file if http.getanyfile false fails' '
80+
log_div "getanyfile false"
81+
config http.getanyfile false &&
82+
get_static_files "403 Forbidden"
83+
'
84+
85+
test_expect_success 'http.uploadpack default enabled' '
86+
log_div "uploadpack default"
87+
GET info/refs?service=git-upload-pack "200 OK" &&
88+
POST git-upload-pack 0000 "200 OK"
89+
'
90+
test_expect_success 'http.uploadpack true' '
91+
log_div "uploadpack true"
92+
config http.uploadpack true &&
93+
GET info/refs?service=git-upload-pack "200 OK" &&
94+
POST git-upload-pack 0000 "200 OK"
95+
'
96+
test_expect_success 'http.uploadpack false' '
97+
log_div "uploadpack false"
98+
config http.uploadpack false &&
99+
GET info/refs?service=git-upload-pack "403 Forbidden" &&
100+
POST git-upload-pack 0000 "403 Forbidden"
101+
'
102+
103+
test_expect_success 'http.receivepack default disabled' '
104+
log_div "receivepack default"
105+
GET info/refs?service=git-receive-pack "403 Forbidden" &&
106+
POST git-receive-pack 0000 "403 Forbidden"
107+
'
108+
test_expect_success 'http.receivepack true' '
109+
log_div "receivepack true"
110+
config http.receivepack true &&
111+
GET info/refs?service=git-receive-pack "200 OK" &&
112+
POST git-receive-pack 0000 "200 OK"
113+
'
114+
test_expect_success 'http.receivepack false' '
115+
log_div "receivepack false"
116+
config http.receivepack false &&
117+
GET info/refs?service=git-receive-pack "403 Forbidden" &&
118+
POST git-receive-pack 0000 "403 Forbidden"
119+
'

0 commit comments

Comments
 (0)