This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / knotmirror / xrpc / git_get_archive_test.go
1.0 kB 26 lines
1package xrpc 2 3import ( 4 "net/http" 5 "net/http/httptest" 6 "strings" 7 "testing" 8) 9 10func TestGetArchiveRejectsBadParams(t *testing.T) { 11 for query, wantMessage := range map[string]string{ 12 "": "repo parameter invalid", 13 "repo=oyster.cafe%2Fsquid": "repo parameter invalid", 14 "repo=did:plc:boltless&format=tar.xz": "only tar.gz and zip formats are supported", 15 "repo=did:plc:boltless&ref=--output=/x": "ref starts with a dash", 16 "repo=did:plc:boltless&prefix=../../evil": "prefix escapes the archive root", 17 } { 18 rec := httptest.NewRecorder() 19 (&Xrpc{}).GetArchive(rec, httptest.NewRequest(http.MethodGet, "/xrpc/sh.tangled.git.temp.getArchive?"+query, nil)) 20 21 body := rec.Body.String() 22 if rec.Code != http.StatusBadRequest || !strings.Contains(body, "InvalidRequest") || !strings.Contains(body, wantMessage) { 23 t.Errorf("%s: status %d with body %s, want 400 InvalidRequest mentioning %q", query, rec.Code, body, wantMessage) 24 } 25 } 26}