Ejemplo n.º 1
0
def send_request(url, data):
    """Get a clusterfuzz url that requires authentication.

  Attempts to authenticate and is guaranteed to either
  return a valid, authorized response or throw an exception."""

    header = common.get_stored_auth_header() or get_verification_header()
    response = None
    for _ in range(2):
        response = common.post(url=url,
                               headers={
                                   'Authorization': header,
                                   'User-Agent': 'clusterfuzz-tools'
                               },
                               allow_redirects=True,
                               data=data)

        if response.status_code == 401:  # The access token expired.
            header = get_verification_header()
        else:  # Other errors or success
            break

    if response.status_code != 200:
        raise common.ClusterfuzzAuthError(response.text)

    common.store_auth_header(response.headers[CLUSTERFUZZ_AUTH_HEADER])
    return response
Ejemplo n.º 2
0
def send_request(url, data):
  """Get a clusterfuzz url that requires authentication.

  Attempts to authenticate and is guaranteed to either
  return a valid, authorized response or throw an exception."""
  header = common.get_stored_auth_header() or get_verification_header()
  response = None
  for _ in range(RETRY_COUNT):
    response = common.post(
        url=url,
        headers={
            'Authorization': header,
            'User-Agent': 'clusterfuzz-tools'
        },
        data=data,
        allow_redirects=True)

    # The access token expired.
    if response.status_code == 401:
      header = get_verification_header()
    # Internal server error (e.g. due to deployment)
    elif response.status_code == 500:
      time.sleep(common.RETRY_SLEEP_TIME)
      continue
    else:  # Other errors or success
      break

  if response.status_code != 200:
    raise error.ClusterFuzzError(
        response.status_code, response.text,
        str(response.headers.get(CLUSTERFUZZ_AUTH_IDENTITY, '')))

  common.store_auth_header(response.headers[CLUSTERFUZZ_AUTH_HEADER])
  return response
Ejemplo n.º 3
0
    def test_folder_present(self):
        """Tests storing when the folder has already been created."""

        self.fs.CreateFile(common.AUTH_HEADER_FILE)
        common.store_auth_header(self.auth_header)

        with open(common.AUTH_HEADER_FILE, 'r') as f:
            self.assertEqual(f.read(), self.auth_header)
        self.assert_file_permissions(common.AUTH_HEADER_FILE, 600)
Ejemplo n.º 4
0
    def test_folder_absent(self):
        """Tests storing when the folder has not been created prior."""

        self.assertFalse(os.path.exists(common.CLUSTERFUZZ_CACHE_DIR))
        common.store_auth_header(self.auth_header)

        self.assertTrue(os.path.exists(common.CLUSTERFUZZ_CACHE_DIR))
        with open(common.AUTH_HEADER_FILE, 'r') as f:
            self.assertEqual(f.read(), self.auth_header)
        self.assert_file_permissions(common.AUTH_HEADER_FILE, 600)
Ejemplo n.º 5
0
    def test_folder_absent(self):
        """Tests storing when the folder has not been created prior."""

        self.assertFalse(os.path.exists(self.clusterfuzz_dir))
        common.store_auth_header(self.auth_header)

        self.assertTrue(os.path.exists(self.clusterfuzz_dir))
        with open(self.auth_header_file, 'r') as f:
            self.assertEqual(f.read(), self.auth_header)
        self.assert_file_permissions(self.auth_header_file, 600)
Ejemplo n.º 6
0
def send_request(url):
    """Get a clusterfuzz url that requires authentication.

  Attempts to authenticate and is guaranteed to either
  return a valid, authorized response or throw an exception."""

    header = common.get_stored_auth_header()
    response = None
    for _ in range(2):
        if not header or (response and response.status == 401):
            header = get_verification_header()
        response = urlfetch.fetch(url=url, headers={'Authorization': header})
        if response.status == 200:
            break

    if response.status != 200:
        raise common.ClusterfuzzAuthError(response.body)
    common.store_auth_header(response.headers[CLUSTERFUZZ_AUTH_HEADER])

    return response