summaryrefslogtreecommitdiff
path: root/macaroonbakery
diff options
context:
space:
mode:
Diffstat (limited to 'macaroonbakery')
-rw-r--r--macaroonbakery/checkers/_checkers.py9
-rw-r--r--macaroonbakery/httpbakery/_browser.py5
-rw-r--r--macaroonbakery/httpbakery/_client.py7
-rw-r--r--macaroonbakery/tests/common.py4
-rw-r--r--macaroonbakery/tests/test_checkers.py3
-rw-r--r--macaroonbakery/tests/test_client.py5
-rw-r--r--macaroonbakery/tests/test_httpbakery.py16
-rw-r--r--macaroonbakery/tests/test_utils.py4
8 files changed, 39 insertions, 14 deletions
diff --git a/macaroonbakery/checkers/_checkers.py b/macaroonbakery/checkers/_checkers.py
index 71cb56f..11a41b9 100644
--- a/macaroonbakery/checkers/_checkers.py
+++ b/macaroonbakery/checkers/_checkers.py
@@ -5,7 +5,6 @@ from collections import namedtuple
from datetime import datetime
import pyrfc3339
-import pytz
from ._caveat import parse_caveat
from ._conditions import (
COND_ALLOW,
@@ -166,12 +165,16 @@ class CheckerInfo(namedtuple('CheckInfo', 'prefix name ns check')):
def _check_time_before(ctx, cond, arg):
clock = ctx.get(TIME_KEY)
if clock is None:
- now = pytz.UTC.localize(datetime.utcnow())
+ now = datetime.utcnow()
else:
now = clock.utcnow()
try:
- if pyrfc3339.parse(arg) <= now:
+ # Note: pyrfc3339 returns a datetime with a timezone, which
+ # we need to remove before we can compare it with the naive
+ # datetime object returned by datetime.utcnow.
+ expiry = pyrfc3339.parse(arg, utc=True).replace(tzinfo=None)
+ if now >= expiry:
return 'macaroon has expired'
except ValueError:
return 'cannot parse "{}" as RFC 3339'.format(arg)
diff --git a/macaroonbakery/httpbakery/_browser.py b/macaroonbakery/httpbakery/_browser.py
index a1ccbb0..c8a5586 100644
--- a/macaroonbakery/httpbakery/_browser.py
+++ b/macaroonbakery/httpbakery/_browser.py
@@ -85,5 +85,6 @@ class WebBrowserInteractionInfo(namedtuple('WebBrowserInteractionInfo',
@param info_dict The deserialized JSON object
@return a new WebBrowserInteractionInfo object.
'''
- return WebBrowserInteractionInfo(visit_url=info_dict.get('VisitURL'),
- wait_token_url=info_dict('WaitURL'))
+ return WebBrowserInteractionInfo(
+ visit_url=info_dict.get('VisitURL'),
+ wait_token_url=info_dict.get('WaitTokenURL'))
diff --git a/macaroonbakery/httpbakery/_client.py b/macaroonbakery/httpbakery/_client.py
index d877140..4fe0ab1 100644
--- a/macaroonbakery/httpbakery/_client.py
+++ b/macaroonbakery/httpbakery/_client.py
@@ -320,8 +320,11 @@ def extract_macaroons(headers_or_request):
mss = []
def add_macaroon(data):
- data = utils.b64decode(data)
- data_as_objs = json.loads(data.decode('utf-8'))
+ try:
+ data = utils.b64decode(data)
+ data_as_objs = json.loads(data.decode('utf-8'))
+ except ValueError:
+ return
ms = [utils.macaroon_from_dict(x) for x in data_as_objs]
mss.append(ms)
diff --git a/macaroonbakery/tests/common.py b/macaroonbakery/tests/common.py
index cfbfc52..972b3ad 100644
--- a/macaroonbakery/tests/common.py
+++ b/macaroonbakery/tests/common.py
@@ -4,7 +4,6 @@ from datetime import datetime, timedelta
import macaroonbakery.bakery as bakery
import macaroonbakery.checkers as checkers
-import pytz
class _StoppedClock(object):
@@ -15,8 +14,7 @@ class _StoppedClock(object):
return self.t
-epoch = pytz.utc.localize(
- datetime(year=1900, month=11, day=17, hour=19, minute=00, second=13))
+epoch = datetime(year=1900, month=11, day=17, hour=19, minute=00, second=13)
ages = epoch + timedelta(days=1)
test_context = checkers.context_with_clock(checkers.AuthContext(),
diff --git a/macaroonbakery/tests/test_checkers.py b/macaroonbakery/tests/test_checkers.py
index 28da06e..2628153 100644
--- a/macaroonbakery/tests/test_checkers.py
+++ b/macaroonbakery/tests/test_checkers.py
@@ -4,7 +4,6 @@ from datetime import datetime, timedelta
from unittest import TestCase
import macaroonbakery.checkers as checkers
-import pytz
import six
from pymacaroons import MACAROON_V2, Macaroon
@@ -15,7 +14,7 @@ NOW = datetime(
class TestClock():
def utcnow(self):
- return pytz.UTC.localize(NOW)
+ return NOW
class TestCheckers(TestCase):
diff --git a/macaroonbakery/tests/test_client.py b/macaroonbakery/tests/test_client.py
index ab20c3b..bfc7807 100644
--- a/macaroonbakery/tests/test_client.py
+++ b/macaroonbakery/tests/test_client.py
@@ -346,6 +346,11 @@ class TestClient(TestCase):
value=encode_macaroon(m2),
url='http://example.com',
))
+ jar.set_cookie(utils.cookie(
+ name='macaroon-empty',
+ value='',
+ url='http://example.com',
+ ))
jar.add_cookie_header(req)
macaroons = httpbakery.extract_macaroons(req)
diff --git a/macaroonbakery/tests/test_httpbakery.py b/macaroonbakery/tests/test_httpbakery.py
new file mode 100644
index 0000000..4aac850
--- /dev/null
+++ b/macaroonbakery/tests/test_httpbakery.py
@@ -0,0 +1,16 @@
+from unittest import TestCase
+
+from macaroonbakery.httpbakery import WebBrowserInteractionInfo
+
+
+class TestWebBrowserInteractionInfo(TestCase):
+
+ def test_from_dict(self):
+ info_dict = {
+ 'VisitURL': 'https://example.com/visit',
+ 'WaitTokenURL': 'https://example.com/wait'}
+ interaction_info = WebBrowserInteractionInfo.from_dict(info_dict)
+ self.assertEqual(
+ interaction_info.visit_url, 'https://example.com/visit')
+ self.assertEqual(
+ interaction_info.wait_token_url, 'https://example.com/wait')
diff --git a/macaroonbakery/tests/test_utils.py b/macaroonbakery/tests/test_utils.py
index fcc8839..65edeb4 100644
--- a/macaroonbakery/tests/test_utils.py
+++ b/macaroonbakery/tests/test_utils.py
@@ -7,7 +7,6 @@ from unittest import TestCase
import macaroonbakery.bakery as bakery
import pymacaroons
-import pytz
from macaroonbakery._utils import cookie
from pymacaroons.serializers import json_serializer
@@ -21,7 +20,8 @@ class CookieTest(TestCase):
c.expires, int((timestamp - datetime(1970, 1, 1)).total_seconds()))
def test_cookie_expires_with_timezone(self):
- timestamp = datetime.now(pytz.UTC)
+ from datetime import tzinfo
+ timestamp = datetime.utcnow().replace(tzinfo=tzinfo())
self.assertRaises(
ValueError, cookie, 'http://example.com', 'test', 'value',
expires=timestamp)