Lint / Lint (push) Successful in 1m29s
Security / Secrets (gitleaks) (push) Successful in 1m11s
Security / Dependencies (Trivy) (push) Successful in 1m59s
Tests / Dashboard checks (push) Successful in 1m49s
Security / Code (Semgrep) (push) Successful in 3m8s
Tests / Go backend (push) Successful in 2m50s
Docker / Docker Build & Push (push) Successful in 8m42s
- Target API 37 and use build-tools 37 for release signature checks - Adjust list pagination spacing and clarify shared backend docs
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package media
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestUpstreamMediaPathRefusesQueryFragmentAndTraversal(t *testing.T) {
|
|
for _, stored := range []string{"x?y.mp4", "a#b.mp4", "../x.mp4", "media/../../x.mp4", `..\x.mp4`} {
|
|
if _, ok := upstreamMediaPath(stored); ok {
|
|
t.Errorf("upstreamMediaPath(%q) accepted, want refused", stored)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestUpstreamMediaPathEscapesEachSegment(t *testing.T) {
|
|
cases := map[string]string{
|
|
"clips/clip.mp4": "clips/clip.mp4",
|
|
"my clip.mp4": "my%20clip.mp4",
|
|
"100%.mp4": "100%25.mp4",
|
|
"media/a b/c.mp4": "a%20b/c.mp4",
|
|
"/leading.mp4": "leading.mp4",
|
|
}
|
|
for stored, want := range cases {
|
|
got, ok := upstreamMediaPath(stored)
|
|
if !ok || got != want {
|
|
t.Errorf("upstreamMediaPath(%q) = %q, %v; want %q", stored, got, ok, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCanonicalMediaIDAcceptsOnlyCanonicalDecimals(t *testing.T) {
|
|
for _, value := range []string{"", "007", "+1", "-1", "4a", " 4", "4 ", "99999999999999999999"} {
|
|
if id, ok := canonicalMediaID(value); ok {
|
|
t.Errorf("canonicalMediaID(%q) = %d, want refused", value, id)
|
|
}
|
|
}
|
|
if id, ok := canonicalMediaID("42"); !ok || id != 42 {
|
|
t.Errorf("canonicalMediaID(42) = %d, %v; want 42, true", id, ok)
|
|
}
|
|
if mediaIDArg("abc") != nil {
|
|
t.Error("mediaIDArg(non-numeric) is not NULL")
|
|
}
|
|
if mediaIDArg("42") != int64(42) {
|
|
t.Error("mediaIDArg(42) is not 42")
|
|
}
|
|
}
|