コード例 #1
0
    def test_mem_store(self):
        st = macaroonbakery.MemoryKeyStore()

        key, id = st.root_key()
        self.assertEqual(len(key), 24)
        self.assertEqual(id.decode('utf-8'), '0')

        key1, id1 = st.root_key()
        self.assertEqual(key1, key)
        self.assertEqual(id1, id)

        key2 = st.get(id)
        self.assertEqual(key2, key)
コード例 #2
0
 def test_version1_macaroon_id(self):
     # In the version 1 bakery, macaroon ids were hex-encoded with a
     # hyphenated UUID suffix.
     root_key_store = bakery.MemoryKeyStore()
     b = bakery.Bakery(
         root_key_store=root_key_store,
         identity_client=common.OneIdentity(),
     )
     key, id = root_key_store.root_key()
     root_key_store.get(id)
     m = Macaroon(key=key, version=MACAROON_V1, location='',
                  identifier=id + b'-deadl00f')
     b.checker.auth([[m]]).allow(common.test_context,
                                 [bakery.LOGIN_OP])
コード例 #3
0
 def __init__(self,
              key=None,
              location=None,
              locator=None,
              namespace=None,
              root_keystore_for_ops=None,
              ops_store=None):
     '''
     @param namespace holds the namespace to use when adding first party
     caveats.
     @param root_keystore_for_ops a function that will give the macaroon
     storage to be used for root keys associated with macaroons created
     with macaroon.
     @param ops_store object is used to persistently store the association
     of multi-op entities with their associated operations when macaroon is
     called with multiple operations.
     When this is in use, operation entities with the prefix "multi-" are
     reserved - a "multi-"-prefixed entity represents a set of operations
     stored in the OpsStore.
     @param key holds the private nacl key pair used to encrypt third party
     caveats. If it is None, no third party caveats can be created.
     @param location string holds the location that will be associated with
     new macaroons (as returned by Macaroon.Location).
     @param locator is used to find out information on third parties when
     adding third party caveats. If this is None, no non-local third
     party caveats can be added.
     '''
     self.key = key
     self.location = location
     self.locator = locator
     if namespace is None:
         namespace = checkers.Checker().namespace()
     self.namespace = namespace
     self.ops_store = ops_store
     self.root_keystore_for_ops = root_keystore_for_ops
     if root_keystore_for_ops is None:
         my_store = bakery.MemoryKeyStore()
         self.root_keystore_for_ops = lambda x: my_store
コード例 #4
0
 def __init__(self, key, locator):
     self._root_key_store = macaroonbakery.MemoryKeyStore()
     self._key = key
     self._locator = locator