@@ -803,6 +803,52 @@ func TestVerifiedCacheBypasses(t *testing.T) {
803803 }
804804}
805805
806+ func TestShouldApplyRegexExcludeRoutesIgnoreQueryString (t * testing.T ) {
807+ config := CreateConfig ()
808+ config .SiteKey = "test"
809+ config .SecretKey = "test"
810+ config .Mode = "regex"
811+ config .ProtectRoutes = []string {"^/" }
812+ config .ExcludeRoutes = []string {`\/oai\/request` , `\/node\/\d+\/(book-)?manifest` }
813+ config .RateLimit = 0
814+
815+ bc , err := NewCaptchaProtect (context .Background (), nil , config , "test" )
816+ if err != nil {
817+ t .Fatalf ("unexpected error %v" , err )
818+ }
819+
820+ tests := []struct {
821+ name string
822+ url string
823+ want bool
824+ }{
825+ {
826+ name : "query string does not prevent exclude route match" ,
827+ url : "http://example.com/oai/request?foo=bar" ,
828+ want : false ,
829+ },
830+ {
831+ name : "regex exclude route matches manifest path" ,
832+ url : "http://example.com/node/123/manifest" ,
833+ want : false ,
834+ },
835+ {
836+ name : "non excluded route still protected" ,
837+ url : "http://example.com/node/123/other" ,
838+ want : true ,
839+ },
840+ }
841+
842+ for _ , tt := range tests {
843+ t .Run (tt .name , func (t * testing.T ) {
844+ req := httptest .NewRequest (http .MethodGet , tt .url , nil )
845+ if got := bc .shouldApply (req , "1.2.3.4" ); got != tt .want {
846+ t .Errorf ("shouldApply(%q) = %v; want %v" , tt .url , got , tt .want )
847+ }
848+ })
849+ }
850+ }
851+
806852func TestStatsPage (t * testing.T ) {
807853 config := CreateConfig ()
808854 config .SiteKey = "test"
0 commit comments