Skip to content

Commit

Permalink
Implement test for audit ticket MUL-02-002 WP2
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Mar 28, 2024
1 parent 6c58ebc commit 6a7b621
Show file tree
Hide file tree
Showing 5 changed files with 554 additions and 4 deletions.
6 changes: 4 additions & 2 deletions test/connection-checker/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::{

use crate::cli::Opt;

const PAYLOAD: &[u8] = b"Hello there!";

pub fn send_tcp(opt: &Opt, destination: SocketAddr) -> eyre::Result<()> {
let bind_addr: SocketAddr = SocketAddr::new(Ipv4Addr::new(0, 0, 0, 0).into(), 0);

Expand All @@ -31,7 +33,7 @@ pub fn send_tcp(opt: &Opt, destination: SocketAddr) -> eyre::Result<()> {

let mut stream = std::net::TcpStream::from(sock);
stream
.write_all(b"hello there")
.write_all(PAYLOAD)
.wrap_err(eyre!("Failed to send message to {destination}"))?;

Ok(())
Expand All @@ -56,7 +58,7 @@ pub fn send_udp(_opt: &Opt, destination: SocketAddr) -> Result<(), eyre::Error>

let std_socket = std::net::UdpSocket::from(sock);
std_socket
.send_to(b"Hello there!", destination)
.send_to(PAYLOAD, destination)
.wrap_err(eyre!("Failed to send message to {destination}"))?;

Ok(())
Expand Down
10 changes: 9 additions & 1 deletion test/test-manager/src/network_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct ParsedPacket {
pub source: SocketAddr,
pub destination: SocketAddr,
pub protocol: IpNextHeaderProtocol,
pub payload: Vec<u8>,
}

impl PacketCodec for Codec {
Expand Down Expand Up @@ -75,9 +76,9 @@ impl Codec {

let mut source = SocketAddr::new(IpAddr::V4(packet.get_source()), 0);
let mut destination = SocketAddr::new(IpAddr::V4(packet.get_destination()), 0);
let mut payload = vec![];

let protocol = packet.get_next_level_protocol();

match protocol {
IpHeaderProtocols::Tcp => {
let seg = TcpPacket::new(packet.payload()).or_else(|| {
Expand All @@ -86,6 +87,7 @@ impl Codec {
})?;
source.set_port(seg.get_source());
destination.set_port(seg.get_destination());
payload = seg.payload().to_vec();
}
IpHeaderProtocols::Udp => {
let seg = UdpPacket::new(packet.payload()).or_else(|| {
Expand All @@ -94,6 +96,7 @@ impl Codec {
})?;
source.set_port(seg.get_source());
destination.set_port(seg.get_destination());
payload = seg.payload().to_vec();
}
IpHeaderProtocols::Icmp => {}
proto => log::debug!("ignoring v4 packet, transport/protocol type {proto}"),
Expand All @@ -103,6 +106,7 @@ impl Codec {
source,
destination,
protocol,
payload,
})
}

Expand All @@ -114,6 +118,7 @@ impl Codec {

let mut source = SocketAddr::new(IpAddr::V6(packet.get_source()), 0);
let mut destination = SocketAddr::new(IpAddr::V6(packet.get_destination()), 0);
let mut payload = vec![];

let protocol = packet.get_next_header();
match protocol {
Expand All @@ -124,6 +129,7 @@ impl Codec {
})?;
source.set_port(seg.get_source());
destination.set_port(seg.get_destination());
payload = seg.payload().to_vec();
}
IpHeaderProtocols::Udp => {
let seg = UdpPacket::new(packet.payload()).or_else(|| {
Expand All @@ -132,6 +138,7 @@ impl Codec {
})?;
source.set_port(seg.get_source());
destination.set_port(seg.get_destination());
payload = seg.payload().to_vec();
}
IpHeaderProtocols::Icmpv6 => {}
proto => log::debug!("ignoring v6 packet, transport/protocol type {proto}"),
Expand All @@ -141,6 +148,7 @@ impl Codec {
source,
destination,
protocol,
payload,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions test/test-manager/src/tests/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ pub async fn test_installation_idempotency(
// Connect to any relay. This forces the daemon to enter a secured target state
connect_and_wait(&mut mullvad_client)
.await
.map(|_| ()) // Discard the new tunnel state
.or_else(|error| match error {
Error::UnexpectedErrorState(_) => Ok(()),
err => Err(err),
Expand Down
Loading

0 comments on commit 6a7b621

Please sign in to comment.