Skip to content

Commit

Permalink
fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenctl committed Feb 5, 2024
1 parent 158748a commit 7f2ea1a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
12 changes: 3 additions & 9 deletions src/proxy/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,19 +623,13 @@ mod test {
};
let from_gw_conn = Connection {
src_identity: Some(gateawy_id),
src: SocketAddr::V4(SocketAddrV4::new(
IpAddr::V4(mock_default_gateway_ipaddr()),
9999,
)),
src: SocketAddr::V4(SocketAddrV4::new(mock_default_gateway_ipaddr(), 9999)),
dst_network: "default".to_string(),
dst: SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 10), 80)),
};
let not_from_gw_conn = Connection {
src_identity: Some(Identity::default()),
src: SocketAddr::V4(SocketAddrV4::new(
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
9999,
)),
src: SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 9999)),
dst_network: "default".to_string(),
dst: SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 10), 80)),
};
Expand Down Expand Up @@ -741,7 +735,7 @@ mod test {
hostname: "gateway".to_string(),
vips,
ports,
waypoints,
waypoints: Default::default(),
endpoints,
subject_alt_names: vec![],
}
Expand Down
23 changes: 12 additions & 11 deletions src/rbac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ impl From<&XdsStringMatch> for Option<StringMatch> {
#[cfg(test)]
mod tests {
use test_case::test_case;
use std::net::IpAddr;

use super::*;

Expand Down Expand Up @@ -440,7 +441,7 @@ mod tests {
fn plaintext_conn() -> Connection {
Connection {
src_identity: None,
src: IpAddr::from([127, 0, 0, 1]),
src: SocketAddr::new(IpAddr::from([127, 0, 0, 1]), 9999),
dst_network: "".to_string(),
dst: "127.0.0.2:8080".parse().unwrap(),
}
Expand All @@ -453,7 +454,7 @@ mod tests {
namespace: "namespace".to_string(),
service_account: "account".to_string(),
}),
src: IpAddr::from([127, 0, 0, 1]),
src: SocketAddr::new(IpAddr::from([127, 0, 0, 1]), 9999),
dst_network: "".to_string(),
dst: "127.0.0.2:8080".parse().unwrap(),
}
Expand All @@ -466,7 +467,7 @@ mod tests {
namespace: "ns-alt".to_string(),
service_account: "sa=alt".to_string(),
}),
src: IpAddr::from([127, 0, 0, 3]),
src: SocketAddr::new(IpAddr::from([127, 0, 0, 3]), 9999),
dst_network: "".to_string(),
dst: "127.0.0.4:9090".parse().unwrap(),
}
Expand Down Expand Up @@ -514,7 +515,7 @@ mod tests {
namespace: "a".to_string(),
service_account: "account".to_string(),
}),
src: IpAddr::from([127, 0, 0, 1]),
src: SocketAddr::new(IpAddr::from([127, 0, 0, 1]), 9999),
dst_network: "".to_string(),
dst: "127.0.0.2:80".parse().unwrap(),
}));
Expand All @@ -524,7 +525,7 @@ mod tests {
namespace: "b".to_string(),
service_account: "account".to_string(),
}),
src: IpAddr::from([127, 0, 0, 1]),
src: SocketAddr::new(IpAddr::from([127, 0, 0, 1]), 9999),
dst_network: "".to_string(),
dst: "127.0.0.2:80".parse().unwrap(),
}));
Expand All @@ -535,7 +536,7 @@ mod tests {
namespace: "b".to_string(),
service_account: "account".to_string(),
}),
src: IpAddr::from([127, 0, 0, 1]),
src: SocketAddr::new(IpAddr::from([127, 0, 0, 1]), 9999),
dst_network: "remote".to_string(),
dst: "127.0.0.2:80".parse().unwrap(),
}));
Expand All @@ -546,7 +547,7 @@ mod tests {
namespace: "bad".to_string(),
service_account: "account".to_string(),
}),
src: IpAddr::from([127, 0, 0, 1]),
src: SocketAddr::new(IpAddr::from([127, 0, 0, 1]), 9999),
dst_network: "".to_string(),
dst: "127.0.0.2:80".parse().unwrap(),
}));
Expand All @@ -557,7 +558,7 @@ mod tests {
namespace: "b".to_string(),
service_account: "account".to_string(),
}),
src: IpAddr::from([127, 0, 0, 1]),
src: SocketAddr::new(IpAddr::from([127, 0, 0, 1]), 9999),
dst_network: "".to_string(),
dst: "127.0.0.2:12345".parse().unwrap(),
}));
Expand Down Expand Up @@ -585,7 +586,7 @@ mod tests {
namespace: "a".to_string(),
service_account: "account".to_string(),
}),
src: IpAddr::from([127, 0, 0, 1]),
src: SocketAddr::new(IpAddr::from([127, 0, 0, 1]), 9999),
dst_network: "".to_string(),
dst: "127.0.0.2:80".parse().unwrap(),
}));
Expand All @@ -595,7 +596,7 @@ mod tests {
namespace: "b".to_string(),
service_account: "account".to_string(),
}),
src: IpAddr::from([127, 0, 0, 1]),
src: SocketAddr::new(IpAddr::from([127, 0, 0, 1]), 9999),
dst_network: "".to_string(),
dst: "127.0.0.2:80".parse().unwrap(),
}));
Expand All @@ -606,7 +607,7 @@ mod tests {
namespace: "bad".to_string(),
service_account: "account".to_string(),
}),
src: IpAddr::from([127, 0, 0, 1]),
src: SocketAddr::new(IpAddr::from([127, 0, 0, 1]), 9999),
dst_network: "".to_string(),
dst: "127.0.0.2:80".parse().unwrap(),
}));
Expand Down
5 changes: 3 additions & 2 deletions src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ pub fn mock_default_service() -> Service {
let vips = vec![vip1];
let mut ports = HashMap::new();
ports.insert(8080, 80);
let endpoints = HashMap::new();
Service {
name: "".to_string(),
namespace: "default".to_string(),
hostname: "defaulthost".to_string(),
vips,
ports,
endpoints,
endpoints: Default::default(),
waypoints: Default:: default(),
subject_alt_names: vec![],
}
}
Expand Down Expand Up @@ -287,6 +287,7 @@ fn test_custom_svc(
port: HashMap::from([(80u16, echo_port)]),
},
)]),
waypoints: Default::default(),
subject_alt_names: vec!["spiffe://cluster.local/ns/default/sa/default".to_string()],
})
}
Expand Down
2 changes: 2 additions & 0 deletions src/test_helpers/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ impl<'a> TestServiceBuilder<'a> {
vips: vec![],
ports: Default::default(),
endpoints: Default::default(), // populated later when workloads are added
waypoints: Default::default(), // populated later when workloads are added
subject_alt_names: vec![],
},
manager,
Expand Down Expand Up @@ -345,6 +346,7 @@ impl<'a> TestWorkloadBuilder<'a> {
let mut svc = self.manager.services.get(&service_name).unwrap().clone();
let ep_uid = endpoint_uid(&self.w.workload.uid, Some(&ep_network_addr));
svc.endpoints.insert(ep_uid, ep.clone());
svc.insert_waypoint(&self.w.workload);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/xds/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ mod tests {
let conn = crate::rbac::Connection{
dst: std::net::SocketAddr::new(std::net::Ipv4Addr::new(1, 2, 3, 4).into(), 80),
src_identity: None,
src: std::net::Ipv4Addr::new(1, 2,3, 5).into(),
src: std::net::SocketAddr::new(std::net::Ipv4Addr::new(1, 2,3, 5).into(), 9999),
dst_network: "".to_string(),
};
// rbac should reject port 80
Expand Down

0 comments on commit 7f2ea1a

Please sign in to comment.