From dfa331b7d67b5d89f2fdbe0406374810aaf33b57 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Tue, 20 Feb 2018 18:31:17 +0000 Subject: Import py-macaroon-bakery_1.1.2.orig.tar.gz --- docs/conf.py | 2 +- macaroonbakery/httpbakery/agent/_agent.py | 13 +++++++------ macaroonbakery/tests/test_agent.py | 19 +++++++++++++------ setup.py | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index ff5c82e..7985e17 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -63,7 +63,7 @@ copyright = u'2017, Juju UI Team' # the built documents. # # The short X.Y version and the full version. -version = release = '1.1.0' +version = release = '1.1.2' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/macaroonbakery/httpbakery/agent/_agent.py b/macaroonbakery/httpbakery/agent/_agent.py index b717261..618097c 100644 --- a/macaroonbakery/httpbakery/agent/_agent.py +++ b/macaroonbakery/httpbakery/agent/_agent.py @@ -109,14 +109,15 @@ class AgentInteractor(httpbakery.Interactor, httpbakery.LegacyInteractor): if not location.endswith('/'): location += '/' login_url = urljoin(location, p.login_url) - # TODO use client to make the request. - resp = requests.get(login_url, json={ - 'Username': agent.username, - 'PublicKey': str(self._auth_info.key), - }) + resp = requests.get( + login_url, params={ + 'username': agent.username, + 'public-key': str(self._auth_info.key.public_key)}, + auth=client.auth()) if resp.status_code != 200: raise httpbakery.InteractionError( - 'cannot acquire agent macaroon: {}'.format(resp.status_code) + 'cannot acquire agent macaroon: {} {}'.format( + resp.status_code, resp.text) ) m = resp.json().get('macaroon') if m is None: diff --git a/macaroonbakery/tests/test_agent.py b/macaroonbakery/tests/test_agent.py index 3b38337..d670485 100644 --- a/macaroonbakery/tests/test_agent.py +++ b/macaroonbakery/tests/test_agent.py @@ -14,10 +14,13 @@ import macaroonbakery.httpbakery.agent as agent import requests.cookies from httmock import HTTMock, response, urlmatch -from six.moves.urllib.parse import parse_qs +from six.moves.urllib.parse import parse_qs, urlparse log = logging.getLogger(__name__) +PRIVATE_KEY = 'CqoSgj06Zcgb4/S6RT4DpTjLAfKoznEY3JsShSjKJEU=' +PUBLIC_KEY = 'YAhRSsth3a36mRYqQGQaLiS4QJax0p356nd+B8x7UQE=' + class TestAgents(TestCase): def setUp(self): @@ -41,8 +44,8 @@ class TestAgents(TestCase): def test_load_auth_info(self): auth_info = agent.load_auth_info(self.agent_filename) - self.assertEqual(str(auth_info.key), 'CqoSgj06Zcgb4/S6RT4DpTjLAfKoznEY3JsShSjKJEU=') - self.assertEqual(str(auth_info.key.public_key), 'YAhRSsth3a36mRYqQGQaLiS4QJax0p356nd+B8x7UQE=') + self.assertEqual(str(auth_info.key), PRIVATE_KEY) + self.assertEqual(str(auth_info.key.public_key), PUBLIC_KEY) self.assertEqual(auth_info.agents, [ agent.Agent(url='https://1.example.com/', username='user-1'), agent.Agent(url='https://2.example.com/discharger', username='user-2'), @@ -139,12 +142,16 @@ class TestAgents(TestCase): @urlmatch(path='.*/login') def login(url, request): + qs = parse_qs(urlparse(request.url).query) + self.assertEqual(request.method, 'GET') + self.assertEqual( + qs, {'username': ['test-user'], 'public-key': [PUBLIC_KEY]}) b = bakery.Bakery(key=discharge_key) m = b.oven.macaroon( version=bakery.LATEST_VERSION, expiry=datetime.utcnow() + timedelta(days=1), caveats=[bakery.local_third_party_caveat( - auth_info.key.public_key, + PUBLIC_KEY, version=httpbakery.request_version(request.headers))], ops=[bakery.Op(entity='agent', action='login')]) return { @@ -164,7 +171,7 @@ class TestAgents(TestCase): 'http://0.1.2.3/here', cookies=client.cookies, auth=client.auth()) - self.assertEquals(resp.content, b'done') + self.assertEqual(resp.content, b'done') def test_agent_legacy(self): discharge_key = bakery.generate_key() @@ -346,7 +353,7 @@ class TestAgents(TestCase): cookies=client.cookies, auth=client.auth(), ) - self.assertEquals(resp.content, b'done') + self.assertEqual(resp.content, b'done') agent_file = ''' diff --git a/setup.py b/setup.py index eadbb41..265b5f8 100755 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ from setuptools import ( PROJECT_NAME = 'macaroonbakery' -VERSION = (1, 1, 0) +VERSION = (1, 1, 2) def get_version(): -- cgit v1.2.3 From 68863455145e5ca2ff2091c1e5c31b2a6bf05140 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 6 Nov 2017 10:27:10 +0000 Subject: Isolate client tests from any HTTP proxy Debian's Python packaging tools set http_proxy to a non-existent proxy to help flush out packages that try to talk to the network during build, but these tests could previously fail in more normal development environments too. Forwarded: https://github.com/go-macaroon-bakery/py-macaroon-bakery/pull/28 Last-Update: 2018-02-05 Patch-Name: isolate-from-proxy.patch --- macaroonbakery/tests/test_bakery.py | 6 ++++++ macaroonbakery/tests/test_client.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/macaroonbakery/tests/test_bakery.py b/macaroonbakery/tests/test_bakery.py index a6c3e58..72a6928 100644 --- a/macaroonbakery/tests/test_bakery.py +++ b/macaroonbakery/tests/test_bakery.py @@ -1,5 +1,6 @@ # Copyright 2017 Canonical Ltd. # Licensed under the LGPLv3, see LICENCE file for details. +import os from unittest import TestCase import macaroonbakery.httpbakery as httpbakery @@ -171,6 +172,11 @@ def wait_on_error(url, request): class TestBakery(TestCase): + def setUp(self): + super(TestBakery, self).setUp() + # http_proxy would cause requests to talk to the proxy, which is + # unlikely to know how to talk to the test server. + os.environ.pop('http_proxy', None) def assert_cookie_security(self, cookies, name, secure): for cookie in cookies: diff --git a/macaroonbakery/tests/test_client.py b/macaroonbakery/tests/test_client.py index ab20c3b..04e2f2b 100644 --- a/macaroonbakery/tests/test_client.py +++ b/macaroonbakery/tests/test_client.py @@ -3,6 +3,7 @@ import base64 import datetime import json +import os import threading from unittest import TestCase @@ -27,6 +28,12 @@ TEST_OP = bakery.Op(entity='test', action='test') class TestClient(TestCase): + def setUp(self): + super(TestClient, self).setUp() + # http_proxy would cause requests to talk to the proxy, which is + # unlikely to know how to talk to the test server. + os.environ.pop('http_proxy', None) + def test_single_service_first_party(self): b = new_bakery('loc', None, None) -- cgit v1.2.3 From c1850c8a10886894255100fae185c450e800564a Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 9 Feb 2018 21:54:21 +0000 Subject: Improve mock setup for 407-then-unknown test `test_407_then_unknown_interaction_methods` causes the client to fetch the possible methods supported by the discharger (because it's told that it only supports a non-window method). This is currently unmocked, which causes the client to actually contact `http://example.com/visit`. This fails in Launchpad builds because they run with a restrictive network setup that doesn't even expose DNS lookups for non-permitted hosts. There isn't really a good way to simulate this without setting up a similar stunt DNS server (though perhaps installing an `httmock.all_requests` fallback mock that raises an exception would be a good idea?), but this seems to be the only failure at the moment. Forwarded: https://github.com/go-macaroon-bakery/py-macaroon-bakery/pull/45 Last-Update: 2018-02-09 Patch-Name: improve-unknown-interaction-mock.patch --- macaroonbakery/tests/test_bakery.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/macaroonbakery/tests/test_bakery.py b/macaroonbakery/tests/test_bakery.py index 72a6928..1883987 100644 --- a/macaroonbakery/tests/test_bakery.py +++ b/macaroonbakery/tests/test_bakery.py @@ -146,6 +146,16 @@ def discharge_401(url, request): } +@urlmatch(path='.*/visit') +def visit_200(url, request): + return { + 'status_code': 200, + 'content': { + 'interactive': '/visit' + } + } + + @urlmatch(path='.*/wait') def wait_after_401(url, request): if request.url != 'http://example.com/wait': @@ -245,7 +255,8 @@ class TestBakery(TestCase): def kind(self): return 'unknown' client = httpbakery.Client(interaction_methods=[UnknownInteractor()]) - with HTTMock(first_407_then_200), HTTMock(discharge_401): + with HTTMock(first_407_then_200), HTTMock(discharge_401),\ + HTTMock(visit_200): with self.assertRaises(httpbakery.InteractionError) as exc: requests.get( ID_PATH, -- cgit v1.2.3