Parcourir la source

[917] add two changes to stats_httpd.py and its unittest

 - change the relative path to the absolute path because in the case of the
   relative path refering to the other item is failed

 - The too long path is to be NotFound

 - change the condition of addition of anchor tag if depth levels of path are
   equal to or greater than 3, do not add the anchor tag.
Naoki Kambe il y a 13 ans
Parent
commit
6b600cb181
2 fichiers modifiés avec 28 ajouts et 10 suppressions
  1. 20 9
      src/bin/stats/stats_httpd.py.in
  2. 8 1
      src/bin/stats/tests/b10-stats-httpd_test.py

+ 20 - 9
src/bin/stats/stats_httpd.py.in

@@ -92,12 +92,18 @@ class HttpHandler(http.server.BaseHTTPRequestHandler):
             req_path = os.path.normpath(req_path)
             req_path = os.path.normpath(req_path)
             path_dirs = req_path.split('/')
             path_dirs = req_path.split('/')
             path_dirs = [ d for d in filter(None, path_dirs) ]
             path_dirs = [ d for d in filter(None, path_dirs) ]
+            req_path = '/'+"/".join(path_dirs)
+            # The too long path is to be NotFound
+            # in case of /bind10/statistics/xxx/YYY/zzz/aaa
+            if len(path_dirs) > 5:
+                self.send_error(404)
+                return None
             module_name = None
             module_name = None
             item_name = None
             item_name = None
-            # in case of /bind10/statistics/xxx/YYY/zzz/
+            # in case of /bind10/statistics/xxx/YYY/zzz
             if len(path_dirs) >= 5:
             if len(path_dirs) >= 5:
                 item_name = path_dirs[4]
                 item_name = path_dirs[4]
-            # in case of /bind10/statistics/xxx/YYY/
+            # in case of /bind10/statistics/xxx/YYY
             if len(path_dirs) >= 4:
             if len(path_dirs) >= 4:
                 module_name = path_dirs[3]
                 module_name = path_dirs[3]
             if req_path.startswith(XML_URL_PATH):
             if req_path.startswith(XML_URL_PATH):
@@ -592,7 +598,7 @@ class StatsHttpd:
     def xsl_handler(self, module_name=None, item_name=None):
     def xsl_handler(self, module_name=None, item_name=None):
         """Handler which just returns the body of XSL document"""
         """Handler which just returns the body of XSL document"""
 
 
-        def stats_spec2xsl(stats_spec, xsl_elem, path='.'):
+        def stats_spec2xsl(stats_spec, xsl_elem, path=XML_URL_PATH):
             """Internal use for xsl_handler. Reads stats_spec
             """Internal use for xsl_handler. Reads stats_spec
             specified as first arguments, and modify the xml object
             specified as first arguments, and modify the xml object
             specified as second argument. xsl_elem must be
             specified as second argument. xsl_elem must be
@@ -687,10 +693,15 @@ class StatsHttpd:
                                  "title" : item_spec["item_description"] \
                                  "title" : item_spec["item_description"] \
                                      if "item_description" in item_spec \
                                      if "item_description" in item_spec \
                                      else "" })
                                      else "" })
-                    a = xml.etree.ElementTree.Element(
-                        "a", attrib={ "href": urllib.parse.quote(path + "/" + item_spec["item_name"]) })
-                    a.text = item_spec[ "item_title" if "item_title" in item_spec else "item_name" ]
-                    td.append(a)
+                    # if the path length is equal to or shorter than
+                    # XML_URL_PATH + /Module/Item, add the anchor tag.
+                    if len(path.split('/')) <= len((XML_URL_PATH + '/Module/Item').split('/')):
+                        a = xml.etree.ElementTree.Element(
+                            "a", attrib={ "href": urllib.parse.quote(path + "/" + item_spec["item_name"]) })
+                        a.text = item_spec[ "item_title" if "item_title" in item_spec else "item_name" ]
+                        td.append(a)
+                    else:
+                        td.text = item_spec[ "item_title" if "item_title" in item_spec else "item_name" ]
                     tr.append(td)
                     tr.append(td)
                     td = xml.etree.ElementTree.Element("td")
                     td = xml.etree.ElementTree.Element("td")
                     stats_spec2xsl(item_spec, td, path)
                     stats_spec2xsl(item_spec, td, path)
@@ -711,9 +722,9 @@ class StatsHttpd:
             "xsl:template",
             "xsl:template",
             attrib={'match': "bind10:statistics"})
             attrib={'match': "bind10:statistics"})
         if module_name is not None and item_name is not None:
         if module_name is not None and item_name is not None:
-            stats_spec2xsl([ stats_spec ], xsd_root, './' + module_name)
+            stats_spec2xsl([ stats_spec ], xsd_root, XML_URL_PATH + '/' + module_name)
         elif module_name is not None:
         elif module_name is not None:
-            stats_spec2xsl(stats_spec, xsd_root, './' + module_name)
+            stats_spec2xsl(stats_spec, xsd_root, XML_URL_PATH + '/' + module_name)
         else:
         else:
             stats_spec2xsl(stats_spec, xsd_root)
             stats_spec2xsl(stats_spec, xsd_root)
         # The coding conversion is tricky. xml..tostring() of Python 3.2
         # The coding conversion is tricky. xml..tostring() of Python 3.2

Fichier diff supprimé car celui-ci est trop grand
+ 8 - 1
src/bin/stats/tests/b10-stats-httpd_test.py