2017-12-10 01:21:43 +00:00
|
|
|
import datetime
|
|
|
|
|
|
|
|
from nkms.crypto.api import keccak_digest
|
|
|
|
from tests.utilities import MockNetworkyStuff
|
|
|
|
|
|
|
|
|
|
|
|
def test_grant(alice, bob, ursulas):
|
|
|
|
networky_stuff = MockNetworkyStuff(ursulas)
|
|
|
|
policy_end_datetime = datetime.datetime.now() + datetime.timedelta(days=5)
|
|
|
|
n = 5
|
|
|
|
uri = b"this_is_the_path_to_which_access_is_being_granted"
|
2017-12-15 04:36:35 +00:00
|
|
|
policy = alice.grant(bob, uri, networky_stuff, m=3, n=n,
|
2017-12-10 01:21:43 +00:00
|
|
|
expiration=policy_end_datetime)
|
|
|
|
|
|
|
|
# The number of policies is equal to the number of Ursulas we're using (n)
|
2017-12-15 04:36:35 +00:00
|
|
|
assert len(policy._active_contracts) == n
|
2017-12-10 01:21:43 +00:00
|
|
|
|
|
|
|
# Let's look at the first Ursula.
|
2017-12-15 04:36:35 +00:00
|
|
|
ursula = list(policy._active_contracts.values())[0].ursula
|
2017-12-10 01:21:43 +00:00
|
|
|
|
|
|
|
# Get the kfrag, based in the hrac.
|
|
|
|
proper_hrac = keccak_digest(bytes(alice.seal) + bytes(bob.seal) + uri)
|
|
|
|
kfrag_that_was_set = ursula.keystore.get_kfrag(proper_hrac)
|
|
|
|
assert kfrag_that_was_set
|