|
|
@@ -315,6 +315,52 @@ func TestProxyFilterWithHttpsInvalid(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func TestProxyFilterWithSrcset(t *testing.T) {
|
|
|
+ os.Clearenv()
|
|
|
+ os.Setenv("PROXY_IMAGES", "all")
|
|
|
+
|
|
|
+ var err error
|
|
|
+ parser := config.NewParser()
|
|
|
+ config.Opts, err = parser.ParseEnvironmentVariables()
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf(`Parsing failure: %v`, err)
|
|
|
+ }
|
|
|
+
|
|
|
+ r := mux.NewRouter()
|
|
|
+ r.HandleFunc("/proxy/{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 := imageProxyFilter(r, input)
|
|
|
+
|
|
|
+ if expected != output {
|
|
|
+ t.Errorf(`Not expected output: got %s`, output)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestProxyFilterWithPictureSource(t *testing.T) {
|
|
|
+ os.Clearenv()
|
|
|
+ os.Setenv("PROXY_IMAGES", "all")
|
|
|
+
|
|
|
+ var err error
|
|
|
+ parser := config.NewParser()
|
|
|
+ config.Opts, err = parser.ParseEnvironmentVariables()
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf(`Parsing failure: %v`, err)
|
|
|
+ }
|
|
|
+
|
|
|
+ r := mux.NewRouter()
|
|
|
+ r.HandleFunc("/proxy/{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"></picture>`
|
|
|
+ expected := `<picture><source srcset="/proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlMi5wbmc= 656w, /proxy/aHR0cDovL3dlYnNpdGUvZm9sZGVyL2ltYWdlMy5wbmc= 360w"/></picture>`
|
|
|
+ output := imageProxyFilter(r, input)
|
|
|
+
|
|
|
+ if expected != output {
|
|
|
+ t.Errorf(`Not expected output: got %s`, output)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestFormatFileSize(t *testing.T) {
|
|
|
scenarios := []struct {
|
|
|
input int64
|