summaryrefslogtreecommitdiff
path: root/macaroonbakery
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2020-01-29 17:13:24 +0000
committerColin Watson <cjwatson@debian.org>2020-01-29 17:13:24 +0000
commit1f71066d3cd63e829ce094b1298873b0e34ae204 (patch)
treeb041c617f09ccd92b511df94e918dfe165faffca /macaroonbakery
parent64f7b99b10a70e8341b4ddf5c9c726722f005ebe (diff)
New upstream version 1.3.0
Diffstat (limited to 'macaroonbakery')
-rw-r--r--macaroonbakery/checkers/_auth_context.py7
-rw-r--r--macaroonbakery/tests/test_bakery.py13
-rw-r--r--macaroonbakery/tests/test_client.py14
3 files changed, 29 insertions, 5 deletions
diff --git a/macaroonbakery/checkers/_auth_context.py b/macaroonbakery/checkers/_auth_context.py
index dceb015..2ca5168 100644
--- a/macaroonbakery/checkers/_auth_context.py
+++ b/macaroonbakery/checkers/_auth_context.py
@@ -1,9 +1,12 @@
# Copyright 2017 Canonical Ltd.
# Licensed under the LGPLv3, see LICENCE file for details.
-import collections
+try:
+ from collections.abc import Mapping
+except ImportError:
+ from collections import Mapping
-class AuthContext(collections.Mapping):
+class AuthContext(Mapping):
''' Holds a set of keys and values relevant to authorization.
It is passed as an argument to authorization checkers, so that the checkers
diff --git a/macaroonbakery/tests/test_bakery.py b/macaroonbakery/tests/test_bakery.py
index a6c3e58..d242b2a 100644
--- a/macaroonbakery/tests/test_bakery.py
+++ b/macaroonbakery/tests/test_bakery.py
@@ -145,6 +145,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':
@@ -239,7 +249,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,
diff --git a/macaroonbakery/tests/test_client.py b/macaroonbakery/tests/test_client.py
index b03bafa..6437a54 100644
--- a/macaroonbakery/tests/test_client.py
+++ b/macaroonbakery/tests/test_client.py
@@ -4,7 +4,6 @@ import base64
import datetime
import json
import threading
-from unittest import TestCase
import macaroonbakery.bakery as bakery
import macaroonbakery.checkers as checkers
@@ -13,6 +12,10 @@ import pymacaroons
import requests
import macaroonbakery._utils as utils
+from fixtures import (
+ EnvironmentVariable,
+ TestWithFixtures,
+)
from httmock import HTTMock, urlmatch
from six.moves.urllib.parse import parse_qs
from six.moves.urllib.request import Request
@@ -26,7 +29,14 @@ AGES = datetime.datetime.utcnow() + datetime.timedelta(days=1)
TEST_OP = bakery.Op(entity='test', action='test')
-class TestClient(TestCase):
+class TestClient(TestWithFixtures):
+ 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.
+ self.useFixture(EnvironmentVariable('http_proxy'))
+ self.useFixture(EnvironmentVariable('HTTP_PROXY'))
+
def test_single_service_first_party(self):
b = new_bakery('loc', None, None)