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