Example #1
0
def convert_dependency_url_to_local_path(url):
  """Convert a dependency URL to a corresponding local path."""
  # Bot-specific import.
  from bot.webserver import http_server

  logs.log('Process dependency: %s.' % url)
  file_match = FILE_URL_REGEX.search(url)
  http_match = HTTP_URL_REGEX.search(url)
  platform = environment.platform()

  local_path = None
  if file_match:
    file_path = file_match.group(1)
    logs.log('Detected file dependency: %s.' % file_path)
    if platform == 'WINDOWS':
      local_path = file_path
    else:
      local_path = '/' + file_path

      # Convert remote to local path for android.
      if platform == 'ANDROID':
        remote_testcases_directory = android.adb.DEVICE_TESTCASES_DIR
        local_testcases_directory = environment.get_value('FUZZ_INPUTS')
        local_path = local_path.replace(remote_testcases_directory,
                                        local_testcases_directory)

  elif http_match:
    relative_http_path = os.path.sep + http_match.group(2)
    logs.log('Detected http dependency: %s.' % relative_http_path)
    local_path = http_server.get_absolute_testcase_file(relative_http_path)
    if not local_path:
      # This needs to be a warning since in many cases, it is actually a
      # non-existent path. For others, we need to add the directory aliases in
      # file http_server.py.
      logs.log_warn(
          'Unable to find server resource %s, skipping.' % relative_http_path)

  if local_path:
    local_path = utils.normalize_path(local_path)

  return local_path
Example #2
0
 def test_redundant_path(self):
     """Tests redundant paths."""
     self.assertEqual('/test/test2/test3',
                      utils.normalize_path('/test/./test2/test3'))
     self.assertEqual('/test/test2/test3',
                      utils.normalize_path('/test//test2/test3'))