@@ -2155,5 +2155,59 @@ def test_json_query_has_header(self):
21552155 conn .close ()
21562156
21572157
2158+ # ===================================================================
2159+ # 1.0.6 tests — URL validation
2160+ # ===================================================================
2161+
2162+ class TestURLValidation (unittest .TestCase ):
2163+ """Solr constructor should warn on suspicious URLs."""
2164+
2165+ def test_valid_url_no_warning (self ):
2166+ import warnings
2167+ with warnings .catch_warnings (record = True ) as w :
2168+ warnings .simplefilter ("always" )
2169+ conn = solr .Solr (SOLR_HTTP , response_format = 'xml' )
2170+ solr_warnings = [x for x in w if 'solrpy' in str (x .message )]
2171+ self .assertEqual (len (solr_warnings ), 0 )
2172+ conn .close ()
2173+
2174+ def test_url_ending_with_solr_no_warning (self ):
2175+ import warnings
2176+ with warnings .catch_warnings (record = True ) as w :
2177+ warnings .simplefilter ("always" )
2178+ conn = solr .Solr ('http://localhost:8983/solr' , response_format = 'xml' )
2179+ solr_warnings = [x for x in w if 'solrpy' in str (x .message )]
2180+ self .assertEqual (len (solr_warnings ), 0 )
2181+ conn .close ()
2182+
2183+ def test_suspicious_url_warns (self ):
2184+ import warnings
2185+ with warnings .catch_warnings (record = True ) as w :
2186+ warnings .simplefilter ("always" )
2187+ conn = solr .Solr ('http://localhost:8983/search' , response_format = 'xml' )
2188+ solr_warnings = [x for x in w if 'solrpy' in str (x .message )]
2189+ self .assertEqual (len (solr_warnings ), 1 )
2190+ self .assertIn ('/solr' , str (solr_warnings [0 ].message ))
2191+ conn .close ()
2192+
2193+ def test_root_url_warns (self ):
2194+ import warnings
2195+ with warnings .catch_warnings (record = True ) as w :
2196+ warnings .simplefilter ("always" )
2197+ conn = solr .Solr ('http://localhost:8983/' , response_format = 'xml' )
2198+ solr_warnings = [x for x in w if 'solrpy' in str (x .message )]
2199+ self .assertEqual (len (solr_warnings ), 1 )
2200+ conn .close ()
2201+
2202+ def test_url_with_solr_in_path_no_warning (self ):
2203+ import warnings
2204+ with warnings .catch_warnings (record = True ) as w :
2205+ warnings .simplefilter ("always" )
2206+ conn = solr .Solr ('http://localhost:8983/solr/mycore' , response_format = 'xml' )
2207+ solr_warnings = [x for x in w if 'solrpy' in str (x .message )]
2208+ self .assertEqual (len (solr_warnings ), 0 )
2209+ conn .close ()
2210+
2211+
21582212if __name__ == "__main__" :
21592213 unittest .main ()
0 commit comments