http.txtar

  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 server to start
 12waitforserver
 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 '.*credentials needed.*'
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 '404.*'
115
116# deny access ask for credentials
117# this means the server responded with a 401 and prompted for credentials
118# but we disable git terminal prompting to we get a fatal instead of a 401 "Unauthorized"
119! git clone http://localhost:$HTTP_PORT/repo2 repo2_clone
120cmpenv stderr gitclone.txt
121! git clone http://someuser:somepassword@localhost:$HTTP_PORT/repo2 repo2_clone
122stderr '.*403.*'
123
124# go-get not found (private repo)
125curl http://localhost:$HTTP_PORT/repo2.git?go-get=1
126stdout '404.*'
127
128# go-get forbidden (private repo & expired token)
129curl http://$ETOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
130stdout '403.*'
131
132# go-get not found (private repo & different user)
133curl http://$UTOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
134stdout '404.*'
135
136# go-get with creds
137curl http://$TOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
138cmpenv stdout goget.txt
139
140# stop the server
141[windows] stopserver
142[windows] ! stderr .
143
144-- http1.txt --
145{"transfer":"basic","objects":[{"oid":"","size":0,"error":{"code":422,"message":"invalid object"}}],"hash_algo":"sha256"}
146-- http2.txt --
147{"message":"validation error in request: EOF"}
148-- http3.txt --
149{"message":"bad credentials"}
150-- goget.txt --
151<!DOCTYPE html>
152<html lang="en">
153<head>
154    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
155    <meta http-equiv="refresh" content="0; url=https://godoc.org/localhost:$HTTP_PORT/repo2">
156    <meta name="go-import" content="localhost:$HTTP_PORT/repo2 git http://localhost:$HTTP_PORT/repo2.git">
157</head>
158<body>
159Redirecting to docs at <a href="https://godoc.org/localhost:$HTTP_PORT/repo2">godoc.org/localhost:$HTTP_PORT/repo2</a>...
160</body>
161</html>
162-- gitclone.txt --
163Cloning into 'repo2_clone'...
164fatal: could not read Username for 'http://localhost:$HTTP_PORT': terminal prompts disabled