@@ -7,18 +7,31 @@ import (
77 "testing"
88)
99
10- func inject (ci CopyInject , data string ) (found bool , dstdata string , err error ) {
10+ func inject (ci CopyInject , data string , contentType string ) (found bool , dstdata string , err error ) {
1111 src := bytes .NewBuffer ([]byte (data ))
1212 dst := bytes .NewBuffer (make ([]byte , 0 ))
13- injector , err := ci .Sniff (src )
13+ injector , err := ci .Sniff (src , contentType )
1414 if err != nil {
1515 return false , "" , err
1616 }
1717 _ , err = injector .Copy (dst )
1818 if err != nil {
1919 return false , "" , err
2020 }
21- return injector .Found , string (dst .Bytes ()), nil
21+ return injector .Found (), string (dst .Bytes ()), nil
22+ }
23+
24+ func TestReverseProxyNoInject (t * testing.T ) {
25+ ci := CopyInject {
26+ Within : 100 ,
27+ ContentType : "text/html" ,
28+ Marker : regexp .MustCompile ("mark" ),
29+ Payload : []byte ("inject" ),
30+ }
31+ found , dst , err := inject (ci , "imark" , "text/plain" )
32+ if err != nil || found || dst != "imark" {
33+ t .Errorf ("Unexpected, found:%v dst:%v error:%v" , dst , found , err )
34+ }
2235}
2336
2437func TestReverseProxy (t * testing.T ) {
@@ -43,11 +56,12 @@ func TestReverseProxy(t *testing.T) {
4356 }
4457 for i , tt := range sniffTests {
4558 ci := CopyInject {
46- Within : tt .snifflen ,
47- Marker : regexp .MustCompile (tt .marker ),
48- Payload : []byte (tt .payload ),
59+ Within : tt .snifflen ,
60+ ContentType : "text/html" ,
61+ Marker : regexp .MustCompile (tt .marker ),
62+ Payload : []byte (tt .payload ),
4963 }
50- found , dst , err := inject (ci , tt .src )
64+ found , dst , err := inject (ci , tt .src , "text/html" )
5165
5266 // Sanity checkss
5367 if err != nil {
@@ -74,7 +88,7 @@ func TestReverseProxy(t *testing.T) {
7488 }
7589
7690 // Idempotence
77- found , dst2 , err := inject (ci , dst )
91+ found , dst2 , err := inject (ci , dst , "text/html" )
7892 if err != nil {
7993 t .Errorf ("Test %d, unexpected error:\n %s\n " , i , err )
8094 }
@@ -91,8 +105,8 @@ func TestNil(t *testing.T) {
91105 ci := CopyInject {}
92106 val := "onetwothree"
93107 src := bytes .NewBuffer ([]byte (val ))
94- injector , err := ci .Sniff (src )
95- if injector .Found || err != nil {
108+ injector , err := ci .Sniff (src , "" )
109+ if injector .Found () || err != nil {
96110 t .Error ("Unexpected" )
97111 }
98112 dst := bytes .NewBuffer (make ([]byte , 0 ))
0 commit comments