test(media): verify question marks in stored paths are escaped

This commit is contained in:
Gabriel20xx committed 2026-11-21 12:10:44 +01:00
1 parent 8701874efb
commit 170c7570e4
1 file changed
+13 -1
+13 -1
View File
@@ -217,7 +217,7 @@ func TestMediaStreamAndThumbnailAgainstPostgres(t *testing.T) {
t.Run("unsafe stored paths and unknown keys are not found, and never reach CarrierNode", func(t *testing.T) { t.Run("unsafe stored paths and unknown keys are not found, and never reach CarrierNode", func(t *testing.T) {
before := len(h.carrier.seen()) before := len(h.carrier.seen())
for _, key := range []string{"rt-escape", "rt-query", "rt-missing", ""} { for _, key := range []string{"rt-escape", "rt-missing", ""} {
if code := h.do(http.MethodGet, "/media/stream?mediaKey="+key, "alice-token", "").Code; code != http.StatusNotFound { if code := h.do(http.MethodGet, "/media/stream?mediaKey="+key, "alice-token", "").Code; code != http.StatusNotFound {
t.Errorf("stream of %q status = %d, want 404", key, code) t.Errorf("stream of %q status = %d, want 404", key, code)
} }
@@ -227,6 +227,18 @@ func TestMediaStreamAndThumbnailAgainstPostgres(t *testing.T) {
} }
}) })
t.Run("question marks in stored paths are escaped as filename characters", func(t *testing.T) {
before := len(h.carrier.seen())
response := h.do(http.MethodGet, "/media/stream?mediaKey=rt-query", "alice-token", "")
if response.Code != http.StatusOK || response.Body.String() != "BYTES" {
t.Fatalf("stream of rt-query = %d %q, want the proxied bytes", response.Code, response.Body.String())
}
got := h.carrier.seen()
if len(got) != before+1 || got[len(got)-1] != "GET /media/a%3Fb.mp4" {
t.Fatalf("CarrierNode requests after streaming rt-query = %v, want one GET of /media/a%%3Fb.mp4", got[before:])
}
})
t.Run("hidden media is visible to moderators only", func(t *testing.T) { t.Run("hidden media is visible to moderators only", func(t *testing.T) {
for _, target := range []string{"/media/stream?mediaKey=rt-hidden", "/media/thumb?mediaKey=rt-hidden"} { for _, target := range []string{"/media/stream?mediaKey=rt-hidden", "/media/thumb?mediaKey=rt-hidden"} {
if code := h.do(http.MethodGet, target, "alice-token", "").Code; code != http.StatusNotFound { if code := h.do(http.MethodGet, target, "alice-token", "").Code; code != http.StatusNotFound {