def test_get_program_reports( self, YesWeHackRawApiClientMock: MagicMock, ) -> None: YesWeHackRawApiClientMock.return_value.login.return_value = True YesWeHackRawApiClientMock.return_value.get_reports.return_value = [ YesWeHackRawApiReport( ywh_api=None, lazy=True, id=123, ) ] YesWeHackRawApiClientMock.return_value.get_report.return_value = YesWeHackRawApiReport( ywh_api=None, lazy=True, id=123, title='A bug report', ) client = YesWeHackApiClient( configuration=YesWeHackConfiguration(), ) reports = client.get_program_reports( slug='my-program', ) self.assertEqual(1, len(reports)) self.assertEqual('A bug report', reports[0].title)
def test_put_report_tracking_status_json_not_dict_error( self, YesWeHackRawApiClientMock: MagicMock, YesWeHackRawApiReportMock: MagicMock, ) -> None: YesWeHackRawApiClientMock.return_value.login.return_value = True RequestsResponseMock = create_autospec(requests.models.Response) RequestsResponseMock.return_value.json.return_value = 'I am an API response' YesWeHackRawApiReportMock.return_value.put_tracking_status.return_value = RequestsResponseMock() client = YesWeHackApiClient( configuration=YesWeHackConfiguration(), ) raw_report = YesWeHackRawApiReportMock( ywh_api=None, lazy=True, id=123, ) report = Report( raw_report=raw_report, report_id='123', title='A bug report', local_id='YWH-123', bug_type=BugType( name='bug-type', link='http://bug.example.com/type', remediation_link='http://bug.example.com/type/remediation', ), scope='', cvss=Cvss( criticity='critical', score=9.0, vector='vector', ), end_point='/', vulnerable_part='post', part_name='param', payload_sample='abcde', technical_environment='', description_html='This is a bug', attachments=[], hunter=Author( username='******', ), logs=[], status='accepted', tracking_status='AFI', program=ReportProgram( title='My program', slug='my-program', ), ) with self.assertRaises(YesWeHackApiClientError): client.put_report_tracking_status( report=report, tracker_name='tracker', issue_id='foo', issue_url='https://tracker.example.com/issues/foo', status='T', comment='Tracker synchronized.', )
def test_get_program_reports_login_error( self, YesWeHackRawApiClientMock: MagicMock, ) -> None: YesWeHackRawApiClientMock.return_value.login.side_effect = YesWeHackRawAPiError( 'Cannot login.') client = YesWeHackApiClient(configuration=YesWeHackConfiguration(), ) with self.assertRaises(YesWeHackApiClientError): client.get_program_reports(slug='my-program', )
def _get_afi_reports( self, yeswehack_client: YesWeHackApiClient, program: Program, ) -> List[Report]: program_slug = cast(str, program.slug) filters = { 'filter[trackingStatus][0]': 'AFI', } synchronize_options = cast(SynchronizeOptions, program.synchronize_options) feedback_options = cast(FeedbackOptions, program.feedback_options) include_tracked = any(( synchronize_options.upload_private_comments, synchronize_options.upload_public_comments, synchronize_options.upload_details_updates, synchronize_options.upload_rewards, synchronize_options.upload_status_updates, feedback_options.download_tracker_comments, feedback_options.issue_closed_to_report_afv, ), ) if include_tracked: filters['filter[trackingStatus][1]'] = 'T' try: return yeswehack_client.get_program_reports( slug=program_slug, filters=filters, ) except YesWeHackApiClientError as e: raise SynchronizerError( f'Unable to get AFI/T reports for program {program_slug}', ) from e
def get_yeswehack_api_client( self, configuration: YesWeHackConfiguration, ) -> YesWeHackApiClient: """ Get the api client for the given configuration. Args: configuration: a configuration Raises: CoreException: if the client could not be created Returns: The client """ if configuration not in self._yeswehack_api_clients: try: client = YesWeHackApiClient(configuration=configuration, ) except YesWeHackApiClientError as e: raise CoreException( 'Unable to create YesWeHack API client') from e self._yeswehack_api_clients[configuration] = client return self._yeswehack_api_clients[configuration]