Ejemplo n.º 1
0
def test_key_polling_worker(cmd, counter, payload, configure_environment, configure_sockets_environment,
                            detect_initial_worker_connected, connect_to_sockets_function):
    """
    Test worker behavior with agent key-polling.

    This test uses a fictional master node to test wazuh worker behavior against agent-key-polling messages. After
    connecting the worker to the simulated master, the test simulates a key-polling request message from remoted by
    sending a message to the worker local socket. Then, we ensure that the worker completed his duty by checking the
    received message in the other end, in this case, the fictional master node.

    Parameters
    ----------
    cmd : bytes
        Cluster message command
    counter : int
        Cluster message counter
    payload : bytes
        Cluster message payload data
    """
    # Build message to send to c-internal.sock in the worker and send it
    message = cluster_msg_build(cmd=cmd, counter=counter, payload=payload, encrypt=False)
    receiver_sockets[0].send(message)

    try:
        result = monitored_sockets[0].start(timeout=5, callback=callback_clusterd_keypoll).result()
        assert result['payload'] == payload, f'Received payload in the master: {result["payload"]} ' \
                                             f'does not match expected payload: {payload}'
    except TimeoutError as e:
        raise e
Ejemplo n.º 2
0
def send_initial_worker_hello(connect_to_sockets_module):
    """Send initial hello to master"""
    message = cluster_msg_build(cmd=b'hello',
                                counter=0,
                                payload=b'worker1 wazuh worker 3.12',
                                encrypt=True)
    connect_to_sockets_module[0].send(message)
    connect_to_sockets_module[0].receive()
Ejemplo n.º 3
0
 def verify_message(self, data: bytes):
     if len(data) > CLUSTER_DATA_HEADER_SIZE:
         message = data[CLUSTER_DATA_HEADER_SIZE:]
         response = cluster_msg_build(cmd=b'send_sync', counter=2, payload=bytes(self.cluster_output.encode()),
                                      encrypt=False)
         print(f'Received message from wazuh-authd: {message}')
         print(f'Response to send: {self.cluster_output}')
         self.pause()
         return response
     else:
         raise ConnectionResetError('Invalid cluster message!')
Ejemplo n.º 4
0
def test_key_polling_master(cmd, counter, payload, expected,
                            configure_environment,
                            configure_sockets_environment,
                            detect_initial_master_serving,
                            connect_to_sockets_module,
                            send_initial_worker_hello):
    """
    Test master behavior with agent key-polling.

    This test uses a fictional worker node to test wazuh master behavior against agent-key-polling messages. After
    connecting the fictional worker to the master and sending the initial hello, the test sends another worker simulated
    message representing a key-polling request. Then, we ensure that the master completed his duty by checking the
    received message in the other end, in this case, krequest socket handled by modulesd.

    Parameters
    ----------
    cmd : bytes
        Cluster message command
    counter : int
        Cluster message counter
    payload : bytes
        Cluster message payload data
    expected : str
        Expected message in krequest socket
    """
    # Build message and send it to the master
    message = cluster_msg_build(cmd=cmd,
                                counter=counter,
                                payload=payload,
                                encrypt=True)
    receiver_sockets[0].send(message)

    # Ensure krequest socket (modulesd socket for key-polling) receives the appropriate data
    result = monitored_sockets[0].start(timeout=5,
                                        callback=callback_krequest).result()

    assert result == expected