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


Python pymacaroons.Macaroon类代码示例

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


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


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