Browse Source

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

Naoki Kambe 13 years ago
parent
commit
a48e7fa14f
2 changed files with 50 additions and 2 deletions
  1. 6 1
      src/bin/stats/stats_httpd.py.in
  2. 44 1
      src/bin/stats/tests/b10-stats-httpd_test.py

+ 6 - 1
src/bin/stats/stats_httpd.py.in

@@ -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:

+ 44 - 1
src/bin/stats/tests/b10-stats-httpd_test.py

@@ -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