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# set private
 88soft repo private repo2 true
 89
 90# allow access private
 91curl -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
 92cmp stdout http2.txt
 93curl -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
 94cmp stdout http3.txt
 95
 96# deny access private
 97curl http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
 98stdout '.*credentials needed.*'
 99curl http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
100stdout '.*credentials needed.*'
101curl http://0$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
102cmp stdout http3.txt
103
104# deny dumb http git
105curl -XGET http://localhost:$HTTP_PORT/repo2.git/info/refs
106stdout '404.*'
107
108# deny access ask for credentials
109# this means the server responded with a 401 and prompted for credentials
110# but we disable git terminal prompting to we get a fatal instead of a 401 "Unauthorized"
111! git clone http://localhost:$HTTP_PORT/repo2 repo2_clone
112cmpenv stderr gitclone.txt
113! git clone http://someuser:somepassword@localhost:$HTTP_PORT/repo2 repo2_clone
114stderr '.*403.*'
115
116# go-get not found (private repo)
117curl http://localhost:$HTTP_PORT/repo2.git?go-get=1
118stdout '404.*'
119
120# go-get forbidden (private repo & expired token)
121curl http://$ETOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
122stdout '403.*'
123
124# go-get not found (private repo & different user)
125curl http://$UTOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
126stdout '404.*'
127
128# go-get with creds
129curl http://$TOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
130cmpenv stdout goget.txt
131
132-- http1.txt --
133{"transfer":"basic","objects":[{"oid":"","size":0,"error":{"code":422,"message":"invalid object"}}],"hash_algo":"sha256"}
134-- http2.txt --
135{"message":"validation error in request: EOF"}
136-- http3.txt --
137{"message":"bad credentials"}
138-- goget.txt --
139<!DOCTYPE html>
140<html lang="en">
141<head>
142    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
143    <meta http-equiv="refresh" content="0; url=https://godoc.org/localhost:$HTTP_PORT/repo2">
144    <meta name="go-import" content="localhost:$HTTP_PORT/repo2 git http://localhost:$HTTP_PORT/repo2.git">
145</head>
146<body>
147Redirecting to docs at <a href="https://godoc.org/localhost:$HTTP_PORT/repo2">godoc.org/localhost:$HTTP_PORT/repo2</a>...
148</body>
149</html>
150-- gitclone.txt --
151Cloning into 'repo2_clone'...
152fatal: could not read Username for 'http://localhost:$HTTP_PORT': terminal prompts disabled