Project

General

Profile

Bug #44317

Updated by Patrick Seidensal about 4 years ago

Some of the Grafana Unit Test in the backend are not using mocks properly and don't prevent requests being made to a configured HTTP address. In fact, it is required for the tests to pass, that no service is running on this address (`http://localhost:3000`). If a service is available at that port (usually a Grafana instance), the tests will fail: 

 <pre> 
 tests/test_grafana.py ....F 

 __________________________________________________________ GrafanaTest.test_validation ___________________________________________________________ 

 self = <dashboard.tests.test_grafana.GrafanaTest testMethod=test_validation> 

     def test_validation(self): 
         self.server_settings() 
         self._get('/api/grafana/validation/foo') 
 >         self.assertStatus(500) 

 tests/test_grafana.py:47:  
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  
 .tox/py3/lib/python3.6/site-packages/cheroot/test/webtest.py:325: in assertStatus 
     self._handlewebError(msg) 
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  

 self = <dashboard.tests.test_grafana.GrafanaTest testMethod=test_validation>, msg = 'Status 200 OK does not match 500' 

     def _handlewebError(self, msg): 
         print('') 
         print('      ERROR: %s' % msg) 
    
         if not self.interactive: 
 >             raise self.failureException(msg) 
 E             AssertionError: Status 200 OK does not match 500 

 .tox/py3/lib/python3.6/site-packages/cheroot/test/webtest.py:257: AssertionError 
 -------------------------------------------------------------- Captured stdout call -------------------------------------------------------------- 

     ERROR: Status 200 OK does not match 500 
 -------------------------------------------------------------- Captured stderr call -------------------------------------------------------------- 
 DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): localhost:3000 
 DEBUG:urllib3.connectionpool:http://localhost:3000 "GET /api/dashboards/uid/foo HTTP/1.1" 501 496 
 INFO:cherrypy.access.140271818942672:127.0.0.1 - - [27/Feb/2020:09:14:55] "GET /api/grafana/validation/foo HTTP/1.1" 200 3 "" "" 
 --------------------------------------------------------------- Captured log call ---------------------------------------------------------------- 
 </pre> 

 It should be ensured that no requests whatsoever are made from the backend that target external URLs. 

 h3. h1.  
 How to reproduce reproduce: 

 1. Run `python3 -c 'from http import server; s = server.HTTPServer(("", 3000), server.BaseHTTPRequestHandler); s.serve_forever()'` on the host where the unit test will run. 
 2. Run the unit test. 
 3. Observe stray requests being made, which are relied upon to not respond and hence result in failing tests. 

Back