Commit a48e7fa1 authored by Naoki Kambe's avatar Naoki Kambe
Browse files

[917] return 404 NotFound when specified module name or item name is not found

parent 62809f71
......@@ -120,7 +120,12 @@ class HttpHandler(http.server.BaseHTTPRequestHandler):
self.send_error(404)
return None
except StatsHttpdError as err:
self.send_error(500)
# Couldn't find neither specified module name nor
# specified item name
if str(err).startswith('Stats module: specified arguments are incorrect:'):
self.send_error(404)
else:
self.send_error(500)
logger.error(STATHTTPD_SERVER_ERROR, err)
return None
else:
......
......@@ -266,13 +266,56 @@ class TestHttpHandler(unittest.TestCase):
self.assertEqual(response.getheader('Location'),
"http://%s:%d%s" % (self.address, self.port, stats_httpd.XML_URL_PATH))
# 404 NotFound
# 404 NotFound (random path)
self.client._http_vsn_str = 'HTTP/1.0'
self.client.putrequest('GET', '/path/to/foo/bar')
self.client.endheaders()
response = self.client.getresponse()
self.assertEqual(response.status, 404)
self.client._http_vsn_str = 'HTTP/1.0'
self.client.putrequest('GET', '/bind10/foo')
self.client.endheaders()
response = self.client.getresponse()
self.assertEqual(response.status, 404)
self.client._http_vsn_str = 'HTTP/1.0'
self.client.putrequest('GET', '/bind10/statistics/foo')
self.client.endheaders()
response = self.client.getresponse()
self.assertEqual(response.status, 404)
# 404 NotFound (nonexistent module name)
self.client._http_vsn_str = 'HTTP/1.0'
self.client.putrequest('GET', '/bind10/statistics/xml/Foo')
self.client.endheaders()
response = self.client.getresponse()
self.assertEqual(response.status, 404)
self.client._http_vsn_str = 'HTTP/1.0'
self.client.putrequest('GET', '/bind10/statistics/xsd/Foo')
self.client.endheaders()
response = self.client.getresponse()
self.assertEqual(response.status, 404)
self.client._http_vsn_str = 'HTTP/1.0'
self.client.putrequest('GET', '/bind10/statistics/xsl/Foo')
self.client.endheaders()
response = self.client.getresponse()
self.assertEqual(response.status, 404)
# 404 NotFound (nonexistent item name)
self.client._http_vsn_str = 'HTTP/1.0'
self.client.putrequest('GET', '/bind10/statistics/xml/Foo/bar')
self.client.endheaders()
response = self.client.getresponse()
self.assertEqual(response.status, 404)
self.client._http_vsn_str = 'HTTP/1.0'
self.client.putrequest('GET', '/bind10/statistics/xsd/Foo/bar')
self.client.endheaders()
response = self.client.getresponse()
self.assertEqual(response.status, 404)
self.client._http_vsn_str = 'HTTP/1.0'
self.client.putrequest('GET', '/bind10/statistics/xsl/Foo/bar')
self.client.endheaders()
response = self.client.getresponse()
self.assertEqual(response.status, 404)
def test_do_GET_failed1(self):
# checks status
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment