|
|
@@ -15,7 +15,9 @@ import (
|
|
|
|
|
|
func TestProxyFilterWithHttpDefault(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "http-only")
|
|
|
+ os.Setenv("PROXY_OPTION", "http-only")
|
|
|
+ os.Setenv("PROXY_MEDIA_TYPES", "image")
|
|
|
+ os.Setenv("PROXY_PRIVATE_KEY", "test")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -25,11 +27,11 @@ func TestProxyFilterWithHttpDefault(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<p><img src="http://website/folder/image.png" alt="Test"/></p>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
- expected := `<p><img src="/proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" alt="Test"/></p>`
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
+ expected := `<p><img src="/proxy/okK5PsdNY8F082UMQEAbLPeUFfbe2WnNfInNmR9T4WA=/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" alt="Test"/></p>`
|
|
|
|
|
|
if expected != output {
|
|
|
t.Errorf(`Not expected output: got "%s" instead of "%s"`, output, expected)
|
|
|
@@ -38,7 +40,8 @@ func TestProxyFilterWithHttpDefault(t *testing.T) {
|
|
|
|
|
|
func TestProxyFilterWithHttpsDefault(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "http-only")
|
|
|
+ os.Setenv("PROXY_OPTION", "http-only")
|
|
|
+ os.Setenv("PROXY_MEDIA_TYPES", "image")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -48,10 +51,10 @@ func TestProxyFilterWithHttpsDefault(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<p><img src="https://website/folder/image.png" alt="Test"/></p>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
expected := `<p><img src="https://website/folder/image.png" alt="Test"/></p>`
|
|
|
|
|
|
if expected != output {
|
|
|
@@ -61,7 +64,7 @@ func TestProxyFilterWithHttpsDefault(t *testing.T) {
|
|
|
|
|
|
func TestProxyFilterWithHttpNever(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "none")
|
|
|
+ os.Setenv("PROXY_OPTION", "none")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -71,10 +74,10 @@ func TestProxyFilterWithHttpNever(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<p><img src="http://website/folder/image.png" alt="Test"/></p>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
expected := input
|
|
|
|
|
|
if expected != output {
|
|
|
@@ -84,7 +87,7 @@ func TestProxyFilterWithHttpNever(t *testing.T) {
|
|
|
|
|
|
func TestProxyFilterWithHttpsNever(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "none")
|
|
|
+ os.Setenv("PROXY_OPTION", "none")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -94,10 +97,10 @@ func TestProxyFilterWithHttpsNever(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<p><img src="https://website/folder/image.png" alt="Test"/></p>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
expected := input
|
|
|
|
|
|
if expected != output {
|
|
|
@@ -107,7 +110,9 @@ func TestProxyFilterWithHttpsNever(t *testing.T) {
|
|
|
|
|
|
func TestProxyFilterWithHttpAlways(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "all")
|
|
|
+ os.Setenv("PROXY_OPTION", "all")
|
|
|
+ os.Setenv("PROXY_MEDIA_TYPES", "image")
|
|
|
+ os.Setenv("PROXY_PRIVATE_KEY", "test")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -117,11 +122,11 @@ func TestProxyFilterWithHttpAlways(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<p><img src="http://website/folder/image.png" alt="Test"/></p>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
- expected := `<p><img src="/proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" alt="Test"/></p>`
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
+ expected := `<p><img src="/proxy/okK5PsdNY8F082UMQEAbLPeUFfbe2WnNfInNmR9T4WA=/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" alt="Test"/></p>`
|
|
|
|
|
|
if expected != output {
|
|
|
t.Errorf(`Not expected output: got "%s" instead of "%s"`, output, expected)
|
|
|
@@ -130,7 +135,9 @@ func TestProxyFilterWithHttpAlways(t *testing.T) {
|
|
|
|
|
|
func TestProxyFilterWithHttpsAlways(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "all")
|
|
|
+ os.Setenv("PROXY_OPTION", "all")
|
|
|
+ os.Setenv("PROXY_MEDIA_TYPES", "image")
|
|
|
+ os.Setenv("PROXY_PRIVATE_KEY", "test")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -140,11 +147,11 @@ func TestProxyFilterWithHttpsAlways(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<p><img src="https://website/folder/image.png" alt="Test"/></p>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
- expected := `<p><img src="/proxy/aHR0cHM6Ly93ZWJzaXRlL2ZvbGRlci9pbWFnZS5wbmc=" alt="Test"/></p>`
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
+ expected := `<p><img src="/proxy/LdPNR1GBDigeeNp2ArUQRyZsVqT_PWLfHGjYFrrWWIY=/aHR0cHM6Ly93ZWJzaXRlL2ZvbGRlci9pbWFnZS5wbmc=" alt="Test"/></p>`
|
|
|
|
|
|
if expected != output {
|
|
|
t.Errorf(`Not expected output: got "%s" instead of "%s"`, output, expected)
|
|
|
@@ -153,8 +160,9 @@ func TestProxyFilterWithHttpsAlways(t *testing.T) {
|
|
|
|
|
|
func TestProxyFilterWithHttpsAlwaysAndCustomProxyServer(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "all")
|
|
|
- os.Setenv("PROXY_IMAGE_URL", "https://proxy-example/proxy")
|
|
|
+ os.Setenv("PROXY_OPTION", "all")
|
|
|
+ os.Setenv("PROXY_MEDIA_TYPES", "image")
|
|
|
+ os.Setenv("PROXY_URL", "https://proxy-example/proxy")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -164,10 +172,10 @@ func TestProxyFilterWithHttpsAlwaysAndCustomProxyServer(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<p><img src="https://website/folder/image.png" alt="Test"/></p>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
expected := `<p><img src="https://proxy-example/proxy/aHR0cHM6Ly93ZWJzaXRlL2ZvbGRlci9pbWFnZS5wbmc=" alt="Test"/></p>`
|
|
|
|
|
|
if expected != output {
|
|
|
@@ -177,7 +185,8 @@ func TestProxyFilterWithHttpsAlwaysAndCustomProxyServer(t *testing.T) {
|
|
|
|
|
|
func TestProxyFilterWithHttpInvalid(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "invalid")
|
|
|
+ os.Setenv("PROXY_OPTION", "invalid")
|
|
|
+ os.Setenv("PROXY_PRIVATE_KEY", "test")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -187,11 +196,11 @@ func TestProxyFilterWithHttpInvalid(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<p><img src="http://website/folder/image.png" alt="Test"/></p>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
- expected := `<p><img src="/proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" alt="Test"/></p>`
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
+ expected := `<p><img src="/proxy/okK5PsdNY8F082UMQEAbLPeUFfbe2WnNfInNmR9T4WA=/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" alt="Test"/></p>`
|
|
|
|
|
|
if expected != output {
|
|
|
t.Errorf(`Not expected output: got "%s" instead of "%s"`, output, expected)
|
|
|
@@ -200,7 +209,8 @@ func TestProxyFilterWithHttpInvalid(t *testing.T) {
|
|
|
|
|
|
func TestProxyFilterWithHttpsInvalid(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "invalid")
|
|
|
+ os.Setenv("PROXY_OPTION", "invalid")
|
|
|
+ os.Setenv("PROXY_PRIVATE_KEY", "test")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -210,10 +220,10 @@ func TestProxyFilterWithHttpsInvalid(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<p><img src="https://website/folder/image.png" alt="Test"/></p>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
expected := `<p><img src="https://website/folder/image.png" alt="Test"/></p>`
|
|
|
|
|
|
if expected != output {
|
|
|
@@ -223,7 +233,9 @@ func TestProxyFilterWithHttpsInvalid(t *testing.T) {
|
|
|
|
|
|
func TestProxyFilterWithSrcset(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "all")
|
|
|
+ os.Setenv("PROXY_OPTION", "all")
|
|
|
+ os.Setenv("PROXY_MEDIA_TYPES", "image")
|
|
|
+ os.Setenv("PROXY_PRIVATE_KEY", "test")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -233,11 +245,11 @@ func TestProxyFilterWithSrcset(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<p><img src="http://website/folder/image.png" srcset="http://website/folder/image2.png 656w, http://website/folder/image3.png 360w" alt="test"></p>`
|
|
|
- expected := `<p><img src="/proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" srcset="/proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlMi5wbmc= 656w, /proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlMy5wbmc= 360w" alt="test"/></p>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
+ expected := `<p><img src="/proxy/okK5PsdNY8F082UMQEAbLPeUFfbe2WnNfInNmR9T4WA=/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" srcset="/proxy/aY5Hb4urDnUCly2vTJ7ExQeeaVS-52O7kjUr2v9VrAs=/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlMi5wbmc= 656w, /proxy/QgAmrJWiAud_nNAsz3F8OTxaIofwAiO36EDzH_YfMzo=/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlMy5wbmc= 360w" alt="test"/></p>`
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
|
|
|
if expected != output {
|
|
|
t.Errorf(`Not expected output: got %s`, output)
|
|
|
@@ -246,7 +258,9 @@ func TestProxyFilterWithSrcset(t *testing.T) {
|
|
|
|
|
|
func TestProxyFilterWithEmptySrcset(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "all")
|
|
|
+ os.Setenv("PROXY_OPTION", "all")
|
|
|
+ os.Setenv("PROXY_MEDIA_TYPES", "image")
|
|
|
+ os.Setenv("PROXY_PRIVATE_KEY", "test")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -256,11 +270,11 @@ func TestProxyFilterWithEmptySrcset(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<p><img src="http://website/folder/image.png" srcset="" alt="test"></p>`
|
|
|
- expected := `<p><img src="/proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" srcset="" alt="test"/></p>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
+ expected := `<p><img src="/proxy/okK5PsdNY8F082UMQEAbLPeUFfbe2WnNfInNmR9T4WA=/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlLnBuZw==" srcset="" alt="test"/></p>`
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
|
|
|
if expected != output {
|
|
|
t.Errorf(`Not expected output: got %s`, output)
|
|
|
@@ -269,7 +283,9 @@ func TestProxyFilterWithEmptySrcset(t *testing.T) {
|
|
|
|
|
|
func TestProxyFilterWithPictureSource(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "all")
|
|
|
+ os.Setenv("PROXY_OPTION", "all")
|
|
|
+ os.Setenv("PROXY_MEDIA_TYPES", "image")
|
|
|
+ os.Setenv("PROXY_PRIVATE_KEY", "test")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -279,11 +295,11 @@ func TestProxyFilterWithPictureSource(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<picture><source srcset="http://website/folder/image2.png 656w, http://website/folder/image3.png 360w, https://website/some,image.png 2x"></picture>`
|
|
|
- expected := `<picture><source srcset="/proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlMi5wbmc= 656w, /proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlMy5wbmc= 360w, /proxy/aHR0cHM6Ly93ZWJzaXRlL3NvbWUsaW1hZ2UucG5n 2x"/></picture>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
+ expected := `<picture><source srcset="/proxy/aY5Hb4urDnUCly2vTJ7ExQeeaVS-52O7kjUr2v9VrAs=/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlMi5wbmc= 656w, /proxy/QgAmrJWiAud_nNAsz3F8OTxaIofwAiO36EDzH_YfMzo=/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlMy5wbmc= 360w, /proxy/ZIw0hv8WhSTls5aSqhnFaCXlUrKIqTnBRaY0-NaLnds=/aHR0cHM6Ly93ZWJzaXRlL3NvbWUsaW1hZ2UucG5n 2x"/></picture>`
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
|
|
|
if expected != output {
|
|
|
t.Errorf(`Not expected output: got %s`, output)
|
|
|
@@ -292,7 +308,9 @@ func TestProxyFilterWithPictureSource(t *testing.T) {
|
|
|
|
|
|
func TestProxyFilterOnlyNonHTTPWithPictureSource(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "https")
|
|
|
+ os.Setenv("PROXY_OPTION", "https")
|
|
|
+ os.Setenv("PROXY_MEDIA_TYPES", "image")
|
|
|
+ os.Setenv("PROXY_PRIVATE_KEY", "test")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -302,20 +320,21 @@ func TestProxyFilterOnlyNonHTTPWithPictureSource(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<picture><source srcset="http://website/folder/image2.png 656w, https://website/some,image.png 2x"></picture>`
|
|
|
- expected := `<picture><source srcset="/proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlMi5wbmc= 656w, https://website/some,image.png 2x"/></picture>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
+ expected := `<picture><source srcset="/proxy/aY5Hb4urDnUCly2vTJ7ExQeeaVS-52O7kjUr2v9VrAs=/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlMi5wbmc= 656w, https://website/some,image.png 2x"/></picture>`
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
|
|
|
if expected != output {
|
|
|
t.Errorf(`Not expected output: got %s`, output)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestImageProxyWithImageDataURL(t *testing.T) {
|
|
|
+func TestProxyWithImageDataURL(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "all")
|
|
|
+ os.Setenv("PROXY_OPTION", "all")
|
|
|
+ os.Setenv("PROXY_MEDIA_TYPES", "image")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -325,20 +344,21 @@ func TestImageProxyWithImageDataURL(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<img src="data:image/gif;base64,test">`
|
|
|
expected := `<img src="data:image/gif;base64,test"/>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
|
|
|
if expected != output {
|
|
|
t.Errorf(`Not expected output: got %s`, output)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestImageProxyWithImageSourceDataURL(t *testing.T) {
|
|
|
+func TestProxyWithImageSourceDataURL(t *testing.T) {
|
|
|
os.Clearenv()
|
|
|
- os.Setenv("PROXY_IMAGES", "all")
|
|
|
+ os.Setenv("PROXY_OPTION", "all")
|
|
|
+ os.Setenv("PROXY_MEDIA_TYPES", "image")
|
|
|
|
|
|
var err error
|
|
|
parser := config.NewParser()
|
|
|
@@ -348,11 +368,11 @@ func TestImageProxyWithImageSourceDataURL(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
- r.HandleFunc("/proxy/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
+ r.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", func(w http.ResponseWriter, r *http.Request) {}).Name("proxy")
|
|
|
|
|
|
input := `<picture><source srcset="data:image/gif;base64,test"/></picture>`
|
|
|
expected := `<picture><source srcset="data:image/gif;base64,test"/></picture>`
|
|
|
- output := ImageProxyRewriter(r, input)
|
|
|
+ output := ProxyRewriter(r, input)
|
|
|
|
|
|
if expected != output {
|
|
|
t.Errorf(`Not expected output: got %s`, output)
|