fix(import): подтвердить обязательные гарантии второго эпика
This commit is contained in:
1 parent
31f6f00d3b
commit
ad23cd9a46
33 files changed
+3328
-18
No files matched your search
@@ -367,6 +367,8 @@ impl ExternalReferenceFetcher {
|
||||
fn outbound_client(policy: &OutboundHttpPolicy) -> Result<Client, Arc<str>> {
|
||||
let resolver = Arc::new(PolicyDnsResolver {
|
||||
policy: policy.clone(),
|
||||
#[cfg(test)]
|
||||
lookup: None,
|
||||
});
|
||||
Client::builder()
|
||||
.redirect(redirect::Policy::none())
|
||||
@@ -611,23 +613,43 @@ impl OutboundHttpPolicy {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone)]
|
||||
struct PolicyDnsResolver {
|
||||
policy: OutboundHttpPolicy,
|
||||
// Test-local DNS answers exercise the actual policy resolver and connector.
|
||||
// Neither this field nor an injection API exists in production builds.
|
||||
#[cfg(test)]
|
||||
lookup: Option<Arc<dyn Resolve>>,
|
||||
}
|
||||
|
||||
impl PolicyDnsResolver {
|
||||
fn lookup(&self, name: Name) -> Resolving {
|
||||
#[cfg(test)]
|
||||
if let Some(lookup) = &self.lookup {
|
||||
return lookup.resolve(name);
|
||||
}
|
||||
let host = normalize_host(name.as_str());
|
||||
Box::pin(async move {
|
||||
let addresses = tokio::net::lookup_host((host.as_str(), 0))
|
||||
.await
|
||||
.map_err(|error| Box::new(error) as Box<dyn std::error::Error + Send + Sync>)?;
|
||||
let addresses: Vec<_> = addresses.collect();
|
||||
Ok(Box::new(addresses.into_iter()) as Addrs)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Resolve for PolicyDnsResolver {
|
||||
fn resolve(&self, name: Name) -> Resolving {
|
||||
let host = normalize_host(name.as_str());
|
||||
let policy = self.policy.clone();
|
||||
let resolver = self.clone();
|
||||
Box::pin(async move {
|
||||
policy
|
||||
.validate_host(&host)
|
||||
.map_err(|error| boxed_io_error(error.to_string()))?;
|
||||
let explicitly_allowed = policy.is_explicitly_allowed(&host);
|
||||
let resolved = tokio::net::lookup_host((host.as_str(), 0))
|
||||
.await
|
||||
.map_err(|error| Box::new(error) as Box<dyn std::error::Error + Send + Sync>)?;
|
||||
let resolved = resolver.lookup(name).await?;
|
||||
let addresses = resolved
|
||||
.filter(|address| {
|
||||
!policy.is_denied_ip(address.ip())
|
||||
@@ -969,3 +991,7 @@ fn to_reqwest_method(method: HttpMethod) -> reqwest::Method {
|
||||
HttpMethod::Options => reqwest::Method::OPTIONS,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "client_dns_tests.rs"]
|
||||
mod dns_tests;
|
||||
Reference in new issue
Block a user