mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
@@ -101,8 +101,9 @@ mod test {
|
||||
use super::*;
|
||||
use chrono::DateTime;
|
||||
use connlib_shared::messages::{
|
||||
client::ResourceDescriptionCidr, client::ResourceDescriptionDns, DnsServer, IpDnsServer,
|
||||
Stun, Turn,
|
||||
client::ResourceDescriptionCidr,
|
||||
client::{GatewayGroup, ResourceDescriptionDns},
|
||||
DnsServer, IpDnsServer, Stun, Turn,
|
||||
};
|
||||
use phoenix_channel::{OutboundRequestId, PhoenixMessage};
|
||||
|
||||
@@ -232,11 +233,21 @@ mod test {
|
||||
id: "73037362-715d-4a83-a749-f18eadd970e6".parse().unwrap(),
|
||||
address: "172.172.0.0/16".parse().unwrap(),
|
||||
name: "172.172.0.0/16".to_string(),
|
||||
address_description: "cidr resource".to_string(),
|
||||
gateway_groups: vec![GatewayGroup {
|
||||
name: "test".to_string(),
|
||||
id: "bf56f32d-7b2c-4f5d-a784-788977d014a4".parse().unwrap(),
|
||||
}],
|
||||
}),
|
||||
ResourceDescription::Dns(ResourceDescriptionDns {
|
||||
id: "03000143-e25e-45c7-aafb-144990e57dcd".parse().unwrap(),
|
||||
address: "gitlab.mycorp.com".to_string(),
|
||||
name: "gitlab.mycorp.com".to_string(),
|
||||
address_description: "dns resource".to_string(),
|
||||
gateway_groups: vec![GatewayGroup {
|
||||
name: "test".to_string(),
|
||||
id: "bf56f32d-7b2c-4f5d-a784-788977d014a4".parse().unwrap(),
|
||||
}],
|
||||
}),
|
||||
],
|
||||
relays: vec![],
|
||||
@@ -256,6 +267,8 @@ mod test {
|
||||
"address": "172.172.0.0/16",
|
||||
"id": "73037362-715d-4a83-a749-f18eadd970e6",
|
||||
"name": "172.172.0.0/16",
|
||||
"address_description": "cidr resource",
|
||||
"gateway_groups": [{"name": "test", "id": "bf56f32d-7b2c-4f5d-a784-788977d014a4"}],
|
||||
"type": "cidr"
|
||||
},
|
||||
{
|
||||
@@ -264,6 +277,8 @@ mod test {
|
||||
"ipv4": "100.126.44.50",
|
||||
"ipv6": "fd00:2021:1111::e:7758",
|
||||
"name": "gitlab.mycorp.com",
|
||||
"address_description": "dns resource",
|
||||
"gateway_groups": [{"name": "test", "id": "bf56f32d-7b2c-4f5d-a784-788977d014a4"}],
|
||||
"type": "dns"
|
||||
}
|
||||
]
|
||||
@@ -291,11 +306,21 @@ mod test {
|
||||
id: "73037362-715d-4a83-a749-f18eadd970e6".parse().unwrap(),
|
||||
address: "172.172.0.0/16".parse().unwrap(),
|
||||
name: "172.172.0.0/16".to_string(),
|
||||
address_description: "cidr resource".to_string(),
|
||||
gateway_groups: vec![GatewayGroup {
|
||||
name: "test".to_string(),
|
||||
id: "bf56f32d-7b2c-4f5d-a784-788977d014a4".parse().unwrap(),
|
||||
}],
|
||||
}),
|
||||
ResourceDescription::Dns(ResourceDescriptionDns {
|
||||
id: "03000143-e25e-45c7-aafb-144990e57dcd".parse().unwrap(),
|
||||
address: "gitlab.mycorp.com".to_string(),
|
||||
name: "gitlab.mycorp.com".to_string(),
|
||||
address_description: "dns resource".to_string(),
|
||||
gateway_groups: vec![GatewayGroup {
|
||||
name: "test".to_string(),
|
||||
id: "bf56f32d-7b2c-4f5d-a784-788977d014a4".parse().unwrap(),
|
||||
}],
|
||||
}),
|
||||
],
|
||||
relays: vec![],
|
||||
@@ -317,6 +342,8 @@ mod test {
|
||||
"id": "73037362-715d-4a83-a749-f18eadd970e6",
|
||||
"name": "172.172.0.0/16",
|
||||
"type": "cidr",
|
||||
"address_description": "cidr resource",
|
||||
"gateway_groups": [{"name": "test", "id": "bf56f32d-7b2c-4f5d-a784-788977d014a4"}],
|
||||
"not": "relevant"
|
||||
},
|
||||
{
|
||||
@@ -326,6 +353,8 @@ mod test {
|
||||
"ipv6": "fd00:2021:1111::e:7758",
|
||||
"name": "gitlab.mycorp.com",
|
||||
"type": "dns",
|
||||
"address_description": "dns resource",
|
||||
"gateway_groups": [{"name": "test", "id": "bf56f32d-7b2c-4f5d-a784-788977d014a4"}],
|
||||
"not": "relevant"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -313,13 +313,22 @@ mod tests {
|
||||
|
||||
use itertools::Itertools;
|
||||
|
||||
use super::{client::ResourceDescription, client::ResourceDescriptionDns, ResourceId};
|
||||
use super::{
|
||||
client::ResourceDescription,
|
||||
client::{GatewayGroup, ResourceDescriptionDns},
|
||||
ResourceId,
|
||||
};
|
||||
|
||||
fn fake_resource(name: &str, uuid: &str) -> ResourceDescription {
|
||||
ResourceDescription::Dns(ResourceDescriptionDns {
|
||||
id: ResourceId::from_str(uuid).unwrap(),
|
||||
name: name.to_string(),
|
||||
address: "unused.example.com".to_string(),
|
||||
address_description: "test description".to_string(),
|
||||
gateway_groups: vec![GatewayGroup {
|
||||
name: "test".to_string(),
|
||||
id: "99ba0c1e-5189-4cfc-a4db-fd6cb1c937fd".parse().unwrap(),
|
||||
}],
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
//! Client related messages that are needed within connlib
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::{borrow::Cow, str::FromStr};
|
||||
|
||||
use ip_network::IpNetwork;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::ResourceId;
|
||||
|
||||
@@ -18,6 +19,9 @@ pub struct ResourceDescriptionDns {
|
||||
///
|
||||
/// Used only for display.
|
||||
pub name: String,
|
||||
|
||||
pub address_description: String,
|
||||
pub gateway_groups: Vec<GatewayGroup>,
|
||||
}
|
||||
|
||||
/// Description of a resource that maps to a CIDR.
|
||||
@@ -31,6 +35,33 @@ pub struct ResourceDescriptionCidr {
|
||||
///
|
||||
/// Used only for display.
|
||||
pub name: String,
|
||||
|
||||
pub address_description: String,
|
||||
pub gateway_groups: Vec<GatewayGroup>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct GatewayGroup {
|
||||
pub name: String,
|
||||
pub id: SiteId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct SiteId(Uuid);
|
||||
|
||||
impl FromStr for SiteId {
|
||||
type Err = uuid::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(SiteId(Uuid::parse_str(s)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl SiteId {
|
||||
#[cfg(feature = "proptest")]
|
||||
pub(crate) fn from_u128(v: u128) -> Self {
|
||||
Self(Uuid::from_u128(v))
|
||||
}
|
||||
}
|
||||
|
||||
impl ResourceDescription {
|
||||
|
||||
@@ -1,22 +1,67 @@
|
||||
use crate::messages::{
|
||||
client::ResourceDescriptionCidr, client::ResourceDescriptionDns, ClientId, ResourceId,
|
||||
client::ResourceDescriptionCidr,
|
||||
client::{GatewayGroup, ResourceDescriptionDns, SiteId},
|
||||
ClientId, ResourceId,
|
||||
};
|
||||
use ip_network::{IpNetwork, Ipv4Network, Ipv6Network};
|
||||
use proptest::{
|
||||
arbitrary::{any, any_with},
|
||||
sample,
|
||||
collection, sample,
|
||||
strategy::Strategy,
|
||||
};
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
|
||||
pub fn dns_resource() -> impl Strategy<Value = ResourceDescriptionDns> {
|
||||
(resource_id(), resource_name(), dns_resource_address())
|
||||
.prop_map(|(id, name, address)| ResourceDescriptionDns { id, address, name })
|
||||
(
|
||||
resource_id(),
|
||||
resource_name(),
|
||||
dns_resource_address(),
|
||||
gateway_groups(),
|
||||
address_description(),
|
||||
)
|
||||
.prop_map(|(id, name, address, gateway_groups, address_description)| {
|
||||
ResourceDescriptionDns {
|
||||
id,
|
||||
address,
|
||||
name,
|
||||
gateway_groups,
|
||||
address_description,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn cidr_resource(host_mask_bits: usize) -> impl Strategy<Value = ResourceDescriptionCidr> {
|
||||
(resource_id(), resource_name(), ip_network(host_mask_bits))
|
||||
.prop_map(|(id, name, address)| ResourceDescriptionCidr { id, address, name })
|
||||
(
|
||||
resource_id(),
|
||||
resource_name(),
|
||||
ip_network(host_mask_bits),
|
||||
gateway_groups(),
|
||||
address_description(),
|
||||
)
|
||||
.prop_map(|(id, name, address, gateway_groups, address_description)| {
|
||||
ResourceDescriptionCidr {
|
||||
id,
|
||||
address,
|
||||
name,
|
||||
gateway_groups,
|
||||
address_description,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn address_description() -> impl Strategy<Value = String> {
|
||||
any_with::<String>("[a-z]{4,10}".into())
|
||||
}
|
||||
|
||||
pub fn gateway_groups() -> impl Strategy<Value = Vec<GatewayGroup>> {
|
||||
collection::vec(gateway_group(), 1..=10)
|
||||
}
|
||||
|
||||
pub fn gateway_group() -> impl Strategy<Value = GatewayGroup> {
|
||||
(any_with::<String>("[a-z]{4,10}".into()), any::<u128>()).prop_map(|(name, id)| GatewayGroup {
|
||||
name,
|
||||
id: SiteId::from_u128(id),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn resource_id() -> impl Strategy<Value = ResourceId> + Clone {
|
||||
|
||||
@@ -1489,6 +1489,8 @@ mod proptests {
|
||||
address,
|
||||
id: resource.id,
|
||||
name: resource.name,
|
||||
address_description: resource.address_description,
|
||||
gateway_groups: resource.gateway_groups,
|
||||
};
|
||||
|
||||
client_state.add_resources(&[ResourceDescription::Cidr(dns_as_cidr_resource.clone())]);
|
||||
|
||||
@@ -506,7 +506,9 @@ mod test {
|
||||
r#"{
|
||||
"id": "c4bb3d79-afa7-4660-8918-06c38fda3a4a",
|
||||
"address": "*.foo.com",
|
||||
"name": "foo.com wildcard"
|
||||
"name": "foo.com wildcard",
|
||||
"address_description": "foo",
|
||||
"gateway_groups": [{"id": "bf56f32d-7b2c-4f5d-a784-788977d014a4", "name": "test"}]
|
||||
}"#,
|
||||
)
|
||||
.unwrap()
|
||||
@@ -517,7 +519,9 @@ mod test {
|
||||
r#"{
|
||||
"id": "c4bb3d79-afa7-4660-8918-06c38fda3a4b",
|
||||
"address": "*.bar.com",
|
||||
"name": "bar.com wildcard"
|
||||
"name": "bar.com wildcard",
|
||||
"address_description": "bar",
|
||||
"gateway_groups": [{"id": "bf56f32d-7b2c-4f5d-a784-788977d014a4", "name": "test"}]
|
||||
}"#,
|
||||
)
|
||||
.unwrap()
|
||||
@@ -528,7 +532,9 @@ mod test {
|
||||
r#"{
|
||||
"id": "c4bb3d79-afa7-4660-8918-06c38fda3a4c",
|
||||
"address": "baz.com",
|
||||
"name": "baz.com"
|
||||
"name": "baz.com",
|
||||
"address_description": "baz",
|
||||
"gateway_groups": [{"id": "bf56f32d-7b2c-4f5d-a784-788977d014a4", "name": "test"}]
|
||||
}"#,
|
||||
)
|
||||
.unwrap()
|
||||
|
||||
Reference in New Issue
Block a user