Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add urllib3 AuthorizedHttp #19

Merged
merged 4 commits into from
Oct 13, 2016
Merged

Add urllib3 AuthorizedHttp #19

merged 4 commits into from
Oct 13, 2016

Conversation

theacodes
Copy link
Contributor

Implementation of the plan detailed over at #15.

@theacodes theacodes added this to the 1.0.0 milestone Oct 12, 2016
from six.moves import http_client

DEFAULT_REFRESH_STATUS_CODES = (http_client.UNAUTHORIZED,)
DEFAULT_MAX_REFRESH_ATTEMPTS = 2

This comment was marked as spam.

This comment was marked as spam.

try:
import certifi
except ImportError: # pragma: NO COVER
certifi = None

This comment was marked as spam.

This comment was marked as spam.

http = urllib3.PoolManager()
request = google.auth.transport.urllib3.Request(http)

credentials.refresh(request)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.



def _make_default_http():
if certifi:

This comment was marked as spam.

This comment was marked as spam.

if certifi:
return urllib3.PoolManager(
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where())

This comment was marked as spam.

This comment was marked as spam.

self.headers = headers or {}

def urlopen(self, method, url, body=None, headers=None, **kwargs):
self.requests.append((method, url, body, headers))

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

return self.responses.pop(0)


class MockResponse(object):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

mock.sentinel.credentials)

assert authed_http.credentials == mock.sentinel.credentials
assert authed_http.http is not None

This comment was marked as spam.

This comment was marked as spam.

assert authed_http.http is not None

def test_urlopen_no_refresh(self):
mock_credentials = mock.Mock(wraps=MockCredentials())

This comment was marked as spam.

This comment was marked as spam.

def test_urlopen_refresh(self):
mock_credentials = mock.Mock(wraps=MockCredentials())
mock_final_response = MockResponse(status=http_client.OK)
# First request will 403, second request will succeed.

This comment was marked as spam.

This comment was marked as spam.

@dhermes
Copy link
Contributor

dhermes commented Oct 13, 2016

@jonparrott We have anything left?

@theacodes
Copy link
Contributor Author

Don't think so.

On Wed, Oct 12, 2016, 10:46 PM Danny Hermes notifications@github.com
wrote:

@jonparrott https://github.com/jonparrott We have anything left?


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
#19 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAPUc8mIfZ4OLMoPGnPioce6t7ufaTF7ks5qzcWsgaJpZM4KVNbu
.

@dhermes
Copy link
Contributor

dhermes commented Oct 13, 2016

👍 LGTM then

@theacodes theacodes merged commit 27f6e1e into master Oct 13, 2016
@theacodes theacodes deleted the urllib3-authorized-http branch October 13, 2016 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants