mirror of
https://github.com/gtsteffaniak/filebrowser.git
synced 2026-11-27 00:49:41 -05:00
+11



![coderabbitai[bot]](/avatar/4a08c485fbe908b864e4cf902fddaff20a4dd8a58faf8f65f051648bd2ef3153?size=40)




45a14bf2f2
Signed-off-by: MichaIng <micha@dietpi.com> Co-authored-by: Kevin B. <kurami32_kbm@proton.me> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Mattijs Bliek <mattijs@mattijsbliek.com> Co-authored-by: GammelSami <39372285+GammelSami@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: yzxcj797 <54314860+yzxcj797@users.noreply.github.com> Co-authored-by: yzxcj797 <yzxcj797@users.noreply.github.com> Co-authored-by: DireMunchkin <dire.munchkin@proton.me> Co-authored-by: Chris <39135018+Chri6s@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Aditya Raj Singh <github@adityaraj.com> Co-authored-by: tbsagdic <86909795+tbsagdic@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Ethan Lee Qi Yang <pluscompanyhqDEPT@gmail.com> Co-authored-by: Aditya Raj Singh <aditya@bncw.in> Co-authored-by: MichaIng <micha@dietpi.com> Co-authored-by: FandacqkaCorp <david@davidyloreto.com> Co-authored-by: FandacqkaCorp <275647464+FandacqkaCorp@users.noreply.github.com> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: connorjfarrell <connorjfarrell@users.noreply.github.com>
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package web
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"testing/fstest"
|
|
)
|
|
|
|
func TestRootFontHandler_ValidFont(t *testing.T) {
|
|
prev := assetFs
|
|
assetFs = fstest.MapFS{
|
|
"fonts/roboto.woff2": &fstest.MapFile{Data: []byte("woff2-data")},
|
|
}
|
|
t.Cleanup(func() { assetFs = prev })
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/fonts/roboto.woff2", nil)
|
|
rec := httptest.NewRecorder()
|
|
rootFontHandler(rec, req)
|
|
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("status = %d, want %d", rec.Code, http.StatusOK)
|
|
}
|
|
body, err := io.ReadAll(rec.Body)
|
|
if err != nil {
|
|
t.Fatalf("read body: %v", err)
|
|
}
|
|
if string(body) != "woff2-data" {
|
|
t.Fatalf("body = %q, want %q", body, "woff2-data")
|
|
}
|
|
if rec.Header().Get("Content-Type") != "font/woff2" {
|
|
t.Fatalf("Content-Type = %q, want font/woff2", rec.Header().Get("Content-Type"))
|
|
}
|
|
if rec.Header().Get("Cache-Control") != "public, max-age=86400" {
|
|
t.Fatalf("unexpected Cache-Control: %s", rec.Header().Get("Cache-Control"))
|
|
}
|
|
}
|
|
|
|
func TestRootFontHandler_MissingFont(t *testing.T) {
|
|
prev := assetFs
|
|
assetFs = fstest.MapFS{}
|
|
t.Cleanup(func() { assetFs = prev })
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/fonts/missing.woff2", nil)
|
|
rec := httptest.NewRecorder()
|
|
rootFontHandler(rec, req)
|
|
|
|
if rec.Code != http.StatusNotFound {
|
|
t.Fatalf("status = %d, want %d", rec.Code, http.StatusNotFound)
|
|
}
|
|
}
|
|
|
|
func TestRootFontHandler_TraversalPath(t *testing.T) {
|
|
prev := assetFs
|
|
assetFs = fstest.MapFS{
|
|
"fonts/secret.woff2": &fstest.MapFile{Data: []byte("secret")},
|
|
}
|
|
t.Cleanup(func() { assetFs = prev })
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/fonts/../secret.woff2", nil)
|
|
rec := httptest.NewRecorder()
|
|
rootFontHandler(rec, req)
|
|
|
|
if rec.Code != http.StatusNotFound {
|
|
t.Fatalf("status = %d, want %d", rec.Code, http.StatusNotFound)
|
|
}
|
|
}
|