Exemplo n.º 1
0
    def _report_exception(self, edata, eid, num, total):
        """
        Report one or more bugs to w3af's Github, submit data to server.
        """
        try:
            gh = GithubIssues(OAUTH_TOKEN)
            gh.login()
        except LoginFailed:
            msg = 'Failed to contact github.com. Please try again later.'
            om.out.console(msg)
        except OAuthTokenInvalid:
            om.out.console(OAUTH_AUTH_FAILED)
        else:
            traceback_str = edata.traceback_str
            desc = edata.get_summary()
            plugins = edata.enabled_plugins
            summary = str(edata.exception)

            ticket_id, ticket_url = gh.report_bug(summary,
                                                  desc,
                                                  tback=traceback_str,
                                                  plugins=plugins)

            if ticket_id is None:
                fmt = '    [%s/%s] Failed to report bug with id %s.'
                msg = fmt % (num, total, eid)
            else:
                fmt = '    [%s/%s] Bug with id %s reported at %s'
                msg = fmt % (num, total, eid, ticket_url)

            om.out.console(str(msg))
Exemplo n.º 2
0
    def _report_exception(self, edata, eid, num, total):
        """
        Report one or more bugs to w3af's Github, submit data to server.
        """
        gh = GithubIssues(OAUTH_TOKEN)
        if not gh.login():
            msg = 'Failed to contact github.com. Please try again later.'
            om.out.console(msg)
        else:
            traceback_str = edata.traceback_str
            desc = edata.get_summary()
            plugins = edata.enabled_plugins
            summary = str(edata.exception)

            ticket_id, ticket_url = gh.report_bug(summary, desc,
                                                  tback=traceback_str,
                                                  plugins=plugins)

            if ticket_id is None:
                msg = '    [%s/%s] Failed to report bug with id %s.' % (
                    num, total, eid)
            else:
                msg = '    [%s/%s] Bug with id %s reported at %s' % (
                    num, total, eid, ticket_url)

            om.out.console(str(msg))
Exemplo n.º 3
0
    def _login_github(self, retry=3):
        """
        Perform user login.

        :return: (user wants to exit,
                  github instance,
                  user's email)
        """
        invalid_login = False
        email = None

        while retry:
            # Decrement retry counter
            retry -= 1

            # Ask for user and password, or anonymous
            dlg_cred = dlg_ask_credentials(invalid_login)
            user_exit, method, params = dlg_cred.run()
            dlg_cred.destroy()

            # The user closed the dialog and wants to exit
            if user_exit:
                return user_exit, None, None

            if method == dlg_ask_credentials.METHOD_GH:
                user, password = params

            elif method == dlg_ask_credentials.METHOD_EMAIL:
                # The user chose METHOD_ANON or METHOD_EMAIL with both these
                # methods the framework actually logs in using our default
                # credentials
                user, password = (OAUTH_TOKEN, None)
                email = params[0]

            else:
                # The user chose METHOD_ANON or METHOD_EMAIL with both these
                # methods the framework actually logs in using our default
                # credentials
                user, password = (OAUTH_TOKEN, None)

            try:
                gh = GithubIssues(user, password)
                gh.login()
            except LoginFailed:
                # Let the user try again
                invalid_login = True
                continue
            except OAuthTokenInvalid:
                dlg = dlg_invalid_token(self)
                dlg.run()
                dlg.destroy()
                return True, None, None
            else:
                # Login success!
                break

        return False, gh, email
Exemplo n.º 4
0
    def _login_github(self, retry=3):
        """
        Perform user login.

        :return: (user wants to exit,
                  github instance,
                  user's email)
        """
        invalid_login = False
        email = None

        while retry:
            # Decrement retry counter
            retry -= 1

            # Ask for user and password, or anonymous
            dlg_cred = dlg_ask_credentials(invalid_login)
            user_exit, method, params = dlg_cred.run()
            dlg_cred.destroy()

            # The user closed the dialog and wants to exit
            if user_exit:
                return user_exit, None, None

            if method == dlg_ask_credentials.METHOD_GH:
                user, password = params

            elif method == dlg_ask_credentials.METHOD_EMAIL:
                # The user chose METHOD_ANON or METHOD_EMAIL with both these
                # methods the framework actually logs in using our default
                # credentials
                user, password = (OAUTH_TOKEN, None)
                email = params[0]

            else:
                # The user chose METHOD_ANON or METHOD_EMAIL with both these
                # methods the framework actually logs in using our default
                # credentials
                user, password = (OAUTH_TOKEN, None)

            try:
                gh = GithubIssues(user, password)
                gh.login()
            except LoginFailed:
                # Let the user try again
                invalid_login = True
                continue
            except OAuthTokenInvalid:
                dlg = dlg_invalid_token(self)
                dlg.run()
                dlg.destroy()
                return True, None, None
            else:
                # Login success!
                break

        return False, gh, email
Exemplo n.º 5
0
    def _login_github(self, retry=3):
        """
        Perform user login.
        """
        invalid_login = False
        email = None

        while retry:
            # Decrement retry counter
            retry -= 1
            # Ask for user and password, or anonymous
            dlg_cred = dlg_ask_credentials(invalid_login)
            user_exit, method, params = dlg_cred.run()
            dlg_cred.destroy()

            # The user closed the dialog and wants to exit
            if user_exit:
                return user_exit, None, None

            if method == dlg_ask_credentials.METHOD_GH:
                user, password = params

            elif method == dlg_ask_credentials.METHOD_EMAIL:
                # The user chose METHOD_ANON or METHOD_EMAIL with both these
                # methods the framework actually logs in using our default
                # credentials
                user, password = (OAUTH_TOKEN, None)
                email = params[0]

            else:
                # The user chose METHOD_ANON or METHOD_EMAIL with both these
                # methods the framework actually logs in using our default
                # credentials
                user, password = (OAUTH_TOKEN, None)

            gh = GithubIssues(user, password)
            login_result = gh.login()
            invalid_login = not login_result

            if login_result:
                break

        return False, gh, email
Exemplo n.º 6
0
    def _login_github(self, retry=3):
        """
        Perform user login.
        """
        invalid_login = False
        email = None

        while retry:
            # Decrement retry counter
            retry -= 1
            # Ask for user and password, or anonymous
            dlg_cred = dlg_ask_credentials(invalid_login)
            user_exit, method, params = dlg_cred.run()
            dlg_cred.destroy()

            # The user closed the dialog and wants to exit
            if user_exit:
                return user_exit, None, None

            if method == dlg_ask_credentials.METHOD_GH:
                user, password = params

            elif method == dlg_ask_credentials.METHOD_EMAIL:
                # The user chose METHOD_ANON or METHOD_EMAIL with both these
                # methods the framework actually logs in using our default
                # credentials
                user, password = (OAUTH_TOKEN, None)
                email = params[0]

            else:
                # The user chose METHOD_ANON or METHOD_EMAIL with both these
                # methods the framework actually logs in using our default
                # credentials
                user, password = (OAUTH_TOKEN, None)

            gh = GithubIssues(user, password)
            login_result = gh.login()
            invalid_login = not login_result

            if login_result:
                break

        return (False, gh, email)
Exemplo n.º 7
0
    def test_report(self):
        gh = GithubIssues(OAUTH_TOKEN)
        gh.login()

        summary = 'Unittest bug report'
        userdesc = 'Please remove this ticket'

        ticket_id, ticket_url = gh.report_bug(summary, userdesc)
        self.assertIsInstance(ticket_id, int)
        self.assertTrue(ticket_url.startswith(
                'https://github.com/andresriancho/w3af/issues/'))

        # Remove the ticket I've just created
        gh = Github(OAUTH_TOKEN)
        repo = gh.get_user('andresriancho').get_repo('w3af')
        issue = repo.get_issue(ticket_id)
        issue.edit(state='closed')
Exemplo n.º 8
0
    def test_report(self):
        gh = GithubIssues(OAUTH_TOKEN)
        gh.login()
        
        summary = 'Unittest bug report'
        userdesc = 'Please remove this ticket'

        ticket_id, ticket_url = gh.report_bug(summary, userdesc)
        self.assertIsInstance(ticket_id, int)
        self.assertTrue(ticket_url.startswith(
            'https://github.com/andresriancho/w3af/issues/'))
        
        # Remove the ticket I've just created
        gh = Github(OAUTH_TOKEN)
        repo = gh.get_user('andresriancho').get_repo('w3af')
        issue = repo.get_issue(ticket_id)
        issue.edit(state='closed')
Exemplo n.º 9
0
 def test_login_failed_user_pass(self):
     gh = GithubIssues('foobar', 'testbar')
     self.assertFalse(gh.login())
     
Exemplo n.º 10
0
 def test_login_success_token(self):
     gh = GithubIssues(OAUTH_TOKEN)
     self.assertTrue(gh.login())
Exemplo n.º 11
0
 def test_login_failed_token(self):
     gh = GithubIssues(OAUTH_TOKEN + 'foobar')
     self.assertFalse(gh.login())
Exemplo n.º 12
0
 def test_login_failed_user_pass(self):
     gh = GithubIssues('foobar', 'testbar')
     self.assertRaises(UserCredentialsInvalid, gh.login)
Exemplo n.º 13
0
 def test_login_success_token(self):
     gh = GithubIssues(OAUTH_TOKEN)
     self.assertTrue(gh.login())
Exemplo n.º 14
0
 def test_login_failed_token(self):
     gh = GithubIssues(OAUTH_TOKEN + 'foobar')
     self.assertRaises(OAuthTokenInvalid, gh.login)