2023-09-06 22:01:51 +01:00
|
|
|
from ipaddress import IPv4Address
|
2023-08-29 13:21:34 +01:00
|
|
|
|
2023-09-06 22:01:51 +01:00
|
|
|
from primaite.simulator.network.hardware.nodes.computer import Computer
|
|
|
|
|
from primaite.simulator.network.networks import arcd_uc2_network
|
2023-09-06 22:26:23 +01:00
|
|
|
from primaite.simulator.network.transmission.data_link_layer import EthernetHeader, Frame
|
2023-09-06 22:01:51 +01:00
|
|
|
from primaite.simulator.network.transmission.network_layer import IPPacket, Precedence
|
2023-09-06 22:26:23 +01:00
|
|
|
from primaite.simulator.network.transmission.transport_layer import Port, TCPHeader
|
2023-08-29 13:21:34 +01:00
|
|
|
|
2023-08-29 14:15:49 +01:00
|
|
|
|
2023-09-06 22:01:51 +01:00
|
|
|
def test_database_query_across_the_network():
|
|
|
|
|
"""Tests DB query across the network returns HTTP status 200 and date."""
|
|
|
|
|
network = arcd_uc2_network()
|
2023-08-29 14:15:49 +01:00
|
|
|
|
2023-09-06 22:01:51 +01:00
|
|
|
client_1: Computer = network.get_node_by_hostname("client_1")
|
2023-08-29 14:15:49 +01:00
|
|
|
|
2023-09-06 22:01:51 +01:00
|
|
|
client_1.arp.send_arp_request(IPv4Address("192.168.1.14"))
|
2023-08-29 14:15:49 +01:00
|
|
|
|
2023-09-06 22:01:51 +01:00
|
|
|
dst_mac_address = client_1.arp.get_arp_cache_mac_address(IPv4Address("192.168.1.14"))
|
|
|
|
|
|
|
|
|
|
outbound_nic = client_1.arp.get_arp_cache_nic(IPv4Address("192.168.1.14"))
|
|
|
|
|
client_1.ping("192.168.1.14")
|
2023-08-29 14:15:49 +01:00
|
|
|
|
2023-09-06 22:01:51 +01:00
|
|
|
frame = Frame(
|
2023-09-06 22:26:23 +01:00
|
|
|
ethernet=EthernetHeader(src_mac_addr=client_1.ethernet_port[1].mac_address, dst_mac_addr=dst_mac_address),
|
2023-09-06 22:01:51 +01:00
|
|
|
ip=IPPacket(
|
|
|
|
|
src_ip_address=client_1.ethernet_port[1].ip_address,
|
|
|
|
|
dst_ip_address=IPv4Address("192.168.1.14"),
|
2023-09-06 22:26:23 +01:00
|
|
|
precedence=Precedence.FLASH,
|
2023-09-06 22:01:51 +01:00
|
|
|
),
|
2023-09-06 22:26:23 +01:00
|
|
|
tcp=TCPHeader(src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER),
|
|
|
|
|
payload="SELECT * FROM user;",
|
2023-09-06 22:01:51 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
outbound_nic.send_frame(frame)
|
2023-08-29 14:15:49 +01:00
|
|
|
|
2023-09-06 22:01:51 +01:00
|
|
|
client_1_last_payload = outbound_nic.pcap.read()[-1]["payload"]
|
2023-08-29 14:15:49 +01:00
|
|
|
|
2023-09-06 22:01:51 +01:00
|
|
|
assert client_1_last_payload["status_code"] == 200
|
2023-09-06 22:26:23 +01:00
|
|
|
assert client_1_last_payload["data"]
|