http.txtar
9797 bytes
1# vi: set ft=conf
2
3# FIXME: don't skip windows
4[windows] skip 'curl makes github actions hang'
5
6# convert crlf to lf on windows
7[windows] dos2unix http1.txt http2.txt http3.txt goget.txt gitclone.txt
8
9# start soft serve
10exec soft serve &
11# wait for SSH server to start
12ensureserverrunning SSH_PORT
13
14# create user
15soft user create user1 --key "$USER1_AUTHORIZED_KEY"
16
17# create access token
18soft token create --expires-in '1h' 'repo2'
19stdout 'ss_*'
20cp stdout tokenfile
21envfile TOKEN=tokenfile
22soft token create --expires-in '1ns' 'repo2'
23stdout 'ss_*'
24cp stdout etokenfile
25envfile ETOKEN=etokenfile
26usoft token create 'repo2'
27stdout 'ss_*'
28cp stdout utokenfile
29envfile UTOKEN=utokenfile
30
31# push & create repo with some files, commits, tags...
32mkdir ./repo2
33git -c init.defaultBranch=master -C repo2 init
34mkfile ./repo2/README.md '# Project\nfoo'
35mkfile ./repo2/foo.png 'foo'
36mkfile ./repo2/bar.png 'bar'
37git -C repo2 remote add origin http://$TOKEN@localhost:$HTTP_PORT/repo2
38git -C repo2 lfs install --local
39git -C repo2 lfs track '*.png'
40git -C repo2 add -A
41git -C repo2 commit -m 'first'
42git -C repo2 tag v0.1.0
43git -C repo2 push origin HEAD
44git -C repo2 push origin HEAD --tags
45
46# dumb http git
47curl -XGET http://localhost:$HTTP_PORT/repo2.git/info/refs
48stdout '[0-9a-z]{40} refs/heads/master\n[0-9a-z]{40} refs/tags/v0.1.0'
49
50# http errors
51curl -XGET http://localhost:$HTTP_PORT/repo2111foobar.git/foo/bar
52stdout '404.*'
53curl -XGET http://localhost:$HTTP_PORT/repo2111/foobar.git/foo/bar
54stdout '404.*'
55curl -XGET http://localhost:$HTTP_PORT/repo2.git/foo/bar
56stdout '404.*'
57curl -XPOST http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/foo
58stdout '404.*'
59curl -XGET http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
60stdout '.*Method Not Allowed.*'
61curl -XPOST http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
62stdout '.*Not Acceptable.*'
63curl -XPOST -H 'Accept: application/vnd.git-lfs+json' -H 'Content-Type: application/vnd.git-lfs+json' http://$TOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
64stdout '.*validation error.*'
65curl -XPOST -H 'Accept: application/vnd.git-lfs+json' -H 'Content-Type: application/vnd.git-lfs+json' -d '{}' http://$TOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
66stdout '.*no objects found.*'
67curl -XPOST -H 'Accept: application/vnd.git-lfs+json' -H 'Content-Type: application/vnd.git-lfs+json' -d '{"operation":"download","transfers":["foo"]}' http://$TOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
68stdout '.*unsupported transfer.*'
69curl -XPOST -H 'Accept: application/vnd.git-lfs+json' -H 'Content-Type: application/vnd.git-lfs+json' -d '{"operation":"bar","objects":[{}]}' http://$TOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
70stdout '.*unsupported operation.*'
71curl -XPOST -H 'Accept: application/vnd.git-lfs+json' -H 'Content-Type: application/vnd.git-lfs+json' -d '{"operation":"download","objects":[{}]}' http://$TOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
72cmp stdout http1.txt
73curl -XPOST -H 'Accept: application/vnd.git-lfs+json' -H 'Content-Type: application/vnd.git-lfs+json' -d '{"operation":"upload","objects":[{}]}' http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
74stdout '.*write access required.*'
75curl -XPOST -H 'Accept: application/vnd.git-lfs+json' -H 'Content-Type: application/vnd.git-lfs+json' -d '{"operation":"upload","objects":[{}]}' http://$TOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
76cmp stdout http1.txt
77
78
79# go-get allow (public repo)
80curl http://localhost:$HTTP_PORT/repo2.git?go-get=1
81cmpenv stdout goget.txt
82curl http://localhost:$HTTP_PORT/repo2.git/subpackage?go-get=1
83cmpenv stdout goget.txt
84curl http://localhost:$HTTP_PORT/repo2/subpackage?go-get=1
85cmpenv stdout goget.txt
86
87# go-get not found (invalid method)
88curl -XPOST http://localhost:$HTTP_PORT/repo2/subpackage?go-get=1
89stdout '404.*'
90
91# go-get not found (invalid repo)
92curl -XPOST http://localhost:$HTTP_PORT/repo299/subpackage?go-get=1
93stdout '404.*'
94
95# set private
96soft repo private repo2 true
97
98# allow access private
99curl -XPOST -H 'Accept: application/vnd.git-lfs+json' -H 'Content-Type: application/vnd.git-lfs+json' http://$TOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
100cmp stdout http2.txt
101curl -XPOST -H 'Accept: application/vnd.git-lfs+json' -H 'Content-Type: application/vnd.git-lfs+json' http://$ETOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
102cmp stdout http3.txt
103
104# deny access private
105curl http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
106stdout '.*credentials needed.*'
107curl http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
108stdout '.*repository not found.*'
109curl http://0$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
110cmp stdout http3.txt
111
112# deny dumb http git
113curl -XGET http://localhost:$HTTP_PORT/repo2.git/info/refs
114stdout '401.*'
115curl -XGET http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/refs
116stdout '404.*'
117
118# private and missing repos get the same answer
119curl http://localhost:$HTTP_PORT/repo2.git/info/refs?service=git-upload-pack
120stdout '401.*'
121cp stdout private.txt
122curl http://localhost:$HTTP_PORT/nope.git/info/refs?service=git-upload-pack
123cmp stdout private.txt
124curl http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/refs?service=git-upload-pack
125stdout '404.*'
126cp stdout private.txt
127curl http://$UTOKEN@localhost:$HTTP_PORT/nope.git/info/refs?service=git-upload-pack
128cmp stdout private.txt
129curl http://someuser:somepassword@localhost:$HTTP_PORT/repo2.git/info/refs?service=git-upload-pack
130stdout '403.*'
131cp stdout private.txt
132curl http://someuser:somepassword@localhost:$HTTP_PORT/nope.git/info/refs?service=git-upload-pack
133cmp stdout private.txt
134curl -XPOST -H 'Accept: application/vnd.git-lfs+json' -H 'Content-Type: application/vnd.git-lfs+json' http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
135cp stdout private.txt
136curl -XPOST -H 'Accept: application/vnd.git-lfs+json' -H 'Content-Type: application/vnd.git-lfs+json' http://localhost:$HTTP_PORT/nope.git/info/lfs/objects/batch
137cmp stdout private.txt
138curl -H 'Authorization: Bearer garbage' http://localhost:$HTTP_PORT/repo2.git/info/refs?service=git-upload-pack
139stdout '403.*'
140cp stdout private.txt
141curl -H 'Authorization: Bearer garbage' http://localhost:$HTTP_PORT/nope.git/info/refs?service=git-upload-pack
142cmp stdout private.txt
143curl -H 'Authorization: Bearer garbage' http://localhost:$HTTP_PORT/repo2.git/HEAD
144cp stdout private.txt
145curl -H 'Authorization: Bearer garbage' http://localhost:$HTTP_PORT/nope.git/HEAD
146cmp stdout private.txt
147curl -XPOST -H 'Authorization: Bearer garbage' http://localhost:$HTTP_PORT/repo2.git/info/lfs/locks
148cp stdout private.txt
149curl -XPOST -H 'Authorization: Bearer garbage' http://localhost:$HTTP_PORT/nope.git/info/lfs/locks
150cmp stdout private.txt
151curl -XPOST http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/locks
152stdout '.*repository not found.*'
153cp stdout private.txt
154curl -XPOST http://$UTOKEN@localhost:$HTTP_PORT/nope.git/info/lfs/locks
155cmp stdout private.txt
156
157# deny access ask for credentials
158# this means the server responded with a 401 and prompted for credentials
159# but we disable git terminal prompting to we get a fatal instead of a 401 "Unauthorized"
160! git clone http://localhost:$HTTP_PORT/repo2 repo2_clone
161cmpenv stderr gitclone.txt
162! git clone http://someuser:somepassword@localhost:$HTTP_PORT/repo2 repo2_clone
163stderr '.*403.*'
164
165# go-get not found (private repo)
166curl http://localhost:$HTTP_PORT/repo2.git?go-get=1
167stdout '404.*'
168
169# go-get forbidden (private repo & expired token)
170curl http://$ETOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
171stdout '403.*'
172
173# go-get not found (private repo & different user)
174curl http://$UTOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
175stdout '404.*'
176
177# go-get with creds
178curl http://$TOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
179cmpenv stdout goget.txt
180
181# go-get subpackage of a private repo does not reveal it (GHSA-fgxm-5hvv-x4vh)
182curl http://localhost:$HTTP_PORT/repo2/subpackage?go-get=1
183stdout '404.*'
184! stdout 'go-import'
185curl http://$UTOKEN@localhost:$HTTP_PORT/repo2/sub/package?go-get=1
186stdout '404.*'
187! stdout 'go-import'
188curl http://$TOKEN@localhost:$HTTP_PORT/repo2/subpackage?go-get=1
189cmpenv stdout goget.txt
190
191# go-get resolves a readable repo nested under an unreadable one
192soft repo create outer -p
193soft repo create outer/inner
194curl http://localhost:$HTTP_PORT/outer/inner/pkg?go-get=1
195stdout 'go-import.*/outer/inner git'
196curl http://localhost:$HTTP_PORT/outer/pkg?go-get=1
197stdout '404.*'
198
199# go-get does not bypass repository checks on other routes
200curl http://localhost:$HTTP_PORT/nope.git/info/lfs/objects/basic/0000000000000000000000000000000000000000000000000000000000000000?go-get=1
201stdout '.*credentials needed.*'
202curl http://localhost:$HTTP_PORT/nope.git/objects/info/packs?go-get=1
203stdout '401.*'
204
205# stop the server
206[windows] stopserver
207[windows] ! stderr .
208
209-- http1.txt --
210{"transfer":"basic","objects":[{"oid":"","size":0,"error":{"code":422,"message":"invalid object"}}],"hash_algo":"sha256"}
211-- http2.txt --
212{"message":"validation error in request: EOF"}
213-- http3.txt --
214{"message":"bad credentials"}
215-- goget.txt --
216<!DOCTYPE html>
217<html lang="en">
218<head>
219 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
220 <meta http-equiv="refresh" content="0; url=https://godoc.org/localhost:$HTTP_PORT/repo2">
221 <meta name="go-import" content="localhost:$HTTP_PORT/repo2 git http://localhost:$HTTP_PORT/repo2.git">
222</head>
223<body>
224Redirecting to docs at <a href="https://godoc.org/localhost:$HTTP_PORT/repo2">godoc.org/localhost:$HTTP_PORT/repo2</a>...
225</body>
226</html>
227-- gitclone.txt --
228Cloning into 'repo2_clone'...
229fatal: could not read Username for 'http://localhost:$HTTP_PORT': terminal prompts disabled