Exemplo n.º 1
0
 def test_validate_no_trackers(self) -> None:
     root = RootConfiguration(
         bugtrackers=Trackers(),
         yeswehack=YesWeHackConfigurations(my_ywh=YesWeHackConfiguration(
             api_url='http://example.com',
             login='******',
             password='******',
             oauth_args=OAuthSettings(
                 client_id='client-id',
                 client_secret='client-secret',
                 redirect_uri='http://example.com/oauth/redirect',
             ),
             apps_headers=Headers({
                 'X-YesWeHack-Apps': '123',
             }, ),
             verify=True,
             programs=Programs([
                 Program(
                     slug='1-pgm',
                     bugtrackers_name=Bugtrackers([
                         'my_gitlab',
                         'my_github',
                     ], ),
                 ),
             ], ),
         ), ),
     )
     with self.assertRaises(AttributesError):
         root.validate()
Exemplo n.º 2
0
    def test_constructor(self) -> None:
        ywh = YesWeHackConfiguration(
            api_url='http://example.com',
            pat='60d8fac0-c0ee-496a-a153-298164615021',
            verify=True,
            programs=Programs([
                Program(
                    slug='1-pgm',
                    bugtrackers_name=Bugtrackers([
                        'bt1',
                        'bt2',
                    ], ),
                ),
            ], ),
        )

        self.assertEqual('http://example.com', ywh.api_url)
        self.assertEqual('60d8fac0-c0ee-496a-a153-298164615021', ywh.pat)
        self.assertEqual(first=True, second=ywh.verify)
        self.assertEqual('1-pgm', cast(Programs, ywh.programs)[0].slug)
        self.assertEqual(
            [
                'bt1',
                'bt2',
            ],
            cast(Programs, ywh.programs)[0].bugtrackers_name,
        )
Exemplo n.º 3
0
 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.',
         )
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 def test_validate_no_trackers(self) -> None:
     root = RootConfiguration(
         bugtrackers=Trackers(),
         yeswehack=YesWeHackConfigurations(
             my_ywh=YesWeHackConfiguration(
                 api_url='http://example.com',
                 pat='e2d00087-a2fa-4fe2-ac1c-7abf1da2a036',
                 verify=True,
                 programs=Programs(
                     [
                         Program(
                             slug='1-pgm',
                             bugtrackers_name=Bugtrackers(
                                 [
                                     'my_gitlab',
                                     'my_github',
                                 ],
                             ),
                         ),
                     ],
                 ),
             ),
         ),
     )
     with self.assertRaises(AttributesError):
         root.validate()
Exemplo n.º 6
0
 def _build_configuration(
     self,
     tracker_key: str = 'tracker',
 ) -> RootConfiguration:
     return RootConfiguration(
         yeswehack=YesWeHackConfigurations(ywh_test=YesWeHackConfiguration(
             apps_headers=Headers(**{
                 'X-YesWeHack-Apps': 'qwerty',
             }, ),
             login='******',
             password='******',
             programs=Programs(items=[
                 Program(
                     slug='program1',
                     bugtrackers_name=Bugtrackers([
                         tracker_key,
                     ], ),
                 ),
             ], ),
         ), ),
         bugtrackers=Trackers(
             **{
                 tracker_key: MyTrackerTrackerConfiguration(),
             }, ),
     )
Exemplo n.º 7
0
 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', )
Exemplo n.º 8
0
    def test_constructor(self) -> None:
        ywh = YesWeHackConfiguration(
            api_url='http://example.com',
            apps_headers=Headers(foo='bar', ),
            login='******',
            password='******',
            oauth_args=OAuthSettings(
                client_id='client-id',
                client_secret='client-secret',
                redirect_uri='http://example.com/oauth/redirect',
            ),
            verify=True,
            programs=Programs([
                Program(
                    slug='1-pgm',
                    bugtrackers_name=Bugtrackers([
                        'bt1',
                        'bt2',
                    ], ),
                ),
            ], ),
        )

        self.assertEqual('http://example.com', ywh.api_url)
        self.assertEqual(
            dict(foo='bar', ),
            ywh.apps_headers,
        )
        self.assertEqual('*****@*****.**', ywh.login)
        self.assertEqual('my-password', ywh.password)
        self.assertEqual('client-id',
                         cast(OAuthSettings, ywh.oauth_args).client_id)
        self.assertEqual('client-secret',
                         cast(OAuthSettings, ywh.oauth_args).client_secret)
        self.assertEqual('http://example.com/oauth/redirect',
                         cast(OAuthSettings, ywh.oauth_args).redirect_uri)
        self.assertEqual(first=True, second=ywh.verify)
        self.assertEqual('1-pgm', cast(Programs, ywh.programs)[0].slug)
        self.assertEqual(
            [
                'bt1',
                'bt2',
            ],
            cast(Programs, ywh.programs)[0].bugtrackers_name,
        )
Exemplo n.º 9
0
 def test_validate(self) -> None:
     root = RootConfiguration(
         bugtrackers=Trackers(
             my_gitlab=GitLabConfiguration(
                 token='gl-token',
                 project='my-project',
             ),
             my_github=GitHubConfiguration(
                 token='gh-token',
                 project='project',
             ),
         ),
         yeswehack=YesWeHackConfigurations(my_ywh=YesWeHackConfiguration(
             api_url='http://example.com',
             login='******',
             password='******',
             oauth_args=OAuthSettings(
                 client_id='client-id',
                 client_secret='client-secret',
                 redirect_uri='http://example.com/oauth/redirect',
             ),
             apps_headers=Headers({
                 'X-YesWeHack-Apps': '123',
             }, ),
             verify=True,
             programs=Programs([
                 Program(
                     slug='1-pgm',
                     bugtrackers_name=Bugtrackers([
                         'my_gitlab',
                     ], ),
                 ),
                 Program(
                     slug='1-pgm',
                     bugtrackers_name=Bugtrackers([
                         'my_github',
                     ], ),
                 ),
             ], ),
         ), ),
     )
     root.validate()
Exemplo n.º 10
0
 def test_validate(self) -> None:
     root = RootConfiguration(
         bugtrackers=Trackers(
             my_gitlab=GitLabConfiguration(
                 token='gl-token',
                 project='my-project',
             ),
             my_github=GitHubConfiguration(
                 token='gh-token',
                 project='project',
             ),
         ),
         yeswehack=YesWeHackConfigurations(
             my_ywh=YesWeHackConfiguration(
                 api_url='http://example.com',
                 pat='e2d00087-a2fa-4fe2-ac1c-7abf1da2a036',
                 verify=True,
                 programs=Programs(
                     [
                         Program(
                             slug='1-pgm',
                             bugtrackers_name=Bugtrackers(
                                 [
                                     'my_gitlab',
                                 ],
                             ),
                         ),
                         Program(
                             slug='1-pgm',
                             bugtrackers_name=Bugtrackers(
                                 [
                                     'my_github',
                                 ],
                             ),
                         ),
                     ],
                 ),
             ),
         ),
     )
     root.validate()