diff options
Diffstat (limited to 'macaroonbakery/tests/test_client.py')
-rw-r--r-- | macaroonbakery/tests/test_client.py | 68 |
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''' |