summaryrefslogtreecommitdiff
path: root/macaroonbakery/tests/test_client.py
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2019-05-09 09:50:35 +0100
committerColin Watson <cjwatson@debian.org>2019-05-09 09:52:58 +0100
commit1b2acc6aebeada2cf8d53b2e2184030ac6160f7e (patch)
tree1502b10f97b49252505a3f7734912d1e3c0216b6 /macaroonbakery/tests/test_client.py
parentbc4ad5ef594af4c89ab09c405e64c1483caa0696 (diff)
parent64f7b99b10a70e8341b4ddf5c9c726722f005ebe (diff)
Update upstream source from tag 'upstream/1.2.3'
Update to upstream version '1.2.3' with Debian dir 3636e342362ac7260cde53e4969a25f9f270aa8b
Diffstat (limited to 'macaroonbakery/tests/test_client.py')
-rw-r--r--macaroonbakery/tests/test_client.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/macaroonbakery/tests/test_client.py b/macaroonbakery/tests/test_client.py
index 9c57b78..b03bafa 100644
--- a/macaroonbakery/tests/test_client.py
+++ b/macaroonbakery/tests/test_client.py
@@ -72,6 +72,7 @@ class TestClient(TestCase):
@urlmatch(path='.*/discharge')
def discharge(url, request):
+ self.assertEqual(url.path, '/discharge')
qs = parse_qs(request.body)
content = {q: qs[q][0] for q in qs}
m = httpbakery.discharge(checkers.AuthContext(), content, d.key, d,
@@ -101,6 +102,53 @@ class TestClient(TestCase):
finally:
httpd.shutdown()
+ def test_single_service_third_party_with_path(self):
+ class _DischargerLocator(bakery.ThirdPartyLocator):
+ def __init__(self):
+ self.key = bakery.generate_key()
+
+ def third_party_info(self, loc):
+ if loc == 'http://1.2.3.4/some/path':
+ return bakery.ThirdPartyInfo(
+ public_key=self.key.public_key,
+ version=bakery.LATEST_VERSION,
+ )
+
+ d = _DischargerLocator()
+ b = new_bakery('loc', d, None)
+
+ @urlmatch(path='.*/discharge')
+ def discharge(url, request):
+ self.assertEqual(url.path, '/some/path/discharge')
+ qs = parse_qs(request.body)
+ content = {q: qs[q][0] for q in qs}
+ m = httpbakery.discharge(checkers.AuthContext(), content, d.key, d,
+ alwaysOK3rd)
+ return {
+ 'status_code': 200,
+ 'content': {
+ 'Macaroon': m.to_dict()
+ }
+ }
+
+ def handler(*args):
+ GetHandler(b, 'http://1.2.3.4/some/path', None, None, None, AGES, *args)
+ try:
+ httpd = HTTPServer(('', 0), handler)
+ server_url = 'http://' + httpd.server_address[0] + ':' + str(httpd.server_address[1])
+ thread = threading.Thread(target=httpd.serve_forever)
+ thread.start()
+ client = httpbakery.Client()
+ with HTTMock(discharge):
+ resp = requests.get(
+ url=server_url,
+ cookies=client.cookies,
+ auth=client.auth())
+ resp.raise_for_status()
+ self.assertEquals(resp.text, 'done')
+ finally:
+ httpd.shutdown()
+
def test_single_service_third_party_version_1_caveat(self):
class _DischargerLocator(bakery.ThirdPartyLocator):
def __init__(self):
@@ -486,6 +534,26 @@ class TestClient(TestCase):
self.assertEquals(macaroons[0][0].identifier, m1.identifier)
self.assertEquals(macaroons[1][0].identifier, m2.identifier)
+ def test_handle_error_cookie_path(self):
+ macaroon = bakery.Macaroon(
+ root_key=b'some key', id=b'xxx',
+ location='some location',
+ version=bakery.VERSION_0)
+ info = {
+ 'Macaroon': macaroon.to_dict(),
+ 'MacaroonPath': '.',
+ 'CookieNameSuffix': 'test'
+ }
+ error = httpbakery.Error(
+ code=407,
+ message='error',
+ version=bakery.LATEST_VERSION,
+ info=httpbakery.ErrorInfo.from_dict(info))
+ client = httpbakery.Client()
+ client.handle_error(error, 'http://example.com/some/path')
+ [cookie] = client.cookies
+ self.assertEqual(cookie.path, "/some/")
+
class GetHandler(BaseHTTPRequestHandler):
'''A mock HTTP server that serves a GET request'''