Esempio n. 1
0
 def _send(self, item_queue):
     """
     Serialize a list of test results and send them to remote server.
     """
     content = []
     for item in item_queue:
         content.append(item.serialize())
     data = json.dumps(content)
     headers = {}
     headers['content-type'] = 'application/json'
     url = 'http://%s:%s/api/tests/' % (self.args.server, self.args.port)
     try:
         response = requests.post(
             url,
             data=data,
             headers=headers,
             auth=(self.args.username, self.args.password),
         )
         if response.status_code != 201:
             logger.debug('Failed to send result (HTTP%s):',
                          response.status_code)
             if 'DOCTYPE' in response.text:
                 html_path = 'debug_%s.html' % rnd.regex('[a-z]{4}')
                 with open(html_path, 'w') as fp:
                     fp.write(response.text)
                 logger.debug('Html response saved to %s',
                              os.path.abspath(html_path))
             else:
                 logger.debug(response.text)
     except requests.ConnectionError as detail:
         logger.debug('Failed to send result to server: %s', detail)
Esempio n. 2
0
 def _send(self, item_queue):
     """
     Serialize a list of test results and send them to remote server.
     """
     content = []
     for item in item_queue:
         content.append(item.serialize())
     data = json.dumps(content)
     headers = {}
     headers["content-type"] = "application/json"
     url = "http://%s:%s/api/tests/" % (self.args.server, self.args.port)
     try:
         response = requests.post(url, data=data, headers=headers, auth=(self.args.username, self.args.password))
         if response.status_code != 201:
             logger.debug("Failed to send result (HTTP%s):", response.status_code)
             if "DOCTYPE" in response.text:
                 html_path = "debug_%s.html" % rnd.regex("[a-z]{4}")
                 with open(html_path, "w") as fp:
                     fp.write(response.text)
                 logger.debug("Html response saved to %s", os.path.abspath(html_path))
             else:
                 logger.debug(response.text)
     except requests.ConnectionError as detail:
         logger.debug("Failed to send result to server: %s", detail)
Esempio n. 3
0
 def test_rnd_regex(self):
     patts = [
         r"[a-fA-F0-9]{32}",
         r"[a-fA-F0-9]{8}\-([a-fA-F0-9]{4}\-){3}[a-fA-F0-9]{12}",
         r"[0-9]+",
         r"[a-zA-Z0-9\-_\.]+",
         r"[a-zA-Z0-9/\-_\. \(\)]+",
         r"""/[a-zA-Z0-9_\.\+\-\\&"'<>/%,]+""",
         r"-?[0-9]+",
         r"[a-zA-Z0-9_\.\-]+",
         r"[0-9]{1,2}",
         r"[a-zA-Z0-9_\.\+\-/]+",
         r"[a-zA-Z0-9_\-.]+",
         r"(0x)?[0-9a-fA-F]{1,4}",
         r"(0x)?[0-9a-fA-F]{1,2}",
         r"(0x)?[0-9a-fA-F]{1,16}",
         r"(0x)?[0-9a-fA-F]{1,3}",
         r"0x[a-fA-F0-9]{1,4}",
         r"[a-zA-Z0-9_\.\-\\:/]+",
         r"((0x)?[0-9a-fA-F]{1,3}\.){0,3}(0x)?[0-9a-fA-F]{1,3}",
         r"0x[fF][0-9a-eA-E]?",
         r"0x[a-fA-F0-9]",
         r"[a-zA-Z0-9_]+",
         r"[a-fA-F0-9][02468aAcCeE](:[a-fA-F0-9]{2}){5}",
         r"(0x)?[0-1]?[0-9a-fA-F]",
         r"[a-zA-Z0-9_\+\-]+",
         r"0x[0-9a-eA-E][0-9a-fA-F]?",
         r"(0x)?[0-7]",
         r"-1",
         r"""[a-zA-Z0-9_\.\+\-\\&"'<>/%]+""",
         r"[a-zA-Z0-9\-_]+",
         r"[a-zA-Z0-9_\.:]+",
         r"(0x)?[0-3]",
         r"0x[0-9a-fA-F]{1,4}",
         r"""/[a-zA-Z0-9_\.\+\-\\&"'<>/%]*""",
         r"[a-zA-Z0-9\.\-]+",
         r"[0-9]{1,2}.[0-9]{1,2}",
         r"0x[0-9a-fA-F]{1,2}",
         r"0x[0-9a-fA-F]{1,6}",
         r"(0x)?[0-9a-fA-F]{16}",
         r"(-|\+)?[0-9]+",
         r"(ab|cde|fga)",
         r"(a|b)",
         r"(a)|(b(c))",
         r"a|b",
         r"(([0-2]?[0-9]?[0-9]\.){3}[0-2]?[0-9]?[0-9])|(([0-9a-fA-F]+|:)+"
         "[0-9a-fA-F]+)|([a-zA-Z0-9_\.\+\-]*)",
         r"(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9]))\.)"
         "{3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9]))",
         r"([0-9]+(-[0-9]+)?|\^[0-9]+)(,([0-9]+(-[0-9]+)?|\^[0-9]+))*",
         r"a(b|c)",
         r"[^\n]+",
         r"[^,a]{12}",
         r"[^/]+",
         r"(vepa|bridge|private|passthrough)",
         r"(ioemu:)?(fd|hd|sd|vd|xvd|ubd)[a-zA-Z0-9_]+",
         r"[A-Za-z0-9_\.\+\-]+",
         r"[x20-x7E]{0,8}",
         r"(([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}"
         ":[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?"
         "[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:)"
         "{0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}"
         ":){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]"
         "{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}(((25[0-5])"
         "|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9]))\.){3}((25[0-5])"
         "|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9])))|(([0-9A-Fa-f]"
         "{1,4}:){0,5}:(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])"
         "|([0-9]))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])"
         "|([0-9])))|(::([0-9A-Fa-f]{1,4}:){0,5}(((25[0-5])|(2[0-4][0-9])"
         "|(1[0-9]{2})|([1-9][0-9])|([0-9]))\.){3}((25[0-5])|(2[0-4][0-9])"
         "|(1[0-9]{2})|([1-9][0-9])|([0-9])))|([0-9A-Fa-f]{1,4}::"
         "([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:)"
         "{0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:)",
         # r"-[^-]",
     ]
     for patt in patts:
         for i in range(100):
             res = rnd.regex(patt)
             m = re.match(patt + '$', res)
             self.assertIsNotNone(m)
Esempio n. 4
0
 def test_rnd_regex(self):
     patts = [
         r"[a-fA-F0-9]{32}",
         r"[a-fA-F0-9]{8}\-([a-fA-F0-9]{4}\-){3}[a-fA-F0-9]{12}",
         r"[0-9]+",
         r"[a-zA-Z0-9\-_\.]+",
         r"[a-zA-Z0-9/\-_\. \(\)]+",
         r"""/[a-zA-Z0-9_\.\+\-\\&"'<>/%,]+""",
         r"-?[0-9]+",
         r"[a-zA-Z0-9_\.\-]+",
         r"[0-9]{1,2}",
         r"[a-zA-Z0-9_\.\+\-/]+",
         r"[a-zA-Z0-9_\-.]+",
         r"(0x)?[0-9a-fA-F]{1,4}",
         r"(0x)?[0-9a-fA-F]{1,2}",
         r"(0x)?[0-9a-fA-F]{1,16}",
         r"(0x)?[0-9a-fA-F]{1,3}",
         r"0x[a-fA-F0-9]{1,4}",
         r"[a-zA-Z0-9_\.\-\\:/]+",
         r"((0x)?[0-9a-fA-F]{1,3}\.){0,3}(0x)?[0-9a-fA-F]{1,3}",
         r"0x[fF][0-9a-eA-E]?",
         r"0x[a-fA-F0-9]",
         r"[a-zA-Z0-9_]+",
         r"[a-fA-F0-9][02468aAcCeE](:[a-fA-F0-9]{2}){5}",
         r"(0x)?[0-1]?[0-9a-fA-F]",
         r"[a-zA-Z0-9_\+\-]+",
         r"0x[0-9a-eA-E][0-9a-fA-F]?",
         r"(0x)?[0-7]",
         r"-1",
         r"""[a-zA-Z0-9_\.\+\-\\&"'<>/%]+""",
         r"[a-zA-Z0-9\-_]+",
         r"[a-zA-Z0-9_\.:]+",
         r"(0x)?[0-3]",
         r"0x[0-9a-fA-F]{1,4}",
         r"""/[a-zA-Z0-9_\.\+\-\\&"'<>/%]*""",
         r"[a-zA-Z0-9\.\-]+",
         r"[0-9]{1,2}.[0-9]{1,2}",
         r"0x[0-9a-fA-F]{1,2}",
         r"0x[0-9a-fA-F]{1,6}",
         r"(0x)?[0-9a-fA-F]{16}",
         r"(-|\+)?[0-9]+",
         r"(ab|cde|fga)",
         r"(a|b)",
         r"(a)|(b(c))",
         r"a|b",
         r"(([0-2]?[0-9]?[0-9]\.){3}[0-2]?[0-9]?[0-9])|(([0-9a-fA-F]+|:)+" "[0-9a-fA-F]+)|([a-zA-Z0-9_\.\+\-]*)",
         r"(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9]))\.)"
         "{3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9]))",
         r"([0-9]+(-[0-9]+)?|\^[0-9]+)(,([0-9]+(-[0-9]+)?|\^[0-9]+))*",
         r"a(b|c)",
         r"[^\n]+",
         r"[^,a]{12}",
         r"[^/]+",
         r"(vepa|bridge|private|passthrough)",
         r"(ioemu:)?(fd|hd|sd|vd|xvd|ubd)[a-zA-Z0-9_]+",
         r"[A-Za-z0-9_\.\+\-]+",
         r"[x20-x7E]{0,8}",
         r"(([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}"
         ":[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?"
         "[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:)"
         "{0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}"
         ":){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]"
         "{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}(((25[0-5])"
         "|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9]))\.){3}((25[0-5])"
         "|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9])))|(([0-9A-Fa-f]"
         "{1,4}:){0,5}:(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])"
         "|([0-9]))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])"
         "|([0-9])))|(::([0-9A-Fa-f]{1,4}:){0,5}(((25[0-5])|(2[0-4][0-9])"
         "|(1[0-9]{2})|([1-9][0-9])|([0-9]))\.){3}((25[0-5])|(2[0-4][0-9])"
         "|(1[0-9]{2})|([1-9][0-9])|([0-9])))|([0-9A-Fa-f]{1,4}::"
         "([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:)"
         "{0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:)",
         # r"-[^-]",
     ]
     for patt in patts:
         for i in range(100):
             res = rnd.regex(patt)
             m = re.match(patt + "$", res)
             self.assertIsNotNone(m)