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
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 error.ClusterFuzzError(response.status_code, response.text) common.store_auth_header(response.headers[CLUSTERFUZZ_AUTH_HEADER]) return response
def test_init(self): """Test init.""" error.MinimizationNotFinishedError() error.SanitizerNotProvidedError() error.ClusterFuzzError(500, 'resp', 'identity') error.PermissionsTooPermissiveError('filename', 'perm') error.GomaNotInstalledError() error.JobTypeNotSupportedError('job', '1234') error.NotInstalledError('bin') error.GsutilNotInstalledError() error.BadJobTypeDefinitionError('job') error.UnreproducibleError(10, [Signature('type', ['a', 'b'], 'output')]) error.DirtyRepoError('source') error.CommandFailedError('cmd', 12, 'err') error.KillProcessFailedError('cmd', 123) error.UserRespondingNoError('question') error.InvalidTestcaseIdError('123456') error.UnauthorizedError('123456', 'identity') error.DifferentStacktraceError( 10, [Signature('type', ['a', 'b'], 'output')]) error.GdbNotSupportedOnAndroidError() error.BootFailed() error.NoAndroidDeviceIdError('ANDROID_SERIAL') error.GclientManagedEnabledException('/chromium/.gclient')
def test_404(self): """Test 404.""" self.mock.send_request.side_effect = error.ClusterFuzzError( 404, 'resp', 'identity') with self.assertRaises(error.InvalidTestcaseIdError) as cm: reproduce.get_testcase_and_identity('12345') self.assertIn('12345', cm.exception.message) self.mock.send_request.assert_called_once_with( reproduce.CLUSTERFUZZ_TESTCASE_INFO_URL, '{"testcaseId": "12345"}')
def test_401(self): """Test 401.""" self.mock.send_request.side_effect = error.ClusterFuzzError( 401, 'resp') with self.assertRaises(error.UnauthorizedError) as cm: reproduce.get_testcase_info('12345') self.assertIn('12345', cm.exception.message) self.mock.send_request.assert_called_once_with( reproduce.CLUSTERFUZZ_TESTCASE_INFO_URL, '{"testcaseId": "12345"}')
def test_error(self): """Test other error.""" self.mock.send_request.side_effect = error.ClusterFuzzError( 500, 'resp') with self.assertRaises(error.ClusterFuzzError) as cm: reproduce.get_testcase_info('12345') self.assertEqual(500, cm.exception.status_code) self.assertIn('resp', cm.exception.message) self.mock.send_request.assert_called_once_with( reproduce.CLUSTERFUZZ_TESTCASE_INFO_URL, '{"testcaseId": "12345"}')
def test_init(self): """Test init.""" error.MinimizationNotFinishedError() error.SanitizerNotProvidedError() error.ClusterFuzzError(500, 'resp') error.PermissionsTooPermissiveError('filename', 'perm') error.GomaNotInstalledError() error.JobTypeNotSupportedError('job') error.NotInstalledError('bin') error.GsutilNotInstalledError() error.BadJobTypeDefinitionError('job') error.UnreproducibleError(10, [Signature('type', ['a', 'b'], 'output')]) error.DirtyRepoError('source') error.CommandFailedError('cmd', 12, 'err') error.KillProcessFailedError('cmd', 123) error.UserRespondingNoError('question') error.InvalidTestcaseIdError('123456') error.UnauthorizedError('123456') error.DifferentStacktraceError( 10, [Signature('type', ['a', 'b'], 'output')])