• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pymacaroons.Macaroon类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_serializing_max_length_packet

 def test_serializing_max_length_packet(self):
     m = Macaroon(location='test', identifier='blah', key='secret')
     m.add_first_party_caveat('x' * 65526)  # exactly 0xFFFF
     assert_not_equal(
         m.serialize(),
         None
     )
开发者ID:matrix-org,项目名称:pymacaroons,代码行数:7,代码来源:functional_tests.py


示例2: test_serializing_too_long_packet

 def test_serializing_too_long_packet(self):
     m = Macaroon(location='test', identifier='blah', key='secret')
     m.add_first_party_caveat('x' * 65527)  # one byte too long
     assert_raises(
         MacaroonSerializationException,
         m.serialize
     )
开发者ID:matrix-org,项目名称:pymacaroons,代码行数:7,代码来源:functional_tests.py


示例3: get_authorization_header

def get_authorization_header(root, discharge):
    """
    Bind root and discharge macaroons and return the authorization header.
    """

    bound = Macaroon.deserialize(root).prepare_for_request(
        Macaroon.deserialize(discharge)
    )

    return "Macaroon root={}, discharge={}".format(root, bound.serialize())
开发者ID:anthonydillon,项目名称:snapcraft.io,代码行数:10,代码来源:authentication.py


示例4: test_inspect

    def test_inspect(self):
        m = Macaroon(
            location='http://mybank/',
            identifier='we used our secret key',
            key='this is our super secret key; only we should know it'
        )
        m.add_first_party_caveat('test = caveat')
        assert_equal(m.inspect(), 'location http://mybank/\nidentifier we used\
 our secret key\ncid test = caveat\nsignature 197bac7a044af33332865b9266e26d49\
3bdd668a660e44d88ce1a998c23dbd67')
开发者ID:illicitonion,项目名称:pymacaroons,代码行数:10,代码来源:functional_tests.py


示例5: generate_macaroon

    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,代码行数:25,代码来源:functional_tests.py


示例6: test_verify_third_party_caveats

    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,代码行数:30,代码来源:functional_tests.py


示例7: test_prepare_for_request

    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,代码行数:32,代码来源:functional_tests.py


示例8: test_serializing_json

 def test_serializing_json(self):
     m = Macaroon(
         location='http://mybank/',
         identifier='we used our secret key',
         key='this is our super secret key; only we should know it'
     )
     m.add_first_party_caveat('test = caveat')
     assert_equal(
         json.loads(m.serialize(serializer=JsonSerializer()))['signature'],
         "197bac7a044af33332865b9266e26d493bdd668a660e44d88ce1a998c23dbd67"
     )
开发者ID:matrix-org,项目名称:pymacaroons,代码行数:11,代码来源:functional_tests.py


示例9: test_serializing_v2

 def test_serializing_v2(self):
     m = Macaroon(
         location='http://mybank/',
         identifier='we used our secret key',
         key='this is our super secret key; only we should know it',
         version=MACAROON_V2
     )
     m.add_first_party_caveat('test = caveat')
     n = Macaroon.deserialize(m.serialize())
     assert_equal(m.identifier_bytes, n.identifier_bytes)
     assert_equal(m.version, n.version)
开发者ID:ecordell,项目名称:pymacaroons,代码行数:11,代码来源:functional_tests.py


示例10: test_serializing_deserializing_macaroon

 def test_serializing_deserializing_macaroon(self, key_id, loc, key):
     assume(key_id and loc and key)
     macaroon = Macaroon(
         location=loc,
         identifier=key_id,
         key=key
     )
     deserialized = Macaroon.deserialize(macaroon.serialize())
     assert_equal(macaroon.identifier, deserialized.identifier)
     assert_equal(macaroon.location, deserialized.location)
     assert_equal(macaroon.signature, deserialized.signature)
开发者ID:matrix-org,项目名称:pymacaroons,代码行数:11,代码来源:macaroon_property_tests.py


示例11: test_serializing_json_v2

 def test_serializing_json_v2(self):
     m = Macaroon(
         location='http://mybank/',
         identifier='we used our secret key',
         key='this is our super secret key; only we should know it',
         version=MACAROON_V2
     )
     m.add_first_party_caveat('test = caveat')
     assert_equal(
         json.loads(m.serialize(serializer=JsonSerializer()))['s64'],
         "GXusegRK8zMyhluSZuJtSTvdZopmDkTYjOGpmMI9vWc"
     )
开发者ID:ecordell,项目名称:pymacaroons,代码行数:12,代码来源:functional_tests.py


示例12: test_serializing_deserializing_json

 def test_serializing_deserializing_json(self):
     m = Macaroon(
         location='http://test/',
         identifier='first',
         key='secret_key_1'
     )
     m.add_first_party_caveat('test = caveat')
     n = Macaroon.deserialize(
         m.serialize(serializer=JsonSerializer()),
         serializer=JsonSerializer()
     )
     assert_equal(m.signature, n.signature)
开发者ID:matrix-org,项目名称:pymacaroons,代码行数:12,代码来源:functional_tests.py


示例13: test_serializing_with_binary_v2

 def test_serializing_with_binary_v2(self):
     identifier = base64.b64decode('AK2o+q0Aq9+bONkXw7ky7HAuhCLO9hhaMMc==')
     m = Macaroon(
         location='http://mybank/',
         identifier=identifier,
         key='this is our super secret key; only we should know it',
         version=MACAROON_V2
     )
     m.add_first_party_caveat('test = caveat')
     n = Macaroon.deserialize(m.serialize())
     assert_equal(m.identifier_bytes, n.identifier_bytes)
     assert_equal(m.version, n.version)
开发者ID:ecordell,项目名称:pymacaroons,代码行数:12,代码来源:functional_tests.py


示例14: test_serializing

    def test_serializing(self):
        m = Macaroon(
            location='http://mybank/',
            identifier='we used our secret key',
            key='this is our super secret key; only we should know it'
        )
        m.add_first_party_caveat('test = caveat')
        assert_equal(
            m.serialize(),
            'MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZ\
WQgb3VyIHNlY3JldCBrZXkKMDAxNmNpZCB0ZXN0ID0gY2F2ZWF0CjAwMmZzaWduYXR1cmUgGXusegR\
K8zMyhluSZuJtSTvdZopmDkTYjOGpmMI9vWcK'
        )
开发者ID:matrix-org,项目名称:pymacaroons,代码行数:13,代码来源:functional_tests.py


示例15: test_encrypted_first_party_caveat

 def test_encrypted_first_party_caveat(self):
     m = Macaroon(
         location='http://mybank/',
         identifier='we used our secret key',
         key='this is our super secret key; only we should know it'
     )
     encryptor = SecretBoxEncryptor(nonce=ZERO_NONCE)
     m.first_party_caveat_delegate = EncryptedFirstPartyCaveatDelegate(field_encryptor=encryptor)
     m.add_first_party_caveat('test = caveat', encrypted=True)
     assert_equal(
         m.signature,
         'a443bc61e8f45dca4f0c441d6cfde90b804cebb0b267aab60de1ec2ab8cc8522'
     )
开发者ID:matrix-org,项目名称:pymacaroons,代码行数:13,代码来源:encrypted_field_tests.py


示例16: test_serializing_strips_padding

 def test_serializing_strips_padding(self):
     m = Macaroon(
         location='http://mybank/',
         identifier='we used our secret key',
         key='this is our super secret key; only we should know it'
     )
     m.add_first_party_caveat('test = acaveat')
     assert_equal(
         m.serialize(),
         # In padded base64, this would end with '=='
         ('MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVz'
          'ZWQgb3VyIHNlY3JldCBrZXkKMDAxN2NpZCB0ZXN0ID0gYWNhdmVhdAowMDJmc2ln'
          'bmF0dXJlIJRJ_V3WNJQnqlVq5eez7spnltwU_AXs8NIRY739sHooCg')
     )
开发者ID:matrix-org,项目名称:pymacaroons,代码行数:14,代码来源:functional_tests.py


示例17: test_verify_first_party_exact_caveats

 def test_verify_first_party_exact_caveats(self):
     m = Macaroon(
         location='http://mybank/',
         identifier='we used our secret key',
         key='this is our super secret key; only we should know it'
     )
     m.add_first_party_caveat('test = caveat')
     v = Verifier()
     v.satisfy_exact('test = caveat')
     verified = v.verify(
         m,
         'this is our super secret key; only we should know it'
     )
     assert_true(verified)
开发者ID:matrix-org,项目名称:pymacaroons,代码行数:14,代码来源:functional_tests.py


示例18: test_verify_failing_first_party_general_caveats

    def test_verify_failing_first_party_general_caveats(self):
        m = Macaroon(
            location='http://mybank/',
            identifier='we used our secret key',
            key='this is our super secret key; only we should know it'
        )
        m.add_first_party_caveat('general caveat')

        v = Verifier()
        v.satisfy_general(lambda _: False)
        with assert_raises(MacaroonInvalidSignatureException) as cm:
            v.verify(
                m,
                'this is our super secret key; only we should know it'
            )
开发者ID:matrix-org,项目名称:pymacaroons,代码行数:15,代码来源:functional_tests.py


示例19: test_serializing_json_v2_with_binary

 def test_serializing_json_v2_with_binary(self):
     id = base64.b64decode('AK2o+q0Aq9+bONkXw7ky7HAuhCLO9hhaMMc==')
     m = Macaroon(
         location='http://mybank/',
         identifier=id,
         key='this is our super secret key; only we should know it',
         version=MACAROON_V2
     )
     assert_equal(
         json.loads(m.serialize(serializer=JsonSerializer()))['i64'],
         "AK2o-q0Aq9-bONkXw7ky7HAuhCLO9hhaMMc"
     )
     n = Macaroon.deserialize(
         m.serialize(serializer=JsonSerializer()),
         serializer=JsonSerializer()
     )
     assert_equal(m.identifier_bytes, n.identifier_bytes)
开发者ID:ecordell,项目名称:pymacaroons,代码行数:17,代码来源:functional_tests.py


示例20: test_verify_encrypted_first_party_exact_caveats

    def test_verify_encrypted_first_party_exact_caveats(self):
        m = Macaroon(
            location='http://mybank/',
            identifier='we used our secret key',
            key='this is our super secret key; only we should know it'
        )
        m.first_party_caveat_delegate = EncryptedFirstPartyCaveatDelegate()
        m.add_first_party_caveat('test = caveat', encrypted=True)

        v = Verifier()
        v.first_party_caveat_verifier_delegate = EncryptedFirstPartyCaveatVerifierDelegate()
        v.satisfy_exact('test = caveat')
        verified = v.verify(
            m,
            'this is our super secret key; only we should know it'
        )
        assert_true(verified)
开发者ID:matrix-org,项目名称:pymacaroons,代码行数:17,代码来源:encrypted_field_tests.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numeric.Wad类代码示例发布时间:2022-05-25
下一篇:
Python pylzma.decompressobj函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap