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# create user
10soft user create user1 --key "$USER1_AUTHORIZED_KEY"
11
12# create access token
13soft token create --expires-in '1h' 'repo2'
14stdout 'ss_*'
15cp stdout tokenfile
16envfile TOKEN=tokenfile
17soft token create --expires-in '1ns' 'repo2'
18stdout 'ss_*'
19cp stdout etokenfile
20envfile ETOKEN=etokenfile
21usoft token create 'repo2'
22stdout 'ss_*'
23cp stdout utokenfile
24envfile UTOKEN=utokenfile
25
26# push & create repo with some files, commits, tags...
27mkdir ./repo2
28git -c init.defaultBranch=master -C repo2 init
29mkfile ./repo2/README.md '# Project\nfoo'
30mkfile ./repo2/foo.png 'foo'
31mkfile ./repo2/bar.png 'bar'
32git -C repo2 remote add origin http://$TOKEN@localhost:$HTTP_PORT/repo2
33git -C repo2 lfs install --local
34git -C repo2 lfs track '*.png'
35git -C repo2 add -A
36git -C repo2 commit -m 'first'
37git -C repo2 tag v0.1.0
38git -C repo2 push origin HEAD
39git -C repo2 push origin HEAD --tags
40
41# dumb http git
42curl -XGET http://localhost:$HTTP_PORT/repo2.git/info/refs
43stdout '[0-9a-z]{40} refs/heads/master\n[0-9a-z]{40} refs/tags/v0.1.0'
44
45
46# http errors
47curl -XGET http://localhost:$HTTP_PORT/repo2111foobar.git/foo/bar
48stdout '404.*'
49curl -XGET http://localhost:$HTTP_PORT/repo2111/foobar.git/foo/bar
50stdout '404.*'
51curl -XGET http://localhost:$HTTP_PORT/repo2.git/foo/bar
52stdout '404.*'
53curl -XPOST http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/foo
54stdout '404.*'
55curl -XGET http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
56stdout '.*Method Not Allowed.*'
57curl -XPOST http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
58stdout '.*Not Acceptable.*'
59curl -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
60stdout '.*validation error.*'
61curl -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
62stdout '.*no objects found.*'
63curl -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
64stdout '.*unsupported transfer.*'
65curl -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
66stdout '.*unsupported operation.*'
67curl -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
68cmp stdout http1.txt
69curl -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
70stdout '.*write access required.*'
71curl -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
72cmp stdout http1.txt
73
74
75# go-get allow (public repo)
76curl http://localhost:$HTTP_PORT/repo2.git?go-get=1
77cmpenv stdout goget.txt
78curl http://localhost:$HTTP_PORT/repo2.git/subpackage?go-get=1
79cmpenv stdout goget.txt
80curl http://localhost:$HTTP_PORT/repo2/subpackage?go-get=1
81cmpenv stdout goget.txt
82
83# go-get not found (invalid method)
84curl -XPOST http://localhost:$HTTP_PORT/repo2/subpackage?go-get=1
85stdout '404.*'
86
87# go-get not found (invalid repo)
88curl -XPOST http://localhost:$HTTP_PORT/repo299/subpackage?go-get=1
89stdout '404.*'
90
91# set private
92soft repo private repo2 true
93
94# allow access private
95curl -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
96cmp stdout http2.txt
97curl -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
98cmp stdout http3.txt
99
100# deny access private
101curl http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
102stdout '.*credentials needed.*'
103curl http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
104stdout '.*credentials needed.*'
105curl http://0$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
106cmp stdout http3.txt
107
108# deny dumb http git
109curl -XGET http://localhost:$HTTP_PORT/repo2.git/info/refs
110stdout '404.*'
111
112# deny access ask for credentials
113# this means the server responded with a 401 and prompted for credentials
114# but we disable git terminal prompting to we get a fatal instead of a 401 "Unauthorized"
115! git clone http://localhost:$HTTP_PORT/repo2 repo2_clone
116cmpenv stderr gitclone.txt
117! git clone http://someuser:somepassword@localhost:$HTTP_PORT/repo2 repo2_clone
118stderr '.*403.*'
119
120# go-get not found (private repo)
121curl http://localhost:$HTTP_PORT/repo2.git?go-get=1
122stdout '404.*'
123
124# go-get forbidden (private repo & expired token)
125curl http://$ETOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
126stdout '403.*'
127
128# go-get not found (private repo & different user)
129curl http://$UTOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
130stdout '404.*'
131
132# go-get with creds
133curl http://$TOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
134cmpenv stdout goget.txt
135
136-- http1.txt --
137{"transfer":"basic","objects":[{"oid":"","size":0,"error":{"code":422,"message":"invalid object"}}],"hash_algo":"sha256"}
138-- http2.txt --
139{"message":"validation error in request: EOF"}
140-- http3.txt --
141{"message":"bad credentials"}
142-- goget.txt --
143<!DOCTYPE html>
144<html lang="en">
145<head>
146 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
147 <meta http-equiv="refresh" content="0; url=https://godoc.org/localhost:$HTTP_PORT/repo2">
148 <meta name="go-import" content="localhost:$HTTP_PORT/repo2 git http://localhost:$HTTP_PORT/repo2.git">
149</head>
150<body>
151Redirecting to docs at <a href="https://godoc.org/localhost:$HTTP_PORT/repo2">godoc.org/localhost:$HTTP_PORT/repo2</a>...
152</body>
153</html>
154-- gitclone.txt --
155Cloning into 'repo2_clone'...
156fatal: could not read Username for 'http://localhost:$HTTP_PORT': terminal prompts disabled