Sync shared snapshot from 9e58b6d
This commit is contained in:
1 parent
36ab01aab1
commit
5a4bf45bc7
10 files changed
+393
-51
No files matched your search
@@ -1,24 +1,50 @@
|
||||
package media
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUpstreamMediaPathRefusesQueryFragmentAndTraversal(t *testing.T) {
|
||||
for _, stored := range []string{"x?y.mp4", "a#b.mp4", "../x.mp4", "media/../../x.mp4", `..\x.mp4`} {
|
||||
func TestUpstreamMediaPathRefusesTraversal(t *testing.T) {
|
||||
for _, stored := range []string{"../x.mp4", "media/../../x.mp4", `..\x.mp4`} {
|
||||
if _, ok := upstreamMediaPath(stored); ok {
|
||||
t.Errorf("upstreamMediaPath(%q) accepted, want refused", stored)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CarrierNode's router matches a raw request path literally, so a name must reach it with no raw path:
|
||||
// a %2C for a comma would never match "Hello, World.mp4". Query and fragment markers are escaped, not refused.
|
||||
func TestUpstreamMediaPathReachesCarrierNodeAsTheLiteralName(t *testing.T) {
|
||||
for _, stored := range []string{"Hello, World.mp4", "a;b.mp4", "x?y.mp4", "a#b.mp4", "100%.mp4", "dir one/x y.mp4"} {
|
||||
upstream, ok := upstreamMediaPath(stored)
|
||||
if !ok {
|
||||
t.Fatalf("upstreamMediaPath(%q) refused", stored)
|
||||
}
|
||||
request, err := http.NewRequest(http.MethodGet, "http://carrier.example/media/"+upstream, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("NewRequest for %q: %v", stored, err)
|
||||
}
|
||||
if request.URL.RawPath != "" {
|
||||
t.Errorf("%q produced raw path %q; CarrierNode would match that instead of the name", stored, request.URL.RawPath)
|
||||
}
|
||||
if want := "/media/" + urlPath(stored); request.URL.Path != want {
|
||||
t.Errorf("%q decodes to %q, want %q", stored, request.URL.Path, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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",
|
||||
"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",
|
||||
"Hello, World.mp4": "Hello,%20World.mp4",
|
||||
"a;b.mp4": "a;b.mp4",
|
||||
"x?y.mp4": "x%3Fy.mp4",
|
||||
"a#b.mp4": "a%23b.mp4",
|
||||
}
|
||||
for stored, want := range cases {
|
||||
got, ok := upstreamMediaPath(stored)
|
||||
|
||||
Reference in new issue
Block a user