refactor(backend): rename mediacore package to media
This commit is contained in:
1 parent
e8cb7c6c68
commit
75c08beec6
34 files changed
+837
-656
No files matched your search
@@ -0,0 +1,46 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user