From 2b249f69fc7344c0579737d76377ccf5abc1043d 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 Gbp-Pq: 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 b03bafa..2ae08d3 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 d31d090af102f64e0dd8266b3d6f28bfb19535c8 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 Gbp-Pq: 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 From e183a35a2f950bc1346e4b9d58cc8960edcb93fe 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 Gbp-Pq: 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 b03bafa..2ae08d3 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 507f3eb3007c869baa48888890e3049fb9986b17 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 Gbp-Pq: 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 From a583a4025a5ddc09a2e56f89f371c6b1d8dc768e 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 Gbp-Pq: 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 b03bafa..2ae08d3 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 e1a7ba951eb867e0336c8cd090537d11ea5954ed 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 Gbp-Pq: 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 From 590e72a8af577c238da51d234a07cc199eff941a Mon Sep 17 00:00:00 2001 From: Francesco Banconi Date: Mon, 13 May 2019 11:27:48 +0200 Subject: Avoid using deprecated platform.dist() in setup.py Bug: https://github.com/go-macaroon-bakery/py-macaroon-bakery/issues/74 Origin: upstream, https://github.com/go-macaroon-bakery/py-macaroon-bakery/commit/3721180c4a3765e8807392fca2b7e7c2d7ffae45 Last-Update: 2019-12-26 Gbp-Pq: Name avoid-deprecated-platform-dist.patch --- setup.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index f098e76..83aec8c 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,6 @@ # Copyright 2017 Canonical Ltd. # Licensed under the LGPLv3, see LICENCE file for details. import sys -import platform from setuptools import ( find_packages, @@ -39,16 +38,14 @@ test_requirements = [ 'httmock==1.2.5', ] -distribution = platform.dist() -if len(distribution) == 3 and distribution[2] == 'trusty': +if sys.version_info < (2, 7, 9): # Injected into urllib3 to fix insecure Python 2. requirements.extend([ 'cryptography==1.3.2', - 'pyOpenSSL==16.0.0', - 'pyasn1==0.1.9', 'ndg_httpsclient==0.3.3', + 'pyasn1==0.1.9', + 'pyOpenSSL==16.0.0', ]) - if sys.version_info.major == 2: requirements.append('ipaddress') -- cgit v1.2.3