diff options
-rw-r--r-- | .travis.yml | 14 | ||||
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | debian/changelog | 6 | ||||
-rw-r--r-- | debian/patches/improve-unknown-interaction-mock.patch | 1 | ||||
-rw-r--r-- | debian/patches/isolate-from-proxy.patch | 3 | ||||
-rwxr-xr-x | docs/conf.py | 2 | ||||
-rw-r--r-- | macaroonbakery/_utils/__init__.py | 20 | ||||
-rw-r--r-- | macaroonbakery/httpbakery/_client.py | 6 | ||||
-rw-r--r-- | macaroonbakery/tests/test_client.py | 35 | ||||
-rw-r--r-- | macaroonbakery/tests/test_utils.py | 22 | ||||
-rwxr-xr-x | setup.py | 7 |
11 files changed, 108 insertions, 16 deletions
diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4bc8e34 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: python +python: + - "2.7" + - "3.5" +stages: + - lint + - test +install: pip install tox tox-travis +jobs: + include: + - stage: lint + script: tox -e lint + python: "3.5" +script: tox @@ -40,13 +40,13 @@ check: setup lint clean: $(PYTHON) setup.py clean # Remove the development environments. - rm -rfv $(DEVENV) .tox/ + rm -rf $(DEVENV) .tox/ # Remove distribution artifacts. - rm -rfv *.egg build/ dist/ macaroonbakery.egg-info MANIFEST + rm -rf *.egg build/ dist/ macaroonbakery.egg-info MANIFEST # Remove tests artifacts. - rm -fv .coverage + rm -f .coverage # Remove the canary file. - rm -fv $(SYSDEPS_INSTALLED) + rm -f $(SYSDEPS_INSTALLED) # Remove Python compiled bytecode. find . -name '*.pyc' -delete find . -name '__pycache__' -type d -delete diff --git a/debian/changelog b/debian/changelog index 3e33b2c..570d5e8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,11 @@ -py-macaroon-bakery (1.1.3-2) UNRELEASED; urgency=medium +py-macaroon-bakery (1.1.4-1) UNRELEASED; urgency=medium + [ Ondřej Nový ] * Convert git repository from git-dpm to gbp layout + [ Colin Watson ] + * New upstream release. + -- Ondřej Nový <onovy@debian.org> Wed, 08 Aug 2018 09:17:28 +0200 py-macaroon-bakery (1.1.3-1) unstable; urgency=medium diff --git a/debian/patches/improve-unknown-interaction-mock.patch b/debian/patches/improve-unknown-interaction-mock.patch index 746662a..b09b3a2 100644 --- a/debian/patches/improve-unknown-interaction-mock.patch +++ b/debian/patches/improve-unknown-interaction-mock.patch @@ -1,4 +1,3 @@ -From d918563db4de954c3df719d06a31bdd3aec3a8fc Mon Sep 17 00:00:00 2001 From: Colin Watson <cjwatson@debian.org> Date: Fri, 9 Feb 2018 21:54:21 +0000 Subject: Improve mock setup for 407-then-unknown test diff --git a/debian/patches/isolate-from-proxy.patch b/debian/patches/isolate-from-proxy.patch index 3a4c18c..40803e2 100644 --- a/debian/patches/isolate-from-proxy.patch +++ b/debian/patches/isolate-from-proxy.patch @@ -1,4 +1,3 @@ -From 920e53a9172a6a76d6f1abcef56be2edf4301596 Mon Sep 17 00:00:00 2001 From: Colin Watson <cjwatson@debian.org> Date: Mon, 6 Nov 2017 10:27:10 +0000 Subject: Isolate client tests from any HTTP proxy @@ -41,7 +40,7 @@ index a6c3e58..72a6928 100644 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 bfc7807..baafeed 100644 +index 4061a8a..aa1f268 100644 --- a/macaroonbakery/tests/test_client.py +++ b/macaroonbakery/tests/test_client.py @@ -3,6 +3,7 @@ diff --git a/docs/conf.py b/docs/conf.py index 3e35fbd..3f1adbe 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.3' +version = release = '1.1.4' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/macaroonbakery/_utils/__init__.py b/macaroonbakery/_utils/__init__.py index f2779e0..977cdbe 100644 --- a/macaroonbakery/_utils/__init__.py +++ b/macaroonbakery/_utils/__init__.py @@ -2,6 +2,7 @@ # Licensed under the LGPLv3, see LICENCE file for details. import base64 import binascii +import ipaddress import json import webbrowser from datetime import datetime @@ -134,7 +135,9 @@ def cookie( it must be a naive timestamp in UTC. ''' u = urlparse(url) - domain = u.hostname or u.netloc + domain = u.hostname + if '.' not in domain and not _is_ip_addr(domain): + domain += ".local" port = str(u.port) if u.port is not None else None secure = u.scheme == 'https' if expires is not None: @@ -160,3 +163,18 @@ def cookie( rest=None, rfc2109=False, ) + + +def _is_ip_addr(h): + if six.PY2: + # the python2.7 backport of ipaddr needs a bytestring passed in + try: + h = h.decode('ascii') + except UnicodeDecodeError: + # If there are non-ascii chars it's not an address anyway + return False + try: + ipaddress.ip_address(h) + except ValueError: + return False + return True diff --git a/macaroonbakery/httpbakery/_client.py b/macaroonbakery/httpbakery/_client.py index 4fe0ab1..2510f73 100644 --- a/macaroonbakery/httpbakery/_client.py +++ b/macaroonbakery/httpbakery/_client.py @@ -290,12 +290,8 @@ def _prepare_discharge_hook(req, client): Retry.count) ) client.handle_error(error, req.url) - # Replace the private _cookies from req as it is a copy of - # the original cookie jar passed into the requests method and we need - # to set the cookie for this request. - req._cookies = client.cookies req.headers.pop('Cookie', None) - req.prepare_cookies(req._cookies) + req.prepare_cookies(client.cookies) req.headers[BAKERY_PROTOCOL_HEADER] = \ str(bakery.LATEST_VERSION) with requests.Session() as s: diff --git a/macaroonbakery/tests/test_client.py b/macaroonbakery/tests/test_client.py index bfc7807..4061a8a 100644 --- a/macaroonbakery/tests/test_client.py +++ b/macaroonbakery/tests/test_client.py @@ -55,6 +55,41 @@ class TestClient(TestCase): finally: httpd.shutdown() + def test_cookie_domain_host_not_fqdn(self): + # See + # https://github.com/go-macaroon-bakery/py-macaroon-bakery/issues/53 + + b = new_bakery('loc', None, None) + + def handler(*args): + GetHandler(b, None, None, None, None, AGES, *args) + try: + httpd = HTTPServer(('', 0), handler) + thread = threading.Thread(target=httpd.serve_forever) + thread.start() + srv_macaroon = b.oven.macaroon( + version=bakery.LATEST_VERSION, expiry=AGES, + caveats=None, ops=[TEST_OP]) + self.assertEquals(srv_macaroon.macaroon.location, 'loc') + client = httpbakery.Client() + # Note: by using "localhost" instead of the presumably numeric address held + # in httpd.server_address, we're triggering the no-FQDN logic in the cookie + # code. + resp = requests.get( + url='http://localhost:' + str(httpd.server_address[1]), + cookies=client.cookies, auth=client.auth()) + resp.raise_for_status() + self.assertEquals(resp.text, 'done') + except httpbakery.BakeryException: + pass # interacion required exception is expected + finally: + httpd.shutdown() + + # the cookie has the .local domain appended + [cookie] = client.cookies + self.assertEqual(cookie.name, 'macaroon-test') + self.assertEqual(cookie.domain, 'localhost.local') + def test_single_party_with_header(self): b = new_bakery('loc', None, None) diff --git a/macaroonbakery/tests/test_utils.py b/macaroonbakery/tests/test_utils.py index 65edeb4..4ed3e81 100644 --- a/macaroonbakery/tests/test_utils.py +++ b/macaroonbakery/tests/test_utils.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + # Copyright 2017 Canonical Ltd. # Licensed under the LGPLv3, see LICENCE file for details. @@ -26,6 +28,26 @@ class CookieTest(TestCase): ValueError, cookie, 'http://example.com', 'test', 'value', expires=timestamp) + def test_cookie_with_hostname_not_fqdn(self): + c = cookie('http://myhost', 'test', 'value') + self.assertEqual(c.domain, 'myhost.local') + + def test_cookie_with_hostname_ipv4(self): + c = cookie('http://1.2.3.4', 'test', 'value') + self.assertEqual(c.domain, '1.2.3.4') + + def test_cookie_with_hostname_ipv6(self): + c = cookie('http://[dead::beef]', 'test', 'value') + self.assertEqual(c.domain, 'dead::beef') + + def test_cookie_with_hostname_like_ipv4(self): + c = cookie('http://1.2.3.4.com', 'test', 'value') + self.assertEqual(c.domain, '1.2.3.4.com') + + def test_cookie_with_hostname_not_ascii(self): + c = cookie('http://κουλουράκι', 'test', 'value') + self.assertEqual(c.domain, 'κουλουράκι.local') + class TestB64Decode(TestCase): def test_decode(self): @@ -2,6 +2,7 @@ # Copyright 2017 Canonical Ltd. # Licensed under the LGPLv3, see LICENCE file for details. +import sys import platform from setuptools import ( @@ -12,7 +13,8 @@ from setuptools import ( PROJECT_NAME = 'macaroonbakery' -VERSION = (1, 1, 3) +# version 1.1.4 +VERSION = (1, 1, 4) def get_version(): @@ -47,6 +49,9 @@ if len(distribution) == 3 and distribution[2] == 'trusty': 'ndg_httpsclient==0.3.3', ]) +if sys.version_info.major == 2: + requirements.append('ipaddress') + setup( name=PROJECT_NAME, |