Registry testing - part 15

This commit is contained in:
Maurus Decimus
2026-03-25 18:55:39 +01:00
parent 1b5334b65c
commit 0fde3e04fd
20 changed files with 1084 additions and 665 deletions

View File

@@ -68,7 +68,7 @@ pub struct DomainCache {
pub const DOMAIN_FLAG_RELAY: u8 = 1;
pub const DOMAIN_FLAG_SUB_ADDRESSING: u8 = 1 << 1;
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct AccountCache {
pub name: Box<str>,
pub id: u32,
@@ -156,9 +156,9 @@ pub(crate) struct AccessTo {
#[derive(Clone)]
pub struct AccountInfo {
pub(crate) account_id: u32,
pub(crate) account: Arc<AccountCache>,
pub(crate) addresses: Vec<String>,
pub account_id: u32,
pub account: Arc<AccountCache>,
pub addresses: Vec<String>,
}
#[derive(Clone, Copy)]

View File

@@ -55,6 +55,7 @@ pub struct SpamFilterConfig {
pub pyzor: Option<PyzorConfig>,
pub classifier: Option<ClassifierConfig>,
pub scores: SpamFilterScoreConfig,
pub spam_rules_url: Option<String>,
}
#[derive(Debug, Clone, Default)]
@@ -201,6 +202,7 @@ impl SpamFilterConfig {
spam_threshold: spam.score_spam.into_inner() as f32,
},
grey_list_expiry: spam.greylist_for.map(|d| d.into_inner().as_secs()),
spam_rules_url: spam.spam_filter_rules_url,
}
}
}
@@ -316,49 +318,49 @@ impl DnsBlServer {
zone: bp.compile_expr(obj.id, &server.ctx_zone()),
tags: bp.compile_expr(obj.id, &server.ctx_tag()),
scope: Element::Any,
id: server.description,
id: server.name,
}
.into(),
SpamDnsblServer::Url(server) if server.enable => DnsBlServer {
zone: bp.compile_expr(obj.id, &server.ctx_zone()),
tags: bp.compile_expr(obj.id, &server.ctx_tag()),
scope: Element::Url,
id: server.description,
id: server.name,
}
.into(),
SpamDnsblServer::Domain(server) if server.enable => DnsBlServer {
zone: bp.compile_expr(obj.id, &server.ctx_zone()),
tags: bp.compile_expr(obj.id, &server.ctx_tag()),
scope: Element::Domain,
id: server.description,
id: server.name,
}
.into(),
SpamDnsblServer::Email(server) if server.enable => DnsBlServer {
zone: bp.compile_expr(obj.id, &server.ctx_zone()),
tags: bp.compile_expr(obj.id, &server.ctx_tag()),
scope: Element::Email,
id: server.description,
id: server.name,
}
.into(),
SpamDnsblServer::Ip(server) if server.enable => DnsBlServer {
zone: bp.compile_expr(obj.id, &server.ctx_zone()),
tags: bp.compile_expr(obj.id, &server.ctx_tag()),
scope: Element::Ip,
id: server.description,
id: server.name,
}
.into(),
SpamDnsblServer::Header(server) if server.enable => DnsBlServer {
zone: bp.compile_expr(obj.id, &server.ctx_zone()),
tags: bp.compile_expr(obj.id, &server.ctx_tag()),
scope: Element::Header,
id: server.description,
id: server.name,
}
.into(),
SpamDnsblServer::Body(server) if server.enable => DnsBlServer {
zone: bp.compile_expr(obj.id, &server.ctx_zone()),
tags: bp.compile_expr(obj.id, &server.ctx_tag()),
scope: Element::Body,
id: server.description,
id: server.name,
}
.into(),
_ => None,

View File

@@ -23,6 +23,11 @@ use store::{
};
use types::id::Id;
pub const ASN_IPV4: &str = "https://cdn.jsdelivr.net/npm/@ip-location-db/asn/asn-ipv4.csv";
pub const ASN_IPV6: &str = "https://cdn.jsdelivr.net/npm/@ip-location-db/asn/asn-ipv6.csv";
pub const GEO_IPV4: &str = "https://cdn.jsdelivr.net/npm/@ip-location-db/geolite2-geo-whois-asn-country/geolite2-geo-whois-asn-country-ipv4.csv";
pub const GEO_IPV6: &str = "https://cdn.jsdelivr.net/npm/@ip-location-db/geolite2-geo-whois-asn-country/geolite2-geo-whois-asn-country-ipv6.csv";
pub trait BootstrapDefaults {
fn insert_safe_defaults(&mut self) -> impl Future<Output = ()> + Send;
}
@@ -284,6 +289,7 @@ async fn insert_safe_defaults(bp: &mut Bootstrap) -> trc::Result<()> {
}
if bp.registry.count_object(ObjectType::OidcProvider).await? == 0 {
let todo = "use asymmetric keys";
bp.registry
.write(RegistryWrite::insert(
&OidcProvider {
@@ -489,6 +495,23 @@ async fn insert_safe_defaults(bp: &mut Bootstrap) -> trc::Result<()> {
}
}
#[cfg(not(feature = "test_mode"))]
if bp.registry.count_object(ObjectType::Asn).await? == 0 {
bp.registry
.write(RegistryWrite::insert(
&Asn::Resource(AsnResource {
asn_urls: Map::new(vec![ASN_IPV4.into(), ASN_IPV6.into()]),
geo_urls: Map::new(vec![GEO_IPV4.into(), GEO_IPV6.into()]),
max_size: 104857600,
expires: Duration::from_millis(24 * 60 * 60 * 1000),
timeout: Duration::from_millis(5 * 60 * 1000),
..Default::default()
})
.into(),
))
.await?;
}
if bp.registry.count_object(ObjectType::Tracer).await? == 0 {
bp.registry
.write(RegistryWrite::insert(

View File

@@ -6,7 +6,11 @@
use crate::USER_AGENT;
use hyper::HeaderMap;
use std::time::Duration;
use mail_auth::flate2;
use std::{
io::{BufReader, Read},
time::Duration,
};
use utils::HttpLimitResponse;
pub mod application;
@@ -58,6 +62,16 @@ pub async fn fetch_resource(
))
}
}
.and_then(|bytes| {
if url.ends_with(".gz") || url.ends_with(".gzip") {
BufReader::new(flate2::read::GzDecoder::new(&bytes[..]))
.bytes()
.collect::<Result<Vec<u8>, _>>()
.map_err(|err| format!("Failed to decompress {url}: {err}"))
} else {
Ok(bytes)
}
})
}
pub fn is_localhost_url(url: &str) -> bool {