Registry testing - part 14

This commit is contained in:
Maurus Decimus
2026-03-24 18:43:08 +01:00
parent 3a7dd3ca5d
commit 1b5334b65c
44 changed files with 2449 additions and 1701 deletions

View File

@@ -282,8 +282,18 @@ pub(crate) async fn parse_certificates(
continue;
}
};
let public = match cert_obj.object.certificate.value().await {
Ok(value) => value.into_owned().into_bytes(),
Err(err) => {
bp.build_error(
cert_obj.id,
format!("Failed to obtain certificate value: {err}"),
);
continue;
}
};
match build_certified_key(cert_obj.object.certificate.into_bytes(), secret) {
match build_certified_key(public, secret) {
Ok(cert) => {
match cert
.end_entity_cert()

View File

@@ -29,6 +29,7 @@ pub use crate::types::map::Map;
pub use crate::types::socketaddr::SocketAddr;
pub use crate::types::string::StringValidator;
pub use serde::{Deserialize, Serialize};
pub use std::borrow::Cow;
pub use std::str::FromStr;
pub use types::blob::BlobId;
pub use types::id::Id;

View File

@@ -207,11 +207,11 @@ impl<'de, T: MapItem> Deserialize<'de> for Map<T> {
{
let mut items = Vec::with_capacity(map.size_hint().unwrap_or(0));
while let Some(key) = map.next_key::<&str>()? {
while let Some(key) = map.next_key::<Cow<'de, str>>()? {
let value: Option<bool> = map.next_value()?;
if value == Some(true) {
let item = T::try_from_string(key)
let item = T::try_from_string(&key)
.ok_or_else(|| de::Error::custom(format!("invalid map key: {key}")))?;
if !items.contains(&item) {
items.push(item);

View File

@@ -13,6 +13,11 @@ use crate::{
};
use std::{fmt::Display, str::FromStr};
const UNSET_SOCKET_ADDR: std::net::SocketAddr = std::net::SocketAddr::new(
std::net::IpAddr::V4(std::net::Ipv4Addr::from_octets([255, 255, 255, 255])),
u16::MAX,
);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SocketAddr(pub std::net::SocketAddr);
@@ -22,7 +27,7 @@ impl SocketAddr {
}
pub fn is_valid(&self) -> bool {
!self.0.ip().is_unspecified()
self.0 != UNSET_SOCKET_ADDR
}
}
@@ -63,7 +68,7 @@ impl<'de> serde::Deserialize<'de> for SocketAddr {
impl Default for SocketAddr {
fn default() -> Self {
SocketAddr(std::net::SocketAddr::from(([0, 0, 0, 0], 0)))
SocketAddr(UNSET_SOCKET_ADDR)
}
}

View File

@@ -5,7 +5,11 @@
*/
use crate::{
schema::{enums, prelude::UTCDateTime, structs},
schema::{
enums,
prelude::UTCDateTime,
structs::{self, DmarcReportRecord, TlsFailureDetails},
},
types::{ipaddr::IpAddr, list::List},
};
use mail_auth::{
@@ -927,3 +931,31 @@ impl From<&mail_auth::dmarc::Policy> for enums::DmarcDisposition {
}
}
}
impl DmarcReportRecord {
pub fn eq_except_count(&self, other: &Self) -> bool {
self.dkim_results == other.dkim_results
&& self.envelope_from == other.envelope_from
&& self.envelope_to == other.envelope_to
&& self.evaluated_disposition == other.evaluated_disposition
&& self.evaluated_dkim == other.evaluated_dkim
&& self.evaluated_spf == other.evaluated_spf
&& self.extensions == other.extensions
&& self.header_from == other.header_from
&& self.policy_override_reasons == other.policy_override_reasons
&& self.source_ip == other.source_ip
&& self.spf_results == other.spf_results
}
}
impl TlsFailureDetails {
pub fn eq_except_count(&self, other: &Self) -> bool {
self.additional_information == other.additional_information
&& self.failure_reason_code == other.failure_reason_code
&& self.receiving_ip == other.receiving_ip
&& self.receiving_mx_helo == other.receiving_mx_helo
&& self.receiving_mx_hostname == other.receiving_mx_hostname
&& self.result_type == other.result_type
&& self.sending_mta_ip == other.sending_mta_ip
}
}

View File

@@ -5,8 +5,8 @@
*/
use crate::schema::prelude::{
SecretKey, SecretKeyEnvironmentVariable, SecretKeyFile, SecretKeyOptional, SecretKeyValue,
SecretText, SecretTextOptional, SecretTextValue,
PublicText, SecretKey, SecretKeyEnvironmentVariable, SecretKeyFile, SecretKeyOptional,
SecretKeyValue, SecretText, SecretTextOptional, SecretTextValue,
};
use std::borrow::Cow;
@@ -30,6 +30,16 @@ impl SecretText {
}
}
impl PublicText {
pub async fn value(&self) -> Result<Cow<'_, str>, String> {
match self {
PublicText::Text(value) => Ok(Cow::Borrowed(value.value.as_str())),
PublicText::File(file) => file.secret().await.map(Cow::Owned),
PublicText::EnvironmentVariable(env_var) => env_var.secret().map(Cow::Owned),
}
}
}
impl SecretKeyOptional {
pub async fn secret(&self) -> Result<Option<Cow<'_, str>>, String> {
match self {

View File

@@ -605,7 +605,7 @@ impl DmarcReporting for Server {
.0
.inner
.iter()
.position(|d| d.value == record)
.position(|d| d.value.eq_except_count(&record))
{
report.report.records.0.inner[idx].value.count += 1;
} else {

View File

@@ -421,18 +421,19 @@ impl TlsReporting for Server {
};
// Add failure details
if let Some(failure) = event.failure.clone().map(TlsFailureDetails::from) {
if let Some(mut failure) = event.failure.clone().map(TlsFailureDetails::from) {
if let Some(idx) = policy
.failure_details
.0
.inner
.iter()
.position(|d| d.value == failure)
.position(|d| d.value.eq_except_count(&failure))
{
policy.failure_details.0.inner[idx]
.value
.failed_session_count += 1;
} else {
failure.failed_session_count = 1;
policy.failure_details.push(failure);
}