Beispiel #1
0
 def _handle_auth(self, auth_type, header_key, url, location):
     # this method needs to run in the eventloop because it uses the
     # httpauth module.  At this point the transfer is removed from
     # curl_manager's, so we don't have to worry about accessing our
     # attributes.
     self.current_auth_type = auth_type
     self.auth_attempts[auth_type] += 1
     if auth_type == 'http' and self.http_auth is not None:
         httpauth.remove(self.http_auth)
     elif auth_type == 'proxy' and self.proxy_auth is not None:
         httpauth.remove(self.proxy_auth)
     if self.auth_attempts[auth_type] > MAX_AUTH_ATTEMPTS:
         self.handle_auth_failure()
         return
     try:
         auth_header = self.headers[header_key]
     except KeyError:
         self.handle_auth_failure()
         return
     if auth_type == 'http':
         # now that we have the www-authenticate header, try again to find
         # an existing password
         existing_auth = httpauth.find_http_auth(url, auth_header)
         if existing_auth is not None:
             self.http_auth = existing_auth
             self._send_new_request()
             return
     try:
         httpauth.ask_for_http_auth(self._ask_for_http_auth_callback, url,
                                    auth_header, location)
     except (AssertionError, ValueError), e:
         logging.warn("Error when parsing auth header: %s", e)
         self.handle_auth_failure()
Beispiel #2
0
 def test_remove(self):
     url = 'http://example.com/foo.html'
     header = 'Basic realm="Protected Space"'
     auth = self.ask_for_http_auth(url, header)
     self.assertEquals(httpauth.find_http_auth(url, header), auth)
     httpauth.remove(auth)
     self.assertEquals(httpauth.find_http_auth(url, header), None)
Beispiel #3
0
 def _handle_auth(self, auth_type, header_key, url, location):
     # this method needs to run in the eventloop because it uses the
     # httpauth module.  At this point the transfer is removed from
     # curl_manager's, so we don't have to worry about accessing our
     # attributes.
     self.current_auth_type = auth_type
     self.auth_attempts[auth_type] += 1
     if auth_type == 'http' and self.http_auth is not None:
         httpauth.remove(self.http_auth)
     elif auth_type == 'proxy' and self.proxy_auth is not None:
         httpauth.remove(self.proxy_auth)
     if self.auth_attempts[auth_type] > MAX_AUTH_ATTEMPTS:
         self.handle_auth_failure()
         return
     try:
         auth_header = self.headers[header_key]
     except KeyError:
         self.handle_auth_failure()
         return
     if auth_type == 'http':
         # now that we have the www-authenticate header, try again to find
         # an existing password
         existing_auth = httpauth.find_http_auth(url, auth_header)
         if existing_auth is not None:
             self.http_auth = existing_auth
             self._send_new_request()
             return
     try:
         httpauth.ask_for_http_auth(self._ask_for_http_auth_callback,
                 url, auth_header, location)
     except (AssertionError, ValueError), e:
         logging.warn("Error when parsing auth header: %s", e)
         self.handle_auth_failure()
Beispiel #4
0
 def test_remove_from_main_process(self):
     # This is test_remove using the daemon's httpauth.py, but we also test
     # that it's removed from the main process
     import miro.httpauth
     url = 'http://example.com/foo.html'
     header = 'Basic realm="Protected Space"'
     auth = self.ask_for_http_auth(url, header)
     self.assertEquals(httpauth.find_http_auth(url, header), auth)
     self.assertEquals(miro.httpauth.find_http_auth(url, header), auth)
     httpauth.remove(auth)
     # wait for RemoveHTTPAuthCommand to be run
     self.runPendingIdles()
     self.assertEquals(httpauth.find_http_auth(url, header), None)
     self.assertEquals(miro.httpauth.find_http_auth(url, header), None)