clone

a self-hosted multitenant nostr relay with sites, file storage, git hosting, and inbox and outbox delivery

feat/ui-updates
tinyrelay / tinygit / server_limits_test.go
server_limits_test.go 2.0K
1package tinygit_test23import (4 "context"5 "net/http"6 "net/http/httptest"7 "path/filepath"8 "strings"9 "testing"1011 "github.com/FelineStateMachine/tinyrelay/tinygit"12)1314func TestStandaloneServerRequiresExplicitValidConfiguration(t *testing.T) {15 t.Chdir(t.TempDir())16 owner := signedAnnouncement(t, strings.Repeat("0", 63)+"1").PubKey17 for _, tc := range []struct {18 name string19 cfg tinygit.ServerConfig20 }{21 {"missing owner", tinygit.ServerConfig{DataDir: t.TempDir()}},22 {"malformed owner", tinygit.ServerConfig{DataDir: t.TempDir(), Owner: "not-a-key"}},23 {"uppercase owner", tinygit.ServerConfig{DataDir: t.TempDir(), Owner: strings.ToUpper(owner)}},24 {"missing data", tinygit.ServerConfig{Owner: owner}},25 {"invalid URL", tinygit.ServerConfig{DataDir: t.TempDir(), Owner: owner, PublicURL: "file:///tmp/git"}},26 } {27 t.Run(tc.name, func(t *testing.T) {28 s, err := tinygit.OpenServer(context.Background(), tc.cfg)29 if err == nil {30 s.Close()31 t.Fatal("invalid configuration accepted")32 }33 })34 }35}3637func TestStandaloneServerBoundsEventHTTP(t *testing.T) {38 owner := signedAnnouncement(t, strings.Repeat("0", 63)+"1").PubKey39 s, err := tinygit.OpenServer(context.Background(), tinygit.ServerConfig{DataDir: filepath.Join(t.TempDir(), "data"), Owner: owner})40 if err != nil {41 t.Fatal(err)42 }43 defer s.Close()44 for _, tc := range []struct {45 name, method, path, body string46 status int47 }{48 {"health", http.MethodGet, "/healthz", "", http.StatusOK},49 {"method", http.MethodGet, "/events", "", http.StatusMethodNotAllowed},50 {"body limit", http.MethodPost, "/events", strings.Repeat(" ", (1<<20)+1), http.StatusRequestEntityTooLarge},51 {"unsigned", http.MethodPost, "/events", `{}`, http.StatusBadRequest},52 } {53 t.Run(tc.name, func(t *testing.T) {54 w := httptest.NewRecorder()55 s.ServeHTTP(w, httptest.NewRequest(tc.method, tc.path, strings.NewReader(tc.body)))56 if w.Code != tc.status {57 t.Fatalf("HTTP = %d, want %d: %s", w.Code, tc.status, w.Body.String())58 }59 })60 }61}