示例#1
0
文件: run.py 项目: ntoll/drogulus
def test_send_find_value_unknown(port, version, public_key, private_key):
    """
    Ensures that a "findvalue" message for a non-existent key is sent to the
    test node and the reply is checked.
    """
    item = {
        'uuid': str(uuid.uuid4()),
        'recipient': REMOTE_NODE_PUBLIC_KEY,
        'sender': public_key,
        'reply_port': 1908,
        'version': version,
        'key': sha512('an un-findable key'.encode('utf-8')).hexdigest(),
    }
    msg = seal_message('findvalue', item, private_key)
    result = send_message(port, msg)
    assert result.status_code == 200
    reply = result.json()
    assert reply['uuid'] == item['uuid']
    assert reply['sender'] == REMOTE_NODE_PUBLIC_KEY
    assert reply['recipient'] == public_key
    assert reply['message'] == 'nodes'
    assert reply['reply_port'] == port
    assert reply['version'] == version
    assert 'nodes' in reply
    assert isinstance(reply['nodes'], list)
    assert len(reply['nodes']) == 1  # the node only knows about us!
    assert 'seal' in reply
    assert check_seal(from_dict(reply))
示例#2
0
文件: run.py 项目: waseem18/drogulus
def test_send_find_value_unknown(port, version, public_key, private_key):
    """
    Ensures that a "findvalue" message for a non-existent key is sent to the
    test node and the reply is checked.
    """
    item = {
        'uuid': str(uuid.uuid4()),
        'recipient': REMOTE_NODE_PUBLIC_KEY,
        'sender': public_key,
        'reply_port': 1908,
        'version': version,
        'key': sha512('an un-findable key'.encode('utf-8')).hexdigest(),
    }
    msg = seal_message('findvalue', item, private_key)
    result = send_message(port, msg)
    assert result.status_code == 200
    reply = result.json()
    assert reply['uuid'] == item['uuid']
    assert reply['sender'] == REMOTE_NODE_PUBLIC_KEY
    assert reply['recipient'] == public_key
    assert reply['message'] == 'nodes'
    assert reply['reply_port'] == port
    assert reply['version'] == version
    assert 'nodes' in reply
    assert isinstance(reply['nodes'], list)
    assert len(reply['nodes']) == 1  # the node only knows about us!
    assert 'seal' in reply
    assert check_seal(from_dict(reply))
示例#3
0
 def test_check_seal_bad_seal(self):
     """
     Ensure a message with a bad seal (i.e. malformed junk) fails the check.
     """
     ok_dict = {
         'uuid': str(uuid.uuid4()),
         'recipient': PUBLIC_KEY,
         'sender': BAD_PUBLIC_KEY,
         'reply_port': 1908,
         'version': get_version()
     }
     seal = 'not a seal'
     ok = OK(ok_dict['uuid'], ok_dict['recipient'], ok_dict['sender'],
             ok_dict['reply_port'], ok_dict['version'], seal)
     self.assertFalse(check_seal(ok))
示例#4
0
 def test_check_seal_invalid_seal(self):
     """
     Ensure a message with an invalid seal fails the check.
     """
     ok_dict = {
         'uuid': str(uuid.uuid4()),
         'recipient': PUBLIC_KEY,
         'sender': BAD_PUBLIC_KEY,
         'reply_port': 1908,
         'version': get_version()
     }
     seal = get_seal(ok_dict, PRIVATE_KEY)
     ok = OK(ok_dict['uuid'], ok_dict['recipient'], ok_dict['sender'],
             ok_dict['reply_port'], ok_dict['version'], seal)
     self.assertFalse(check_seal(ok))
示例#5
0
 def test_check_seal_bad_seal(self):
     """
     Ensure a message with a bad seal (i.e. malformed junk) fails the check.
     """
     ok_dict = {
         'uuid': str(uuid.uuid4()),
         'recipient': PUBLIC_KEY,
         'sender': BAD_PUBLIC_KEY,
         'reply_port': 1908,
         'version': get_version()
     }
     seal = 'not a seal'
     ok = OK(ok_dict['uuid'], ok_dict['recipient'], ok_dict['sender'],
             ok_dict['reply_port'], ok_dict['version'], seal)
     self.assertFalse(check_seal(ok))
示例#6
0
 def test_check_seal_invalid_seal(self):
     """
     Ensure a message with an invalid seal fails the check.
     """
     ok_dict = {
         'uuid': str(uuid.uuid4()),
         'recipient': PUBLIC_KEY,
         'sender': BAD_PUBLIC_KEY,
         'reply_port': 1908,
         'version': get_version()
     }
     seal = get_seal(ok_dict, PRIVATE_KEY)
     ok = OK(ok_dict['uuid'], ok_dict['recipient'], ok_dict['sender'],
             ok_dict['reply_port'], ok_dict['version'], seal)
     self.assertFalse(check_seal(ok))
示例#7
0
 def test_check_seal(self):
     """
     Make sure message objects that contain a valid seal are correctly
     checked.
     """
     ok_dict = {
         'uuid': str(uuid.uuid4()),
         'recipient': PUBLIC_KEY,
         'sender': PUBLIC_KEY,
         'reply_port': 1908,
         'version': get_version()
     }
     seal = get_seal(ok_dict, PRIVATE_KEY)
     ok = OK(ok_dict['uuid'], ok_dict['recipient'], ok_dict['sender'],
             ok_dict['reply_port'], ok_dict['version'], seal)
     self.assertTrue(check_seal(ok))
示例#8
0
 def test_check_seal_bad_seal(self):
     """
     Ensure a message with a bad seal (i.e. malformed junk) fails the check.
     """
     ok_dict = {
         "uuid": str(uuid.uuid4()),
         "recipient": PUBLIC_KEY,
         "sender": BAD_PUBLIC_KEY,
         "reply_port": 1908,
         "version": get_version(),
     }
     seal = "not a seal"
     ok = OK(
         ok_dict["uuid"], ok_dict["recipient"], ok_dict["sender"], ok_dict["reply_port"], ok_dict["version"], seal
     )
     self.assertFalse(check_seal(ok))
示例#9
0
 def test_check_seal_invalid_seal(self):
     """
     Ensure a message with an invalid seal fails the check.
     """
     ok_dict = {
         "uuid": str(uuid.uuid4()),
         "recipient": PUBLIC_KEY,
         "sender": BAD_PUBLIC_KEY,
         "reply_port": 1908,
         "version": get_version(),
     }
     seal = get_seal(ok_dict, PRIVATE_KEY)
     ok = OK(
         ok_dict["uuid"], ok_dict["recipient"], ok_dict["sender"], ok_dict["reply_port"], ok_dict["version"], seal
     )
     self.assertFalse(check_seal(ok))
示例#10
0
 def test_check_seal(self):
     """
     Make sure message objects that contain a valid seal are correctly
     checked.
     """
     ok_dict = {
         'uuid': str(uuid.uuid4()),
         'recipient': PUBLIC_KEY,
         'sender': PUBLIC_KEY,
         'reply_port': 1908,
         'version': get_version()
     }
     seal = get_seal(ok_dict, PRIVATE_KEY)
     ok = OK(ok_dict['uuid'], ok_dict['recipient'], ok_dict['sender'],
             ok_dict['reply_port'], ok_dict['version'], seal)
     self.assertTrue(check_seal(ok))
示例#11
0
 def test_check_seal(self):
     """
     Make sure message objects that contain a valid seal are correctly
     checked.
     """
     ok_dict = {
         "uuid": str(uuid.uuid4()),
         "recipient": PUBLIC_KEY,
         "sender": PUBLIC_KEY,
         "reply_port": 1908,
         "version": get_version(),
     }
     seal = get_seal(ok_dict, PRIVATE_KEY)
     ok = OK(
         ok_dict["uuid"], ok_dict["recipient"], ok_dict["sender"], ok_dict["reply_port"], ok_dict["version"], seal
     )
     self.assertTrue(check_seal(ok))
示例#12
0
文件: run.py 项目: waseem18/drogulus
def test_send_find_value_known(port, version, public_key, private_key):
    """
    Ensures that a "findvalue" message for an existing key is sent to the
    test node and the reply is checked.
    """
    item = get_signed_item('item_name', "the item's value", public_key,
                           private_key)
    signature = item['signature']
    item['uuid'] = str(uuid4())
    item['recipient'] = REMOTE_NODE_PUBLIC_KEY
    item['sender'] = public_key
    item['reply_port'] = 1908
    item['version'] = version
    msg = seal_message('store', item, private_key)
    result = send_message(port, msg)
    assert result.status_code == 200
    item = {
        'uuid': str(uuid.uuid4()),
        'recipient': REMOTE_NODE_PUBLIC_KEY,
        'sender': public_key,
        'reply_port': 1908,
        'version': version,
        'key': construct_key(public_key, 'item_name'),
    }
    msg = seal_message('findvalue', item, private_key)
    result = send_message(port, msg)
    assert result.status_code == 200
    reply = result.json()
    assert reply['uuid'] == item['uuid']
    assert reply['sender'] == REMOTE_NODE_PUBLIC_KEY
    assert reply['recipient'] == public_key
    assert reply['message'] == 'value'
    assert reply['reply_port'] == port
    assert reply['version'] == version
    assert reply['name'] == 'item_name'
    assert reply['value'] == "the item's value"
    assert reply['key'] == construct_key(public_key, 'item_name')
    assert reply['public_key'] == public_key
    assert reply['signature'] == signature
    assert reply['expires'] == 0.0
    assert reply['created_with'] == version
    assert isinstance(reply['timestamp'], float)
    assert 'seal' in reply
    assert check_seal(from_dict(reply))
示例#13
0
文件: run.py 项目: ntoll/drogulus
def test_send_find_value_known(port, version, public_key, private_key):
    """
    Ensures that a "findvalue" message for an existing key is sent to the
    test node and the reply is checked.
    """
    item = get_signed_item('item_name', "the item's value", public_key,
                           private_key)
    signature = item['signature']
    item['uuid'] = str(uuid4())
    item['recipient'] = REMOTE_NODE_PUBLIC_KEY
    item['sender'] = public_key
    item['reply_port'] = 1908
    item['version'] = version
    msg = seal_message('store', item, private_key)
    result = send_message(port, msg)
    assert result.status_code == 200
    item = {
        'uuid': str(uuid.uuid4()),
        'recipient': REMOTE_NODE_PUBLIC_KEY,
        'sender': public_key,
        'reply_port': 1908,
        'version': version,
        'key': construct_key(public_key, 'item_name'),
    }
    msg = seal_message('findvalue', item, private_key)
    result = send_message(port, msg)
    assert result.status_code == 200
    reply = result.json()
    assert reply['uuid'] == item['uuid']
    assert reply['sender'] == REMOTE_NODE_PUBLIC_KEY
    assert reply['recipient'] == public_key
    assert reply['message'] == 'value'
    assert reply['reply_port'] == port
    assert reply['version'] == version
    assert reply['name'] == 'item_name'
    assert reply['value'] == "the item's value"
    assert reply['key'] == construct_key(public_key, 'item_name')
    assert reply['public_key'] == public_key
    assert reply['signature'] == signature
    assert reply['expires'] == 0.0
    assert reply['created_with'] == version
    assert isinstance(reply['timestamp'], float)
    assert 'seal' in reply
    assert check_seal(from_dict(reply))
示例#14
0
文件: run.py 项目: waseem18/drogulus
def test_send_store(port, version, public_key, private_key):
    """
    Sends and "store" message to the test node and check's the reply.
    """
    item = get_signed_item('item_name', "the item's value", public_key,
                           private_key)
    item['uuid'] = str(uuid4())
    item['recipient'] = REMOTE_NODE_PUBLIC_KEY
    item['sender'] = public_key
    item['reply_port'] = 1908
    item['version'] = version
    msg = seal_message('store', item, private_key)
    result = send_message(port, msg)
    assert result.status_code == 200
    reply = result.json()
    assert reply['uuid'] == item['uuid']
    assert reply['sender'] == REMOTE_NODE_PUBLIC_KEY
    assert reply['recipient'] == public_key
    assert reply['message'] == 'ok'
    assert reply['reply_port'] == port
    assert reply['version'] == version
    assert 'seal' in reply
    assert check_seal(from_dict(reply))
示例#15
0
文件: run.py 项目: ntoll/drogulus
def test_send_store(port, version, public_key, private_key):
    """
    Sends and "store" message to the test node and check's the reply.
    """
    item = get_signed_item('item_name', "the item's value", public_key,
                           private_key)
    item['uuid'] = str(uuid4())
    item['recipient'] = REMOTE_NODE_PUBLIC_KEY
    item['sender'] = public_key
    item['reply_port'] = 1908
    item['version'] = version
    msg = seal_message('store', item, private_key)
    result = send_message(port, msg)
    assert result.status_code == 200
    reply = result.json()
    assert reply['uuid'] == item['uuid']
    assert reply['sender'] == REMOTE_NODE_PUBLIC_KEY
    assert reply['recipient'] == public_key
    assert reply['message'] == 'ok'
    assert reply['reply_port'] == port
    assert reply['version'] == version
    assert 'seal' in reply
    assert check_seal(from_dict(reply))