From e98f0edb56f3d2355adf83a79edcc8ec2fa65a18 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 7 May 2026 00:41:45 +0300 Subject: Fix static file read seeker guard for s0 --- internal/api/handlers_more_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'internal/api/handlers_more_test.go') diff --git a/internal/api/handlers_more_test.go b/internal/api/handlers_more_test.go index 6a4353e..0403f25 100644 --- a/internal/api/handlers_more_test.go +++ b/internal/api/handlers_more_test.go @@ -196,6 +196,36 @@ func TestServer_ServeFile_notFound(t *testing.T) { } } +type statErrorFS struct{} + +func (statErrorFS) Open(string) (http.File, error) { + return statErrorFile{}, nil +} + +type statErrorFile struct{} + +func (statErrorFile) Close() error { return nil } + +func (statErrorFile) Read([]byte) (int, error) { return 0, io.EOF } + +func (statErrorFile) Seek(int64, int) (int64, error) { return 0, nil } + +func (statErrorFile) Readdir(int) ([]os.FileInfo, error) { return nil, nil } + +func (statErrorFile) Stat() (os.FileInfo, error) { return nil, errors.New("stat failed") } + +func TestServer_ServeFile_statError(t *testing.T) { + srv := &Server{staticFS: statErrorFS{}} + req := httptest.NewRequest(http.MethodGet, "/", nil) + rr := httptest.NewRecorder() + + srv.serveFile(rr, req, "index.html") + + if rr.Code != http.StatusNotFound { + t.Fatalf("expected %d, got %d", http.StatusNotFound, rr.Code) + } +} + // ------------------------------------------------------------------ // Bootstrap negative paths // ------------------------------------------------------------------ -- cgit v1.2.3