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
 51# http errors
 52curl -XGET http://localhost:$HTTP_PORT/repo2111foobar.git/foo/bar
 53stdout '404.*'
 54curl -XGET http://localhost:$HTTP_PORT/repo2111/foobar.git/foo/bar
 55stdout '404.*'
 56curl -XGET http://localhost:$HTTP_PORT/repo2.git/foo/bar
 57stdout '404.*'
 58curl -XPOST http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/foo
 59stdout '404.*'
 60curl -XGET http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
 61stdout '.*Method Not Allowed.*'
 62curl -XPOST http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
 63stdout '.*Not Acceptable.*'
 64curl -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
 65stdout '.*validation error.*'
 66curl -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
 67stdout '.*no objects found.*'
 68curl -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
 69stdout '.*unsupported transfer.*'
 70curl -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
 71stdout '.*unsupported operation.*'
 72curl -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
 73cmp stdout http1.txt
 74curl -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
 75stdout '.*write access required.*'
 76curl -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
 77cmp stdout http1.txt
 78
 79
 80# go-get allow (public repo)
 81curl http://localhost:$HTTP_PORT/repo2.git?go-get=1
 82cmpenv stdout goget.txt
 83curl http://localhost:$HTTP_PORT/repo2.git/subpackage?go-get=1
 84cmpenv stdout goget.txt
 85curl http://localhost:$HTTP_PORT/repo2/subpackage?go-get=1
 86cmpenv stdout goget.txt
 87
 88# go-get not found (invalid method)
 89curl -XPOST http://localhost:$HTTP_PORT/repo2/subpackage?go-get=1
 90stdout '404.*'
 91
 92# go-get not found (invalid repo)
 93curl -XPOST http://localhost:$HTTP_PORT/repo299/subpackage?go-get=1
 94stdout '404.*'
 95
 96# set private
 97soft repo private repo2 true
 98
 99# allow access private
100curl -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
101cmp stdout http2.txt
102curl -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
103cmp stdout http3.txt
104
105# deny access private
106curl http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
107stdout '.*credentials needed.*'
108curl http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
109stdout '.*credentials needed.*'
110curl http://0$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
111cmp stdout http3.txt
112
113# deny dumb http git
114curl -XGET http://localhost:$HTTP_PORT/repo2.git/info/refs
115stdout '404.*'
116
117# deny access ask for credentials
118# this means the server responded with a 401 and prompted for credentials
119# but we disable git terminal prompting to we get a fatal instead of a 401 "Unauthorized"
120! git clone http://localhost:$HTTP_PORT/repo2 repo2_clone
121cmpenv stderr gitclone.txt
122! git clone http://someuser:somepassword@localhost:$HTTP_PORT/repo2 repo2_clone
123stderr '.*403.*'
124
125# go-get not found (private repo)
126curl http://localhost:$HTTP_PORT/repo2.git?go-get=1
127stdout '404.*'
128
129# go-get forbidden (private repo & expired token)
130curl http://$ETOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
131stdout '403.*'
132
133# go-get not found (private repo & different user)
134curl http://$UTOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
135stdout '404.*'
136
137# go-get with creds
138curl http://$TOKEN@localhost:$HTTP_PORT/repo2.git?go-get=1
139cmpenv stdout goget.txt
140
141# stop the server
142[windows] stopserver
143[windows] ! stderr .
144
145-- http1.txt --
146{"transfer":"basic","objects":[{"oid":"","size":0,"error":{"code":422,"message":"invalid object"}}],"hash_algo":"sha256"}
147-- http2.txt --
148{"message":"validation error in request: EOF"}
149-- http3.txt --
150{"message":"bad credentials"}
151-- goget.txt --
152<!DOCTYPE html>
153<html lang="en">
154<head>
155    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
156    <meta http-equiv="refresh" content="0; url=https://godoc.org/localhost:$HTTP_PORT/repo2">
157    <meta name="go-import" content="localhost:$HTTP_PORT/repo2 git http://localhost:$HTTP_PORT/repo2.git">
158</head>
159<body>
160Redirecting to docs at <a href="https://godoc.org/localhost:$HTTP_PORT/repo2">godoc.org/localhost:$HTTP_PORT/repo2</a>...
161</body>
162</html>
163-- gitclone.txt --
164Cloning into 'repo2_clone'...
165fatal: could not read Username for 'http://localhost:$HTTP_PORT': terminal prompts disabled