Code

Smart-http tests: Break test t5560-http-backend into pieces
[git.git] / t / t556x_common
1 #!/bin/sh
3 find_file() {
4         cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
5         find $1 -type f |
6         sed -e 1q
7 }
9 config() {
10         git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" config $1 $2
11 }
13 test_expect_success 'setup repository' '
14         echo content >file &&
15         git add file &&
16         git commit -m one &&
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 &&
27         (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
28          git repack -a -d
29         ) &&
31         echo other >file &&
32         git add file &&
33         git commit -m two &&
34         git push public master:master &&
36         LOOSE_URL=$(find_file objects/??) &&
37         PACK_URL=$(find_file objects/pack/*.pack) &&
38         IDX_URL=$(find_file objects/pack/*.idx)
39 '
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 }
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 '
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"
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"
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"
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"