本文整理汇总了Python中pymacaroons.Macaroon.add_first_party_caveat方法的典型用法代码示例。如果您正苦于以下问题:Python Macaroon.add_first_party_caveat方法的具体用法?Python Macaroon.add_first_party_caveat怎么用?Python Macaroon.add_first_party_caveat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymacaroons.Macaroon
的用法示例。
在下文中一共展示了Macaroon.add_first_party_caveat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_macaroon
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [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
示例2: test_serializing_max_length_packet
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [as 别名]
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
)
示例3: test_serializing_too_long_packet
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [as 别名]
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
)
示例4: test_verify_third_party_caveats
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [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)
示例5: test_prepare_for_request
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [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'
)
示例6: test_inspect
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [as 别名]
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')
示例7: test_serializing_json
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [as 别名]
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"
)
示例8: test_serializing_v2
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [as 别名]
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)
示例9: test_serializing_json_v2
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [as 别名]
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"
)
示例10: test_serializing_deserializing_json
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [as 别名]
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)
示例11: test_serializing_with_binary_v2
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [as 别名]
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)
示例12: test_serializing
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [as 别名]
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'
)
示例13: test_encrypted_first_party_caveat
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [as 别名]
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'
)
示例14: test_serializing_strips_padding
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [as 别名]
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')
)
示例15: test_verify_first_party_exact_caveats
# 需要导入模块: from pymacaroons import Macaroon [as 别名]
# 或者: from pymacaroons.Macaroon import add_first_party_caveat [as 别名]
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)