diff options
author | Colin Watson <cjwatson@debian.org> | 2017-11-06 10:04:48 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2017-11-06 10:04:48 +0000 |
commit | 37d61d0415f6cc96a7a9abe057e1ae0f89fd977e (patch) | |
tree | 4ca3c2560d2ba062adb7de86d047d67db8984940 /macaroonbakery/tests/test_macaroon.py | |
parent | 3d9eaeb5dacee168a93da090e2c0d46eedbe51a2 (diff) |
Import py-macaroon-bakery_0.0.5.orig.tar.gz
Diffstat (limited to 'macaroonbakery/tests/test_macaroon.py')
-rw-r--r-- | macaroonbakery/tests/test_macaroon.py | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/macaroonbakery/tests/test_macaroon.py b/macaroonbakery/tests/test_macaroon.py index 7e77e2b..93bbbb8 100644 --- a/macaroonbakery/tests/test_macaroon.py +++ b/macaroonbakery/tests/test_macaroon.py @@ -7,36 +7,35 @@ import six import pymacaroons from pymacaroons import serializers -import macaroonbakery +import macaroonbakery as bakery import macaroonbakery.checkers as checkers from macaroonbakery.tests import common class TestMacaroon(TestCase): def test_new_macaroon(self): - m = macaroonbakery.Macaroon( + m = bakery.Macaroon( b'rootkey', b'some id', 'here', - macaroonbakery.LATEST_BAKERY_VERSION) + bakery.LATEST_VERSION) self.assertIsNotNone(m) self.assertEquals(m._macaroon.identifier, b'some id') self.assertEquals(m._macaroon.location, 'here') - self.assertEquals(m.version, macaroonbakery.LATEST_BAKERY_VERSION) + self.assertEquals(m.version, bakery.LATEST_VERSION) def test_add_first_party_caveat(self): - m = macaroonbakery.Macaroon('rootkey', 'some id', 'here', - macaroonbakery.LATEST_BAKERY_VERSION) + m = bakery.Macaroon('rootkey', 'some id', 'here', bakery.LATEST_VERSION) m.add_caveat(checkers.Caveat('test_condition')) caveats = m.first_party_caveats() self.assertEquals(len(caveats), 1) self.assertEquals(caveats[0].caveat_id, b'test_condition') def test_add_third_party_caveat(self): - locator = macaroonbakery.ThirdPartyStore() + locator = bakery.ThirdPartyStore() bs = common.new_bakery('bs-loc', locator) - lbv = six.int2byte(macaroonbakery.LATEST_BAKERY_VERSION) + lbv = six.int2byte(bakery.LATEST_VERSION) tests = [ ('no existing id', b'', [], lbv + six.int2byte(0)), ('several existing ids', b'', [ @@ -53,10 +52,10 @@ class TestMacaroon(TestCase): for test in tests: print('test ', test[0]) - m = macaroonbakery.Macaroon( + m = bakery.Macaroon( root_key=b'root key', id=b'id', location='location', - version=macaroonbakery.LATEST_BAKERY_VERSION) + version=bakery.LATEST_VERSION) for id in test[2]: m.macaroon.add_third_party_caveat(key=None, key_id=id, location='') @@ -68,21 +67,21 @@ class TestMacaroon(TestCase): test[3]) def test_marshal_json_latest_version(self): - locator = macaroonbakery.ThirdPartyStore() + locator = bakery.ThirdPartyStore() bs = common.new_bakery('bs-loc', locator) ns = checkers.Namespace({ 'testns': 'x', 'otherns': 'y', }) - m = macaroonbakery.Macaroon( + m = bakery.Macaroon( root_key=b'root key', id=b'id', location='location', - version=macaroonbakery.LATEST_BAKERY_VERSION, + version=bakery.LATEST_VERSION, namespace=ns) m.add_caveat(checkers.Caveat(location='bs-loc', condition='something'), bs.oven.key, locator) data = m.serialize_json() - m1 = macaroonbakery.Macaroon.deserialize_json(data) + m1 = bakery.Macaroon.deserialize_json(data) # Just check the signature and version - we're not interested in fully # checking the macaroon marshaling here. self.assertEqual(m1.macaroon.signature, m.macaroon.signature) @@ -92,8 +91,8 @@ class TestMacaroon(TestCase): self.assertEqual(m1._caveat_data, m._caveat_data) # test with the encoder, decoder - data = json.dumps(m, cls=macaroonbakery.MacaroonJSONEncoder) - m1 = json.loads(data, cls=macaroonbakery.MacaroonJSONDecoder) + data = json.dumps(m, cls=bakery.MacaroonJSONEncoder) + m1 = json.loads(data, cls=bakery.MacaroonJSONDecoder) self.assertEqual(m1.macaroon.signature, m.macaroon.signature) self.assertEqual(m1.macaroon.version, m.macaroon.version) self.assertEqual(len(m1.macaroon.caveats), 1) @@ -101,20 +100,20 @@ class TestMacaroon(TestCase): self.assertEqual(m1._caveat_data, m._caveat_data) def test_json_version1(self): - self._test_json_with_version(macaroonbakery.BAKERY_V1) + self._test_json_with_version(bakery.VERSION_1) def test_json_version2(self): - self._test_json_with_version(macaroonbakery.BAKERY_V2) + self._test_json_with_version(bakery.VERSION_2) def _test_json_with_version(self, version): - locator = macaroonbakery.ThirdPartyStore() + locator = bakery.ThirdPartyStore() bs = common.new_bakery('bs-loc', locator) ns = checkers.Namespace({ 'testns': 'x', }) - m = macaroonbakery.Macaroon( + m = bakery.Macaroon( root_key=b'root key', id=b'id', location='location', version=version, namespace=ns) @@ -124,18 +123,18 @@ class TestMacaroon(TestCase): # Sanity check that no external caveat data has been added. self.assertEqual(len(m._caveat_data), 0) - data = json.dumps(m, cls=macaroonbakery.MacaroonJSONEncoder) - m1 = json.loads(data, cls=macaroonbakery.MacaroonJSONDecoder) + data = json.dumps(m, cls=bakery.MacaroonJSONEncoder) + m1 = json.loads(data, cls=bakery.MacaroonJSONDecoder) # Just check the signature and version - we're not interested in fully # checking the macaroon marshaling here. self.assertEqual(m1.macaroon.signature, m.macaroon.signature) self.assertEqual(m1.macaroon.version, - macaroonbakery.macaroon_version(version)) + bakery.macaroon_version(version)) self.assertEqual(len(m1.macaroon.caveats), 1) # Namespace information has been thrown away. - self.assertEqual(m1.namespace, macaroonbakery.legacy_namespace()) + self.assertEqual(m1.namespace, bakery.legacy_namespace()) self.assertEqual(len(m1._caveat_data), 0) @@ -144,9 +143,9 @@ class TestMacaroon(TestCase): with self.assertRaises(ValueError) as exc: json.loads(json.dumps({ 'm': m.serialize(serializer=serializers.JsonSerializer()), - 'v': macaroonbakery.LATEST_BAKERY_VERSION + 1 - }), cls=macaroonbakery.MacaroonJSONDecoder) - self.assertEqual('unknow bakery version 4', exc.exception.args[0]) + 'v': bakery.LATEST_VERSION + 1 + }), cls=bakery.MacaroonJSONDecoder) + self.assertEqual('unknown bakery version 4', exc.exception.args[0]) def test_json_inconsistent_version(self): m = pymacaroons.Macaroon(version=pymacaroons.MACAROON_V1) @@ -154,21 +153,21 @@ class TestMacaroon(TestCase): json.loads(json.dumps({ 'm': json.loads(m.serialize( serializer=serializers.JsonSerializer())), - 'v': macaroonbakery.LATEST_BAKERY_VERSION - }), cls=macaroonbakery.MacaroonJSONDecoder) + 'v': bakery.LATEST_VERSION + }), cls=bakery.MacaroonJSONDecoder) self.assertEqual('underlying macaroon has inconsistent version; ' 'got 1 want 2', exc.exception.args[0]) def test_clone(self): - locator = macaroonbakery.ThirdPartyStore() + locator = bakery.ThirdPartyStore() bs = common.new_bakery("bs-loc", locator) ns = checkers.Namespace({ "testns": "x", }) - m = macaroonbakery.Macaroon( + m = bakery.Macaroon( root_key=b'root key', id=b'id', location='location', - version=macaroonbakery.LATEST_BAKERY_VERSION, + version=bakery.LATEST_VERSION, namespace=ns) m.add_caveat(checkers.Caveat(location='bs-loc', condition='something'), bs.oven.key, locator) @@ -185,15 +184,15 @@ class TestMacaroon(TestCase): def test_json_deserialize_from_go(self): ns = checkers.Namespace() ns.register("someuri", "x") - m = macaroonbakery.Macaroon( + m = bakery.Macaroon( root_key=b'rootkey', id=b'some id', location='here', - version=macaroonbakery.LATEST_BAKERY_VERSION, namespace=ns) + version=bakery.LATEST_VERSION, namespace=ns) m.add_caveat(checkers.Caveat(condition='something', namespace='someuri')) data = '{"m":{"c":[{"i":"x:something"}],"l":"here","i":"some id",' \ '"s64":"c8edRIupArSrY-WZfa62pgZFD8VjDgqho9U2PlADe-E"},"v":3,' \ '"ns":"someuri:x"}' - m_go = macaroonbakery.Macaroon.deserialize_json(data) + m_go = bakery.Macaroon.deserialize_json(data) self.assertEqual(m.macaroon.signature_bytes, m_go.macaroon.signature_bytes) |