def test_tools_error(self):
     c_nodes = message._compact_nodes(tc.NODES)
     # Compact nodes is one byte short
     assert_raises(MsgError, message._uncompact_nodes, c_nodes[:-1])
     # IP size is weird
     assert_raises(MsgError, bin_to_ip, "123")
     # Port is 0 (
     eq_(message._uncompact_nodes(c_nodes), tc.NODES)
     n = tc.NODES[0]
     tc.NODES[0] = node.Node((n.addr[0], 0), n.id)
     c_nodes = message._compact_nodes(tc.NODES)
     eq_(message._uncompact_nodes(c_nodes), tc.NODES[1:])
     c_nodes2 = message._compact_nodes2(tc.NODES)
     eq_(message._uncompact_nodes2(c_nodes2), tc.NODES[1:])
     tc.NODES[0] = n
Beispiel #2
0
 def test_tools_error(self):
     c_nodes = message._compact_nodes(tc.NODES)
     # Compact nodes is one byte short
     assert_raises(MsgError, message._uncompact_nodes, c_nodes[:-1])
     # IP size is weird
     assert_raises(MsgError, bin_to_ip, '123')
     # Port is 0 (
     eq_(message._uncompact_nodes(c_nodes), tc.NODES)
     n = tc.NODES[0]
     tc.NODES[0] = node.Node((n.addr[0], 0), n.id)
     c_nodes = message._compact_nodes(tc.NODES)
     eq_(message._uncompact_nodes(c_nodes), tc.NODES[1:])
     c_nodes2 = message._compact_nodes2(tc.NODES)
     eq_(message._uncompact_nodes2(c_nodes2), tc.NODES[1:])
     tc.NODES[0] = n
    def test_sanitize(self):
        self.ping_r.sanitize_response(PING)

        del self.fn2_r._msg_dict[RESPONSE][NODES2]
        # No NODES and no NODES2
        assert_raises(MsgError, self.fn2_r.sanitize_response, FIND_NODE)
        self.fn2_r._msg_dict[RESPONSE][NODES] = message._compact_nodes(tc.NODES)
        # Just NODES
        self.fn2_r.sanitize_response(FIND_NODE)
        self.fn2_r._msg_dict[RESPONSE][NODES2] = message._compact_nodes2(tc.NODES)
        # Both NODES and NODES2
        self.fn2_r.sanitize_response(FIND_NODE)

        # Both NODES and PEERS in response
        self.gp_r._msg_dict[RESPONSE][NODES] = message._compact_nodes(tc.NODES)
        self.gp_r.sanitize_response(GET_PEERS)
        # No NODES and no PEERS
        del self.gp_r._msg_dict[RESPONSE][NODES]
        del self.gp_r._msg_dict[RESPONSE][VALUES]
        assert_raises(MsgError, self.gp_r.sanitize_response, GET_PEERS)
Beispiel #4
0
    def test_sanitize(self):
        self.ping_r.sanitize_response(PING)

        del self.fn2_r._msg_dict[RESPONSE][NODES2]
        # No NODES and no NODES2
        assert_raises(MsgError, self.fn2_r.sanitize_response, FIND_NODE)
        self.fn2_r._msg_dict[RESPONSE][NODES] = \
            message._compact_nodes(tc.NODES)
        # Just NODES
        self.fn2_r.sanitize_response(FIND_NODE)
        self.fn2_r._msg_dict[RESPONSE][NODES2] = \
            message._compact_nodes2(tc.NODES)
        # Both NODES and NODES2
        self.fn2_r.sanitize_response(FIND_NODE)

        # Both NODES and PEERS in response
        self.gp_r._msg_dict[RESPONSE][NODES] = \
            message._compact_nodes(tc.NODES)
        self.gp_r.sanitize_response(GET_PEERS)
        # No NODES and no PEERS
        del self.gp_r._msg_dict[RESPONSE][NODES]
        del self.gp_r._msg_dict[RESPONSE][VALUES]
        assert_raises(MsgError, self.gp_r.sanitize_response, GET_PEERS)