WebKit Bugzilla
Attachment 371052 Details for
Bug 198415
: [ews-app] Add authentication while fetching bugs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP
authentication.patch (text/plain), 5.95 KB, created by
Aakash Jain
on 2019-05-31 05:58:55 PDT
(
hide
)
Description:
WIP
Filename:
MIME Type:
Creator:
Aakash Jain
Created:
2019-05-31 05:58:55 PDT
Size:
5.95 KB
patch
obsolete
>Index: Tools/ChangeLog >=================================================================== >--- Tools/ChangeLog (revision 245960) >+++ Tools/ChangeLog (working copy) >@@ -1,3 +1,20 @@ >+2019-05-31 Aakash Jain <aakash_jain@apple.com> >+ >+ [ews-app] Add authentication while fetching bugs >+ https://bugs.webkit.org/show_bug.cgi?id=198415 >+ <rdar://problem/51298710> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * BuildSlaveSupport/ews-app/ews/common/bugzilla.py: >+ (Browser): Moved common code to Browser class. >+ (Bugzilla._fetch_attachment_json): Changed this to an instance method as this need to call authenticate() >+ and use other instance variables. >+ (BugzillaBeautifulSoup): >+ (BugzillaBeautifulSoup._load_query): Added authentication. >+ (BugzillaBeautifulSoup._get_browser): Moved to common class. >+ (BugzillaBeautifulSoup._set_browser): Ditto. >+ > 2019-05-31 Carlos Garcia Campos <cgarcia@igalia.com> > > [WPE] Build at-spi2-core without x11 support in jhbuild >Index: Tools/BuildSlaveSupport/ews-app/ews/common/bugzilla.py >=================================================================== >--- Tools/BuildSlaveSupport/ews-app/ews/common/bugzilla.py (revision 245960) >+++ Tools/BuildSlaveSupport/ews-app/ews/common/bugzilla.py (working copy) >@@ -25,6 +25,7 @@ import logging > import os > import re > import socket >+import time > > from datetime import datetime, timedelta > >@@ -36,10 +37,65 @@ import ews.config as config > _log = logging.getLogger(__name__) > > >-class Bugzilla(): >+class Browser(): >+ def __init__(self): >+ self._browser = None >+ self.authenticated = False >+ >+ def _get_browser(self): >+ if not self._browser: >+ socket.setdefaulttimeout(600) >+ from mechanize import Browser >+ self._browser = Browser() >+ self._browser.set_handle_robots(False) >+ return self._browser >+ >+ def _set_browser(self, value): >+ self._browser = value >+ >+ browser = property(_get_browser, _set_browser) >+ >+ def authenticate(self): >+ if self.authenticated: >+ return >+ username = os.getenv('BUGZILLA_USERNAME', None) >+ password = os.getenv('BUGZILLA_PASSWORD', None) >+ if not username or not password: >+ _log.warn("Username/password not configured in environment variables. Skipping authentication.") >+ return >+ >+ attempts = 0 >+ while not self.authenticated: >+ attempts += 1 >+ _log.info("Logging in as %s..." % username) >+ self.browser.open(config.BUG_SERVER_URL + "index.cgi?GoAheadAndLogIn=1") >+ _log.info("Opening {}".format(config.BUG_SERVER_URL + "index.cgi?GoAheadAndLogIn=1")) >+ self.browser.select_form(name="login") >+ self.browser['Bugzilla_login'] = username >+ self.browser['Bugzilla_password'] = password >+ self.browser.find_control("Bugzilla_restrictlogin").items[0].selected = False >+ response = self.browser.submit() >+ >+ match = re.search("<title>(.+?)</title>", response.read()) >+ # If the resulting page has a title, and it contains the word >+ # "invalid" assume it's the login failure page. >+ if match and re.search("Invalid", match.group(1), re.IGNORECASE): >+ errorMessage = "Bugzilla login failed: %s" % match.group(1) >+ # raise an exception only if this was the last attempt >+ if attempts < 5: >+ _log.error(errorMessage) >+ else: >+ raise Exception(errorMessage) >+ time.sleep(5) >+ else: >+ self.authenticated = True >+ self.username = username >+ >+ >+class Bugzilla(Browser): > @classmethod > def retrieve_attachment(cls, attachment_id): >- attachment_json = Bugzilla._fetch_attachment_json(attachment_id) >+ attachment_json = Bugzilla()._fetch_attachment_json(attachment_id) > if not attachment_json or not attachment_json.get('data'): > _log.warn('Unable to fetch attachment "{}".'.format(attachment_id)) > return None >@@ -54,8 +110,8 @@ class Bugzilla(): > with open(Bugzilla.file_path_for_patch(attachment_id), 'w') as attachment_file: > attachment_file.write(attachment_data) > >- @classmethod >- def _fetch_attachment_json(cls, attachment_id): >+ def _fetch_attachment_json(self, attachment_id): >+ self.authenticate() > if not Patch.is_valid_patch_id(attachment_id): > _log.warn('Invalid attachment id: "{}", skipping download.'.format(attachment_id)) > return None >@@ -83,23 +139,10 @@ class Bugzilla(): > return ids_needing_review > > >-class BugzillaBeautifulSoup(): >+class BugzillaBeautifulSoup(Browser): > # FIXME: Deprecate this class when https://bugzilla.mozilla.org/show_bug.cgi?id=1508531 is fixed. > def __init__(self): >- self._browser = None >- >- def _get_browser(self): >- if not self._browser: >- socket.setdefaulttimeout(600) >- from mechanize import Browser >- self._browser = Browser() >- self._browser.set_handle_robots(False) >- return self._browser >- >- def _set_browser(self, value): >- self._browser = value >- >- browser = property(_get_browser, _set_browser) >+ Browser.__init__(self) > > def fetch_attachment_ids_from_review_queue(self, since=None, only_security_bugs=False): > review_queue_url = 'request.cgi?action=queue&type=review&group=type' >@@ -108,7 +151,7 @@ class BugzillaBeautifulSoup(): > return self._parse_attachment_ids_request_query(self._load_query(review_queue_url), since) > > def _load_query(self, query): >- # TODO: check if we need to authenticate. >+ self.authenticate() > full_url = '{}{}'.format(config.BUG_SERVER_URL, query) > _log.info('Getting list of patches needing review, URL: {}'.format(full_url)) > return self.browser.open(full_url)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198415
:
371052
|
371288
|
371312