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# http errors
39exec curl -s -XGET http://localhost:$HTTP_PORT/repo2111foobar.git/foo/bar
40stdout '404.*'
41exec curl -s -XGET http://localhost:$HTTP_PORT/repo2111/foobar.git/foo/bar
42stdout '404.*'
43exec curl -s -XGET http://localhost:$HTTP_PORT/repo2.git/foo/bar
44stdout '404.*'
45exec curl -s -XPOST http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/foo
46stdout '404.*'
47exec curl -s -XGET http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
48stdout '.*Method Not Allowed.*'
49exec curl -s -XPOST http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
50stdout '.*Not Acceptable.*'
51exec 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
52stdout '.*validation error.*'
53exec 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
54stdout '.*no objects found.*'
55exec 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
56stdout '.*unsupported transfer.*'
57exec 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
58stdout '.*unsupported operation.*'
59exec 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
60cmp stdout http1.txt
61exec 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
62stdout '.*credentials needed.*'
63exec 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
64cmp stdout http1.txt
65
66# set private
67soft repo private repo2 true
68
69# allow access private
70exec 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
71cmp stdout http2.txt
72exec 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
73cmp stdout http3.txt
74
75# deny access private
76exec curl -s http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
77stdout '.*credentials needed.*'
78exec curl -s http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
79stdout '.*credentials needed.*'
80exec curl -s http://0$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
81cmp stdout http3.txt
82
83# deny access ask for credentials
84# this means the server responded with a 401 and prompted for credentials
85# but we disable git terminal prompting to we get a fatal instead of a 401 "Unauthorized"
86! git clone http://localhost:$HTTP_PORT/repo2 repo2_clone
87cmpenv stderr gitclone.txt
88! git clone http://someuser:somepassword@localhost:$HTTP_PORT/repo2 repo2_clone
89stderr '.*Forbidden.*'
90
91# go-get endpoints not found
92exec curl -s http://localhost:$HTTP_PORT/repo2.git
93stdout '404.*'
94
95# go-get endpoints
96exec curl -s http://localhost:$HTTP_PORT/repo2.git?go-get=1
97cmpenv stdout goget.txt
98
99-- http1.txt --
100{"transfer":"basic","objects":[{"oid":"","size":0,"error":{"code":422,"message":"invalid object"}}],"hash_algo":"sha256"}
101-- http2.txt --
102{"message":"validation error in request: EOF"}
103-- http3.txt --
104{"message":"bad credentials"}
105-- goget.txt --
106<!DOCTYPE html>
107<html lang="en">
108<head>
109 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
110 <meta http-equiv="refresh" content="0; url=https://godoc.org/localhost:$HTTP_PORT/repo2">
111 <meta name="go-import" content="localhost:$HTTP_PORT/repo2 git http://localhost:$HTTP_PORT/repo2">
112</head>
113<body>
114Redirecting to docs at <a href="https://godoc.org/localhost:$HTTP_PORT/repo2">godoc.org/localhost:$HTTP_PORT/repo2</a>...
115</body>
116</html>
117-- gitclone.txt --
118Cloning into 'repo2_clone'...
119fatal: could not read Username for 'http://localhost:$HTTP_PORT': terminal prompts disabled