7c730847f605ff0daa9af2d13f06248de4f636ba
- Author
- Ayman Bagabas <ayman.bagabas@gmail.com>
- Committer
- Ayman Bagabas <ayman.bagabas@gmail.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/server/web/context.go b/server/web/context.go
2index b0a2480e787d10bbeb6a10cb919dd3abbc070539..8e7eb8ea9cfb35b6fd550a16418f89db58e8e84a 100644
3--- a/server/web/context.go
4+++ b/server/web/context.go
5@@ -17,7 +17,6 @@ func NewContextHandler(ctx context.Context) func(http.Handler) http.Handler {
6 cfg := config.FromContext(ctx)
7 be := backend.FromContext(ctx)
8 logger := log.FromContext(ctx).WithPrefix("http")
9- logger.Infof("data path %s", cfg.DataPath)
10 dbx := db.FromContext(ctx)
11 datastore := store.FromContext(ctx)
12 return func(next http.Handler) http.Handler {
13diff --git a/testscript/script_test.go b/testscript/script_test.go
14index 8c9e3ceae7c4f393c71466a9319a252827e32542..2c9c0bc32f54a482635b9cdf940c1f8d60b5b626 100644
15--- a/testscript/script_test.go
16+++ b/testscript/script_test.go
17@@ -5,7 +5,10 @@ import (
18 "context"
19 "flag"
20 "fmt"
21+ "io"
22 "net"
23+ "net/http"
24+ "net/url"
25 "os"
26 "path/filepath"
27 "strings"
28@@ -25,6 +28,7 @@ import (
29 "github.com/charmbracelet/soft-serve/server/store/database"
30 "github.com/charmbracelet/soft-serve/server/test"
31 "github.com/rogpeppe/go-internal/testscript"
32+ "github.com/spf13/cobra"
33 "golang.org/x/crypto/ssh"
34 _ "modernc.org/sqlite" // sqlite Driver
35 )
36@@ -55,6 +59,7 @@ func TestScript(t *testing.T) {
37 "soft": cmdSoft(admin1.Signer()),
38 "usoft": cmdSoft(user1.Signer()),
39 "git": cmdGit(key),
40+ "curl": cmdCurl,
41 "mkfile": cmdMkfile,
42 "envfile": cmdEnvfile,
43 "readfile": cmdReadfile,
44@@ -295,3 +300,90 @@ func cmdEnvfile(ts *testscript.TestScript, neg bool, args []string) {
45 ts.Setenv(key, strings.TrimSpace(ts.ReadFile(file)))
46 }
47 }
48+
49+func cmdCurl(ts *testscript.TestScript, neg bool, args []string) {
50+ var verbose bool
51+ var headers []string
52+ var data string
53+ method := http.MethodGet
54+
55+ cmd := &cobra.Command{
56+ Use: "curl",
57+ Args: cobra.MinimumNArgs(1),
58+ RunE: func(cmd *cobra.Command, args []string) error {
59+ url, err := url.Parse(args[0])
60+ if err != nil {
61+ return err
62+ }
63+
64+ req, err := http.NewRequest(method, url.String(), nil)
65+ if err != nil {
66+ return err
67+ }
68+
69+ if data != "" {
70+ req.Body = io.NopCloser(strings.NewReader(data))
71+ }
72+
73+ if verbose {
74+ fmt.Fprintf(cmd.ErrOrStderr(), "< %s %s\n", req.Method, url.String())
75+ }
76+
77+ for _, header := range headers {
78+ parts := strings.SplitN(header, ":", 2)
79+ if len(parts) != 2 {
80+ return fmt.Errorf("invalid header: %s", header)
81+ }
82+ req.Header.Add(strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]))
83+ }
84+
85+ if userInfo := url.User; userInfo != nil {
86+ password, _ := userInfo.Password()
87+ req.SetBasicAuth(userInfo.Username(), password)
88+ }
89+
90+ if verbose {
91+ for key, values := range req.Header {
92+ for _, value := range values {
93+ fmt.Fprintf(cmd.ErrOrStderr(), "< %s: %s\n", key, value)
94+ }
95+ }
96+ }
97+
98+ resp, err := http.DefaultClient.Do(req)
99+ if err != nil {
100+ return err
101+ }
102+
103+ if verbose {
104+ fmt.Fprintf(ts.Stderr(), "> %s\n", resp.Status)
105+ for key, values := range resp.Header {
106+ for _, value := range values {
107+ fmt.Fprintf(cmd.ErrOrStderr(), "> %s: %s\n", key, value)
108+ }
109+ }
110+ }
111+
112+ defer resp.Body.Close()
113+ buf, err := io.ReadAll(resp.Body)
114+ if err != nil {
115+ return err
116+ }
117diff --git a/testscript/testdata/http.txtar b/testscript/testdata/http.txtar
118index defc142d318781892a06ccf40309e9bfac4a4912..68bec65d584f0e032d1a78f6e8a3f128ff5447a0 100644
119--- a/testscript/testdata/http.txtar
120+++ b/testscript/testdata/http.txtar
121@@ -1,5 +1,8 @@
122 # vi: set ft=conf
123
124+# FIXME: don't skip windows
125+[windows] skip 'curl makes github actions hang'
126+
127 # convert crlf to lf on windows
128 [windows] dos2unix http1.txt http2.txt http3.txt goget.txt gitclone.txt
129
130@@ -36,70 +39,70 @@ git -C repo2 push origin HEAD
131 git -C repo2 push origin HEAD --tags
132
133 # dumb http git
134-exec curl -s -XGET http://localhost:$HTTP_PORT/repo2.git/info/refs
135+curl -XGET http://localhost:$HTTP_PORT/repo2.git/info/refs
136 stdout '[0-9a-z]{40} refs/heads/master\n[0-9a-z]{40} refs/tags/v0.1.0'
137
138
139 # http errors
140-exec curl -s -XGET http://localhost:$HTTP_PORT/repo2111foobar.git/foo/bar
141+curl -XGET http://localhost:$HTTP_PORT/repo2111foobar.git/foo/bar
142 stdout '404.*'
143-exec curl -s -XGET http://localhost:$HTTP_PORT/repo2111/foobar.git/foo/bar
144+curl -XGET http://localhost:$HTTP_PORT/repo2111/foobar.git/foo/bar
145 stdout '404.*'
146-exec curl -s -XGET http://localhost:$HTTP_PORT/repo2.git/foo/bar
147+curl -XGET http://localhost:$HTTP_PORT/repo2.git/foo/bar
148 stdout '404.*'
149-exec curl -s -XPOST http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/foo
150+curl -XPOST http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/foo
151 stdout '404.*'
152-exec curl -s -XGET http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
153+curl -XGET http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
154 stdout '.*Method Not Allowed.*'
155-exec curl -s -XPOST http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
156+curl -XPOST http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
157 stdout '.*Not Acceptable.*'
158-exec 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
159+curl -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
160 stdout '.*validation error.*'
161-exec 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
162+curl -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
163 stdout '.*no objects found.*'
164-exec 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
165+curl -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
166 stdout '.*unsupported transfer.*'
167-exec 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
168+curl -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
169 stdout '.*unsupported operation.*'
170-exec 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
171+curl -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
172 cmp stdout http1.txt
173-exec 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
174+curl -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
175 stdout '.*write access required.*'
176-exec 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
177+curl -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
178 cmp stdout http1.txt
179
180
181 # go-get allow (public repo)
182-exec curl -s http://localhost:$HTTP_PORT/repo2.git?go-get=1
183+curl http://localhost:$HTTP_PORT/repo2.git?go-get=1
184 cmpenv stdout goget.txt
185-exec curl -s http://localhost:$HTTP_PORT/repo2.git/subpackage?go-get=1
186+curl http://localhost:$HTTP_PORT/repo2.git/subpackage?go-get=1
187 cmpenv stdout goget.txt
188-exec curl -s http://localhost:$HTTP_PORT/repo2/subpackage?go-get=1
189+curl http://localhost:$HTTP_PORT/repo2/subpackage?go-get=1
190 cmpenv stdout goget.txt
191
192 # go-get not found (invalid method)
193-exec curl -s -XPOST http://localhost:$HTTP_PORT/repo2/subpackage?go-get=1
194+curl -XPOST http://localhost:$HTTP_PORT/repo2/subpackage?go-get=1
195 stdout '404.*'
196
197 # set private
198 soft repo private repo2 true
199
200 # allow access private
201-exec 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
202+curl -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
203 cmp stdout http2.txt
204-exec 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
205+curl -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
206 cmp stdout http3.txt
207
208 # deny access private
209-exec curl -s http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
210+curl http://localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
211 stdout '.*credentials needed.*'
212-exec curl -s http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
213+curl http://$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
214 stdout '.*credentials needed.*'
215-exec curl -s http://0$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
216+curl http://0$UTOKEN@localhost:$HTTP_PORT/repo2.git/info/lfs/objects/batch
217 cmp stdout http3.txt
218
219 # deny dumb http git
220-exec curl -s -XGET http://localhost:$HTTP_PORT/repo2.git/info/refs
221diff --git a/testscript/testdata/repo-create.txtar b/testscript/testdata/repo-create.txtar
222index d81f6b976151dd058c3325b50cb569422d7f81fe..64849215c43d49b2ac9d420f29b3e6689aaf5b99 100644
223--- a/testscript/testdata/repo-create.txtar
224+++ b/testscript/testdata/repo-create.txtar
225@@ -1,7 +1,7 @@
226 # vi: set ft=conf
227
228 # convert crlf to lf on windows
229-[windows] dos2unix tree.txt readme.md branch_list.1.txt info.txt
230+[windows] dos2unix readme.md branch_list.1.txt info.txt
231
232 # create a repo
233 soft repo create repo1 -d 'description' -H -p -n 'repo11'
234@@ -30,6 +30,7 @@ git -C repo1 push origin HEAD --tags
235 # create lfs files, use ssh git-lfs-transfer
236 git -C repo1 lfs install --local
237 git -C repo1 lfs track '*.png'
238+git -C repo1 lfs track '*.mp4'
239 mkfile ./repo1/foo.png 'foo'
240 mkfile ./repo1/bar.png 'bar'
241 git -C repo1 add -A
242@@ -51,7 +52,11 @@ soft repo tag list repo1
243
244 # print tree
245 soft repo tree repo1
246-cmp stdout tree.txt
247+cp stdout tree.txt
248+grep '.gitattributes' tree.txt
249+grep 'README.md' tree.txt
250+grep 'foo.png' tree.txt
251+grep 'bar.png' tree.txt
252
253 # cat blob
254 soft repo blob repo1 README.md
255@@ -85,11 +90,6 @@ soft repo branch delete repo1 master
256 soft repo branch list repo1
257 stdout branch1
258
259--- tree.txt --
260--rw-r--r-- 42 B .gitattributes
261--rw-r--r-- 14 B README.md
262--rw-r--r-- 126 B bar.png
263--rw-r--r-- 126 B foo.png
264 -- readme.md --
265 # Project\nfoo
266 -- branch_list.1.txt --
267diff --git a/testscript/testdata/token.txtar b/testscript/testdata/token.txtar
268index d5010c74f3881add8789a4d11e1613c525057dee..3941b5e2add9ceb38f680adde6cc1d7b07fa872a 100644
269--- a/testscript/testdata/token.txtar
270+++ b/testscript/testdata/token.txtar
271@@ -17,9 +17,9 @@ stderr 'Access token created'
272 # list tokens
273 usoft token list
274 cp stdout tokens.txt
275-grep '1 test1.* -' tokens.txt
276-grep '2 test2.* 1 year from now' tokens.txt
277-grep '3 test3.* expired' tokens.txt
278+grep '1\s+test1.*-' tokens.txt
279+grep '2\s+test2.*1 year from now' tokens.txt
280+grep '3\s+test3.*expired' tokens.txt
281
282 # delete token
283 usoft token delete 1