summaryrefslogtreecommitdiff
path: root/macaroonbakery
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2018-02-20 18:31:17 +0000
committerColin Watson <cjwatson@debian.org>2018-02-20 18:32:43 +0000
commitf9aaf5dacc906f5e4a51b4ce984078aaa0c84bf4 (patch)
tree23940ad6af41e336b7ec9a91c1acf66c9d7e111b /macaroonbakery
parent650d1b77a8729ffb148fc3a22923d7a52678738c (diff)
parentc1850c8a10886894255100fae185c450e800564a (diff)
New upstream release (1.1.2)
Diffstat (limited to 'macaroonbakery')
-rw-r--r--macaroonbakery/httpbakery/agent/_agent.py13
-rw-r--r--macaroonbakery/tests/test_agent.py19
2 files changed, 20 insertions, 12 deletions
diff --git a/macaroonbakery/httpbakery/agent/_agent.py b/macaroonbakery/httpbakery/agent/_agent.py
index b717261..618097c 100644
--- a/macaroonbakery/httpbakery/agent/_agent.py
+++ b/macaroonbakery/httpbakery/agent/_agent.py
@@ -109,14 +109,15 @@ class AgentInteractor(httpbakery.Interactor, httpbakery.LegacyInteractor):
if not location.endswith('/'):
location += '/'
login_url = urljoin(location, p.login_url)
- # TODO use client to make the request.
- resp = requests.get(login_url, json={
- 'Username': agent.username,
- 'PublicKey': str(self._auth_info.key),
- })
+ resp = requests.get(
+ login_url, params={
+ 'username': agent.username,
+ 'public-key': str(self._auth_info.key.public_key)},
+ auth=client.auth())
if resp.status_code != 200:
raise httpbakery.InteractionError(
- 'cannot acquire agent macaroon: {}'.format(resp.status_code)
+ 'cannot acquire agent macaroon: {} {}'.format(
+ resp.status_code, resp.text)
)
m = resp.json().get('macaroon')
if m is None:
diff --git a/macaroonbakery/tests/test_agent.py b/macaroonbakery/tests/test_agent.py
index 3b38337..d670485 100644
--- a/macaroonbakery/tests/test_agent.py
+++ b/macaroonbakery/tests/test_agent.py
@@ -14,10 +14,13 @@ import macaroonbakery.httpbakery.agent as agent
import requests.cookies
from httmock import HTTMock, response, urlmatch
-from six.moves.urllib.parse import parse_qs
+from six.moves.urllib.parse import parse_qs, urlparse
log = logging.getLogger(__name__)
+PRIVATE_KEY = 'CqoSgj06Zcgb4/S6RT4DpTjLAfKoznEY3JsShSjKJEU='
+PUBLIC_KEY = 'YAhRSsth3a36mRYqQGQaLiS4QJax0p356nd+B8x7UQE='
+
class TestAgents(TestCase):
def setUp(self):
@@ -41,8 +44,8 @@ class TestAgents(TestCase):
def test_load_auth_info(self):
auth_info = agent.load_auth_info(self.agent_filename)
- self.assertEqual(str(auth_info.key), 'CqoSgj06Zcgb4/S6RT4DpTjLAfKoznEY3JsShSjKJEU=')
- self.assertEqual(str(auth_info.key.public_key), 'YAhRSsth3a36mRYqQGQaLiS4QJax0p356nd+B8x7UQE=')
+ self.assertEqual(str(auth_info.key), PRIVATE_KEY)
+ self.assertEqual(str(auth_info.key.public_key), PUBLIC_KEY)
self.assertEqual(auth_info.agents, [
agent.Agent(url='https://1.example.com/', username='user-1'),
agent.Agent(url='https://2.example.com/discharger', username='user-2'),
@@ -139,12 +142,16 @@ class TestAgents(TestCase):
@urlmatch(path='.*/login')
def login(url, request):
+ qs = parse_qs(urlparse(request.url).query)
+ self.assertEqual(request.method, 'GET')
+ self.assertEqual(
+ qs, {'username': ['test-user'], 'public-key': [PUBLIC_KEY]})
b = bakery.Bakery(key=discharge_key)
m = b.oven.macaroon(
version=bakery.LATEST_VERSION,
expiry=datetime.utcnow() + timedelta(days=1),
caveats=[bakery.local_third_party_caveat(
- auth_info.key.public_key,
+ PUBLIC_KEY,
version=httpbakery.request_version(request.headers))],
ops=[bakery.Op(entity='agent', action='login')])
return {
@@ -164,7 +171,7 @@ class TestAgents(TestCase):
'http://0.1.2.3/here',
cookies=client.cookies,
auth=client.auth())
- self.assertEquals(resp.content, b'done')
+ self.assertEqual(resp.content, b'done')
def test_agent_legacy(self):
discharge_key = bakery.generate_key()
@@ -346,7 +353,7 @@ class TestAgents(TestCase):
cookies=client.cookies,
auth=client.auth(),
)
- self.assertEquals(resp.content, b'done')
+ self.assertEqual(resp.content, b'done')
agent_file = '''