mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 12:37:00 +01:00
Fix proxy usage in tests (#443)
This commit is contained in:
parent
9d5296a34b
commit
78f780910e
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -12,4 +12,5 @@ kanidm_rlm_python/test_data/ca.pem
|
||||||
loc.sh
|
loc.sh
|
||||||
todo.sh
|
todo.sh
|
||||||
vendor.tar.*
|
vendor.tar.*
|
||||||
|
*.patch
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,7 @@ pub struct KanidmClientBuilder {
|
||||||
verify_hostnames: bool,
|
verify_hostnames: bool,
|
||||||
ca: Option<reqwest::Certificate>,
|
ca: Option<reqwest::Certificate>,
|
||||||
connect_timeout: Option<u64>,
|
connect_timeout: Option<u64>,
|
||||||
|
use_system_proxies: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_file_metadata<P: AsRef<Path>>(path: &P) -> Result<Metadata, ()> {
|
fn read_file_metadata<P: AsRef<Path>>(path: &P) -> Result<Metadata, ()> {
|
||||||
|
@ -92,6 +93,7 @@ impl KanidmClientBuilder {
|
||||||
verify_hostnames: true,
|
verify_hostnames: true,
|
||||||
ca: None,
|
ca: None,
|
||||||
connect_timeout: None,
|
connect_timeout: None,
|
||||||
|
use_system_proxies: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +127,7 @@ impl KanidmClientBuilder {
|
||||||
verify_hostnames,
|
verify_hostnames,
|
||||||
ca,
|
ca,
|
||||||
connect_timeout,
|
connect_timeout,
|
||||||
|
use_system_proxies,
|
||||||
} = self;
|
} = self;
|
||||||
// Process and apply all our options if they exist.
|
// Process and apply all our options if they exist.
|
||||||
let address = match kcc.uri {
|
let address = match kcc.uri {
|
||||||
|
@ -144,6 +147,7 @@ impl KanidmClientBuilder {
|
||||||
verify_hostnames,
|
verify_hostnames,
|
||||||
ca,
|
ca,
|
||||||
connect_timeout,
|
connect_timeout,
|
||||||
|
use_system_proxies,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,6 +201,7 @@ impl KanidmClientBuilder {
|
||||||
verify_hostnames: self.verify_hostnames,
|
verify_hostnames: self.verify_hostnames,
|
||||||
ca: self.ca,
|
ca: self.ca,
|
||||||
connect_timeout: self.connect_timeout,
|
connect_timeout: self.connect_timeout,
|
||||||
|
use_system_proxies: self.use_system_proxies,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,6 +213,7 @@ impl KanidmClientBuilder {
|
||||||
verify_hostnames: !accept_invalid_hostnames,
|
verify_hostnames: !accept_invalid_hostnames,
|
||||||
ca: self.ca,
|
ca: self.ca,
|
||||||
connect_timeout: self.connect_timeout,
|
connect_timeout: self.connect_timeout,
|
||||||
|
use_system_proxies: self.use_system_proxies,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,6 +225,7 @@ impl KanidmClientBuilder {
|
||||||
verify_hostnames: self.verify_hostnames,
|
verify_hostnames: self.verify_hostnames,
|
||||||
ca: self.ca,
|
ca: self.ca,
|
||||||
connect_timeout: self.connect_timeout,
|
connect_timeout: self.connect_timeout,
|
||||||
|
use_system_proxies: self.use_system_proxies,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,6 +236,18 @@ impl KanidmClientBuilder {
|
||||||
verify_hostnames: self.verify_hostnames,
|
verify_hostnames: self.verify_hostnames,
|
||||||
ca: self.ca,
|
ca: self.ca,
|
||||||
connect_timeout: Some(secs),
|
connect_timeout: Some(secs),
|
||||||
|
use_system_proxies: self.use_system_proxies,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn no_proxy(self) -> Self {
|
||||||
|
KanidmClientBuilder {
|
||||||
|
address: self.address,
|
||||||
|
verify_ca: self.verify_ca,
|
||||||
|
verify_hostnames: self.verify_hostnames,
|
||||||
|
ca: self.ca,
|
||||||
|
connect_timeout: self.connect_timeout,
|
||||||
|
use_system_proxies: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,6 +261,7 @@ impl KanidmClientBuilder {
|
||||||
verify_hostnames: self.verify_hostnames,
|
verify_hostnames: self.verify_hostnames,
|
||||||
ca: Some(ca),
|
ca: Some(ca),
|
||||||
connect_timeout: self.connect_timeout,
|
connect_timeout: self.connect_timeout,
|
||||||
|
use_system_proxies: self.use_system_proxies,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,6 +303,11 @@ impl KanidmClientBuilder {
|
||||||
.danger_accept_invalid_hostnames(!self.verify_hostnames)
|
.danger_accept_invalid_hostnames(!self.verify_hostnames)
|
||||||
.danger_accept_invalid_certs(!self.verify_ca);
|
.danger_accept_invalid_certs(!self.verify_ca);
|
||||||
|
|
||||||
|
let client_builder = match self.use_system_proxies {
|
||||||
|
true => client_builder,
|
||||||
|
false => client_builder.no_proxy(),
|
||||||
|
};
|
||||||
|
|
||||||
let client_builder = match &self.ca {
|
let client_builder = match &self.ca {
|
||||||
Some(cert) => client_builder.add_root_certificate(cert.clone()),
|
Some(cert) => client_builder.add_root_certificate(cert.clone()),
|
||||||
None => client_builder,
|
None => client_builder,
|
||||||
|
|
|
@ -92,6 +92,7 @@ pub fn run_test(test_fn: fn(KanidmClient) -> ()) {
|
||||||
let addr = format!("http://127.0.0.1:{}", port);
|
let addr = format!("http://127.0.0.1:{}", port);
|
||||||
let rsclient = KanidmClientBuilder::new()
|
let rsclient = KanidmClientBuilder::new()
|
||||||
.address(addr)
|
.address(addr)
|
||||||
|
.no_proxy()
|
||||||
.build()
|
.build()
|
||||||
.expect("Failed to build client");
|
.expect("Failed to build client");
|
||||||
|
|
||||||
|
|
|
@ -97,17 +97,20 @@ fn run_test(fix_fn: fn(&KanidmClient) -> (), test_fn: fn(CacheLayer, KanidmAsync
|
||||||
// Run fixtures
|
// Run fixtures
|
||||||
let adminclient = KanidmClientBuilder::new()
|
let adminclient = KanidmClientBuilder::new()
|
||||||
.address(addr.clone())
|
.address(addr.clone())
|
||||||
|
.no_proxy()
|
||||||
.build()
|
.build()
|
||||||
.expect("Failed to build sync client");
|
.expect("Failed to build sync client");
|
||||||
fix_fn(&adminclient);
|
fix_fn(&adminclient);
|
||||||
|
|
||||||
let client = KanidmClientBuilder::new()
|
let client = KanidmClientBuilder::new()
|
||||||
.address(addr.clone())
|
.address(addr.clone())
|
||||||
|
.no_proxy()
|
||||||
.build_async()
|
.build_async()
|
||||||
.expect("Failed to build async admin client");
|
.expect("Failed to build async admin client");
|
||||||
|
|
||||||
let rsclient = KanidmClientBuilder::new()
|
let rsclient = KanidmClientBuilder::new()
|
||||||
.address(addr)
|
.address(addr)
|
||||||
|
.no_proxy()
|
||||||
.build_async()
|
.build_async()
|
||||||
.expect("Failed to build client");
|
.expect("Failed to build client");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue