示例#1
0
    def rewrite_url(self, url):
        scheme, host, path, params, query, fragment = urlparse(url)

        # If we can, skip the login page and submit credentials
        # directly. The query should contain a 'return' parameter
        # which, if our credentials are accepted, means we'll be
        # redirected back from whence we came. In other words, we'll
        # end up back at the bug page we first requested.
        login_page = '/login_page.php'
        if path.endswith(login_page):
            path = path[:-len(login_page)] + '/login.php'
            query = cgi.parse_qs(query, True)
            query['username'] = query['password'] = ['guest']
            if 'return' not in query:
                raise BugTrackerConnectError(
                    url, ("Mantis redirected us to the login page "
                          "but did not set a return path."))

            query = urllib.urlencode(query, True)
            url = urlunparse(
                (scheme, host, path, params, query, fragment))

        # Previous versions of the Mantis external bug tracker fetched
        # login_anon.php in addition to the login.php method above, but none
        # of the Mantis installations tested actually needed this. For
        # example, the ALSA bugtracker actually issues an error "Your account
        # may be disabled" when accessing this page. For now it's better to
        # *not* try this page because we may end up annoying admins with
        # spurious login attempts.

        return url
示例#2
0
def valid_builder_url(url):
    """validate a url for a builder.

    Builder urls must be http://host/ or http://host:port/
    (with or without the trailing slash) only.

    >>> valid_builder_url('http://example.com:54321/')
    True
    >>> valid_builder_url('http://example.com/foo')
    False
    >>> valid_builder_url('ftp://foo.com/')
    False

    """
    try:
        (scheme, netloc, path, params, query, fragment) = urlparse(url)
    except UnicodeEncodeError:
        return False
    if scheme != 'http':
        return False
    if params or query or fragment:
        return False
    if path and path != '/':
        return False
    return True
示例#3
0
    def rewrite_url(self, url):
        scheme, host, path, params, query, fragment = urlparse(url)

        # If we can, skip the login page and submit credentials
        # directly. The query should contain a 'return' parameter
        # which, if our credentials are accepted, means we'll be
        # redirected back from whence we came. In other words, we'll
        # end up back at the bug page we first requested.
        login_page = '/login_page.php'
        if path.endswith(login_page):
            path = path[:-len(login_page)] + '/login.php'
            query = cgi.parse_qs(query, True)
            query['username'] = query['password'] = ['guest']
            if 'return' not in query:
                raise BugTrackerConnectError(
                    url, ("Mantis redirected us to the login page "
                          "but did not set a return path."))

            query = urllib.urlencode(query, True)
            url = urlunparse((scheme, host, path, params, query, fragment))

        # Previous versions of the Mantis external bug tracker fetched
        # login_anon.php in addition to the login.php method above, but none
        # of the Mantis installations tested actually needed this. For
        # example, the ALSA bugtracker actually issues an error "Your account
        # may be disabled" when accessing this page. For now it's better to
        # *not* try this page because we may end up annoying admins with
        # spurious login attempts.

        return url
def validate_release_glob(value):
    """Validate that the URL is supported."""
    parts = urlparse(value)
    if (validate_url(value, ["http", "https", "ftp"]) and '*' in parts[2]):
        # The product release finder does support the url scheme and
        # can match more than one file to the url's path part.
        return True
    else:
        raise LaunchpadValidationError('Invalid release URL pattern.')
示例#5
0
def validate_release_glob(value):
    """Validate that the URL is supported."""
    parts = urlparse(value)
    if validate_url(value, ["http", "https", "ftp"]) and "*" in parts[2]:
        # The product release finder does support the url scheme and
        # can match more than one file to the url's path part.
        return True
    else:
        raise LaunchpadValidationError("Invalid release URL pattern.")
示例#6
0
def mantis_login_hook(response, *args, **kwargs):
    """requests hook to automatically log into Mantis anonymously if needed.

    The ALSA bug tracker is the only tested Mantis installation that
    actually needs this. For ALSA bugs, the dance is like so:

      1. We request bug 3301 ('jack sensing problem'):
           https://bugtrack.alsa-project.org/alsa-bug/view.php?id=3301

      2. Mantis redirects us to:
           .../alsa-bug/login_page.php?
                 return=%2Falsa-bug%2Fview.php%3Fid%3D3301

      3. We notice this, rewrite the query, and skip to login.php:
           .../alsa-bug/login.php?
                 return=%2Falsa-bug%2Fview.php%3Fid%3D3301&
                 username=guest&password=guest

      4. Mantis accepts our credentials then redirects us to the bug
         view page via a cookie test page (login_cookie_test.php)
    """
    if response.status_code not in (301, 302, 303, 307):
        return response
    if 'Location' not in response.headers:
        return response

    url = response.headers['Location']
    scheme, host, path, params, query, fragment = urlparse(url)

    # If we can, skip the login page and submit credentials directly.  The
    # query should contain a 'return' parameter which, if our credentials
    # are accepted, means we'll be redirected back whence we came.  In other
    # words, we'll end up back at the bug page we first requested.
    login_page = '/login_page.php'
    if path.endswith(login_page):
        path = path[:-len(login_page)] + '/login.php'
        query_list = [('username', 'guest'), ('password', 'guest')]
        query_list.extend(parse_qsl(query, True))
        if not any(name == 'return' for name, _ in query_list):
            raise BugTrackerConnectError(
                url, ("Mantis redirected us to the login page "
                      "but did not set a return path."))

        query = urlencode(query_list, True)
        url = urlunparse((scheme, host, path, params, query, fragment))

    # Previous versions of the Mantis external bug tracker fetched
    # login_anon.php in addition to the login.php method above, but none of
    # the Mantis installations tested actually needed this.  For example,
    # the ALSA bugtracker actually issues an error "Your account may be
    # disabled" when accessing this page.  For now it's better to *not* try
    # this page because we may end up annoying admins with spurious login
    # attempts.

    response.headers['Location'] = url
    return response
示例#7
0
    def credentials(self):
        """Return the authentication credentials needed to log in.

        If there are specific credentials for the current RT instance,
        these will be returned. Otherwise the RT default guest
        credentials (username and password of 'guest') will be returned.
        """
        credentials_config = config['checkwatches.credentials']
        hostname = urlparse(self.baseurl)[1]
        try:
            username = credentials_config['%s.username' % hostname]
            password = credentials_config['%s.password' % hostname]
            return {'user': username, 'pass': password}
        except KeyError:
            return {'user': '******', 'pass': '******'}
示例#8
0
    def credentials(self):
        """Return the authentication credentials needed to log in.

        If there are specific credentials for the current RT instance,
        these will be returned. Otherwise the RT default guest
        credentials (username and password of 'guest') will be returned.
        """
        credentials_config = config['checkwatches.credentials']
        hostname = urlparse(self.baseurl)[1]
        try:
            username = credentials_config['%s.username' % hostname]
            password = credentials_config['%s.password' % hostname]
            return {'user': username, 'pass': password}
        except KeyError:
            return {'user': '******', 'pass': '******'}
示例#9
0
    def credentials(self):
        credentials_config = config['checkwatches.credentials']

        # Extract the hostname from the current base url using urlparse.
        hostname = urlparse(self.baseurl)[1]
        try:
            # XXX gmb 2009-08-19 bug=391131
            #     We shouldn't be using this here. Ideally we'd be able
            #     to get the credentials from the BugTracker object.
            #     If you find yourself adding credentials for, for
            #     example, www.password.username.pirateninjah4x0rz.org,
            #     think about fixing the above bug instead.
            username = credentials_config['%s.username' % hostname]
            password = credentials_config['%s.password' % hostname]
            return {'login': username, 'password': password}
        except KeyError:
            raise BugTrackerAuthenticationError(self.baseurl,
                                                "No credentials found.")
示例#10
0
    def credentials(self):
        credentials_config = config['checkwatches.credentials']

        # Extract the hostname from the current base url using urlparse.
        hostname = urlparse(self.baseurl)[1]
        try:
            # XXX gmb 2009-08-19 bug=391131
            #     We shouldn't be using this here. Ideally we'd be able
            #     to get the credentials from the BugTracker object.
            #     If you find yourself adding credentials for, for
            #     example, www.password.username.pirateninjah4x0rz.org,
            #     think about fixing the above bug instead.
            username = credentials_config['%s.username' % hostname]
            password = credentials_config['%s.password' % hostname]
            return {'login': username, 'password': password}
        except KeyError:
            raise BugTrackerAuthenticationError(
                self.baseurl, "No credentials found.")
示例#11
0
def valid_absolute_url(name):
    """Validate an absolute URL.

    It looks like this function has been deprecated by
    lp.app.validators.validation.

    We define this as something that can be parsed into a URL that has both
    a protocol and a network address.

      >>> valid_absolute_url('sftp://chinstrap.ubuntu.com/foo/bar')
      True
      >>> valid_absolute_url('http://www.example.com')
      True
      >>> valid_absolute_url('whatever:/uxample.com/blah')
      False
      >>> valid_absolute_url('whatever://example.com/blah')
      True

    Unicode urls are ascii encoded, and a failure here means it isn't valid.

      >>> valid_absolute_url(u'http://www.example.com/test...')
      True
      >>> valid_absolute_url(u'http://www.example.com/test\u2026')
      False

    """
    try:
        (scheme, netloc, path, params, query, fragment) = urlparse(name)
    except UnicodeEncodeError:
        return False
    # note that URL checking is also done inside the database, in
    # trusted.sql, the valid_absolute_url function, and that code uses
    # stdlib urlparse, not our customized version.
    if not (scheme and netloc):
        return False
    return True