/* if this is a request for the API,
check if the API key is correct */
if (req.url.path=="/jsonstat" ||
- req.url.path=="/api/v1/servers/localhost" ||
- req.url.path=="/api/v1/servers/localhost/config" ||
- req.url.path=="/api/v1/servers/localhost/config/allow-from" ||
- req.url.path=="/api/v1/servers/localhost/statistics") {
+ req.url.path.find("/api/") == 0) {
header = req.headers.find("x-api-key");
if (header != req.headers.end()) {
auth_ok = (0==strcmp(header->second.c_str(), expectedApiKey.c_str()));
for key in ['id', 'queries']:
self.assertTrue(frontend[key] >= 0)
+ def testServersIDontExist(self):
+ """
+ API: /api/v1/servers/idontexist (should be 404)
+ """
+ headers = {'x-api-key': self._webServerAPIKey}
+ url = 'http://127.0.0.1:' + str(self._webServerPort) + '/api/v1/servers/idontexist'
+ r = requests.get(url, headers=headers, timeout=self._webTimeout)
+ self.assertEquals(r.status_code, 404)
+
def testServersLocalhostConfig(self):
"""
API: /api/v1/servers/localhost/config