当前位置: 首页>>代码示例>>Python>>正文


Python Macaroon.prepare_for_request方法代码示例

本文整理汇总了Python中pymacaroons.Macaroon.prepare_for_request方法的典型用法代码示例。如果您正苦于以下问题:Python Macaroon.prepare_for_request方法的具体用法?Python Macaroon.prepare_for_request怎么用?Python Macaroon.prepare_for_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymacaroons.Macaroon的用法示例。


在下文中一共展示了Macaroon.prepare_for_request方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_verify_third_party_caveats

# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import prepare_for_request [as 别名]
    def test_verify_third_party_caveats(self):
        m = Macaroon(
            location='http://mybank/',
            identifier='we used our other secret key',
            key='this is a different super-secret key; \
never use the same secret twice'
        )
        m.add_first_party_caveat('account = 3735928559')
        caveat_key = '4; guaranteed random by a fair toss of the dice'
        identifier = 'this was how we remind auth of key/pred'
        m.add_third_party_caveat('http://auth.mybank/', caveat_key, identifier)

        discharge = Macaroon(
            location='http://auth.mybank/',
            key=caveat_key,
            identifier=identifier
        )
        discharge.add_first_party_caveat('time < 2015-01-01T00:00')
        protected = m.prepare_for_request(discharge)

        v = Verifier()
        v.satisfy_exact('account = 3735928559')
        v.satisfy_exact('time < 2015-01-01T00:00')
        verified = v.verify(
            m,
            'this is a different super-secret key; \
never use the same secret twice',
            discharge_macaroons=[protected]
        )
        assert_true(verified)
开发者ID:matrix-org,项目名称:pymacaroons,代码行数:32,代码来源:functional_tests.py

示例2: generate_macaroon

# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import prepare_for_request [as 别名]
    def generate_macaroon(self, nonce):
        m = Macaroon(
            location='http://mybank/',
            identifier='we used our other secret key',
            key='this is a different super-secret key; \
never use the same secret twice'
        )
        m.add_first_party_caveat('account = 3735928559')
        caveat_key = '4; guaranteed random by a fair toss of the dice'
        identifier = 'this was how we remind auth of key/pred'
        m.add_third_party_caveat(
            'http://auth.mybank/',
            caveat_key,
            identifier,
            nonce=nonce,
        )

        discharge = Macaroon(
            location='http://auth.mybank/',
            key=caveat_key,
            identifier=identifier
        )
        discharge.add_first_party_caveat('time < 2015-01-01T00:00')
        protected = m.prepare_for_request(discharge)
        return protected.signature
开发者ID:matrix-org,项目名称:pymacaroons,代码行数:27,代码来源:functional_tests.py

示例3: test_prepare_for_request

# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import prepare_for_request [as 别名]
    def test_prepare_for_request(self, rand_nonce):
        # use a fixed nonce to ensure the same signature
        rand_nonce.return_value = truncate_or_pad(
            b'\0',
            size=crypto_box_NONCEBYTES
        )
        m = Macaroon(
            location='http://mybank/',
            identifier='we used our other secret key',
            key='this is a different super-secret key; \
never use the same secret twice'
        )
        m.add_first_party_caveat('account = 3735928559')
        caveat_key = '4; guaranteed random by a fair toss of the dice'
        identifier = 'this was how we remind auth of key/pred'
        m.add_third_party_caveat(
            'http://auth.mybank/',
            caveat_key,
            identifier
        )

        discharge = Macaroon(
            location='http://auth.mybank/',
            key=caveat_key,
            identifier=identifier
        )
        discharge.add_first_party_caveat('time < 2015-01-01T00:00')
        protected = m.prepare_for_request(discharge)
        assert_equal(
            protected.signature,
            '2eb01d0dd2b4475330739140188648cf25dda0425ea9f661f1574ca0a9eac54e'
        )
开发者ID:erikjohnston,项目名称:pymacaroons,代码行数:34,代码来源:functional_tests.py

示例4: test_mutual_discharge

# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import prepare_for_request [as 别名]
 def test_mutual_discharge(self):
     m1 = Macaroon(location="", identifier="root-id", key="root-key")
     m1.add_third_party_caveat("bob", "bob-caveat-root-key", "bob-is-great")
     m2 = Macaroon(location="bob", identifier="bob-is-great", key="bob-caveat-root-key")
     m2.add_third_party_caveat("charlie", "bob-caveat-root-key", "bob-is-great")
     m2 = m1.prepare_for_request(m2)
     Verifier(discharge_macaroons=[m2]).verify(m1, "root-key")
开发者ID:ecordell,项目名称:pymacaroons,代码行数:9,代码来源:functional_tests.py

示例5: test_verify_third_party_caveats_multi_level

# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import prepare_for_request [as 别名]
    def test_verify_third_party_caveats_multi_level(self):
      # See https://github.com/ecordell/pymacaroons/issues/37
      root = Macaroon(location="", identifier="root-id", key="root-key")
      root.add_third_party_caveat("bob", "bob-caveat-root-key", "bob-is-great")

      # Create a discharge macaroon that requires a secondary discharge.
      discharge1 = Macaroon(location="bob", identifier="bob-is-great", key="bob-caveat-root-key")
      discharge1.add_third_party_caveat("barbara", "barbara-caveat-root-key", "barbara-is-great")

      # Create the secondary discharge macaroon.
      discharge2 = Macaroon(location="barbara", identifier="barbara-is-great", key="barbara-caveat-root-key")

      # Prepare the discharge macaroons for request.
      discharge1 = root.prepare_for_request(discharge1)
      discharge2 = root.prepare_for_request(discharge2)

      verified = Verifier(discharge_macaroons=[discharge1, discharge2]).verify(root, "root-key")
      assert_true(verified)
开发者ID:ecordell,项目名称:pymacaroons,代码行数:20,代码来源:functional_tests.py

示例6: test_macaroon_paper_fig6_fails_with_binding_on_tampered_sig

# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import prepare_for_request [as 别名]
    def test_macaroon_paper_fig6_fails_with_binding_on_tampered_sig(self):
        ''' Runs a similar test as test_macaroon_paper_fig6 with the discharge
        macaroon binding being done on a tampered signature.
        '''
        locator = bakery.ThirdPartyStore()
        bs = common.new_bakery('bs-loc', locator)
        ts = common.new_bakery('ts-loc', locator)

        # ts creates a macaroon.
        ts_macaroon = ts.oven.macaroon(bakery.LATEST_VERSION,
                                       common.ages, None,
                                       [bakery.LOGIN_OP])
        # ts somehow sends the macaroon to fs which adds a third party caveat
        # to be discharged by as.
        ts_macaroon.add_caveat(checkers.Caveat(condition='user==bob',
                                               location='bs-loc'),
                               ts.oven.key, ts.oven.locator)

        # client asks for a discharge macaroon for each third party caveat
        def get_discharge(cav, payload):
            self.assertEqual(cav.location, 'bs-loc')
            return bakery.discharge(
                common.test_context,
                cav.caveat_id_bytes,
                payload,
                bs.oven.key,
                common.ThirdPartyStrcmpChecker('user==bob'),
                bs.oven.locator,
            )

        d = bakery.discharge_all(ts_macaroon, get_discharge)
        # client has all the discharge macaroons. For each discharge macaroon
        # bind it to our ts_macaroon and add it to our request.
        tampered_macaroon = Macaroon()
        for i, dm in enumerate(d[1:]):
            d[i + 1] = tampered_macaroon.prepare_for_request(dm)

        # client makes request to ts.
        with self.assertRaises(bakery.VerificationError) as exc:
            ts.checker.auth([d]).allow(common.test_context,
                                       bakery.LOGIN_OP)
        self.assertEqual('verification failed: Signatures do not match',
                         exc.exception.args[0])
开发者ID:fabricematrat,项目名称:py-macaroon-bakery,代码行数:45,代码来源:test_discharge.py


注:本文中的pymacaroons.Macaroon.prepare_for_request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。