Skip to content

Commit feec7ca

Browse files
committed
Main compiles
1 parent cec9c9e commit feec7ca

6 files changed

Lines changed: 663 additions & 1041 deletions

File tree

src/attested_get.rs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,16 @@ pub async fn attested_get(
99
url_path: &str,
1010
attestation_verifier: AttestationVerifier,
1111
remote_certificate: Option<CertificateDer<'static>>,
12-
allow_self_signed: bool,
1312
) -> Result<reqwest::Response, ProxyError> {
14-
let proxy_client = if allow_self_signed {
15-
let client_config = crate::self_signed::client_tls_config_allow_self_signed()?;
16-
ProxyClient::new_with_tls_config(
17-
client_config,
18-
"127.0.0.1:0".to_string(),
19-
target_addr,
20-
AttestationGenerator::with_no_attestation(),
21-
attestation_verifier,
22-
None,
23-
)
24-
.await?
25-
} else {
26-
ProxyClient::new(
27-
None,
28-
"127.0.0.1:0".to_string(),
29-
target_addr,
30-
AttestationGenerator::with_no_attestation(),
31-
attestation_verifier,
32-
remote_certificate,
33-
)
34-
.await?
35-
};
13+
let proxy_client = ProxyClient::new(
14+
None,
15+
"127.0.0.1:0".to_string(),
16+
target_addr,
17+
AttestationGenerator::with_no_attestation(),
18+
attestation_verifier,
19+
remote_certificate,
20+
)
21+
.await?;
3622

3723
attested_get_with_client(proxy_client, url_path).await
3824
}
@@ -72,11 +58,11 @@ mod tests {
7258
ProxyServer,
7359
attestation::AttestationType,
7460
file_server::static_file_server,
75-
test_helpers::{generate_certificate_chain, generate_tls_config},
61+
test_helpers::{generate_certificate_chain_for_host, generate_tls_config},
7662
};
7763
use tempfile::tempdir;
7864

79-
#[tokio::test]
65+
#[tokio::test(flavor = "multi_thread")]
8066
async fn test_attested_get() {
8167
// Create a temporary directory with a file to serve
8268
let dir = tempdir().unwrap();
@@ -87,7 +73,7 @@ mod tests {
8773
let target_addr = static_file_server(dir.path().to_path_buf()).await.unwrap();
8874

8975
// Create TLS configuration
90-
let (cert_chain, private_key) = generate_certificate_chain("127.0.0.1".parse().unwrap());
76+
let (cert_chain, private_key) = generate_certificate_chain_for_host("localhost");
9177
let (server_config, client_config) = generate_tls_config(cert_chain.clone(), private_key);
9278

9379
// Setup a proxy server targetting the static file server
@@ -113,7 +99,7 @@ mod tests {
11399
let proxy_client = ProxyClient::new_with_tls_config(
114100
client_config,
115101
"127.0.0.1:0".to_string(),
116-
proxy_addr.to_string(),
102+
format!("localhost:{}", proxy_addr.port()),
117103
AttestationGenerator::with_no_attestation(),
118104
AttestationVerifier::mock(),
119105
None,

src/file_server.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ mod tests {
5555
use crate::{ProxyClient, attestation::AttestationType};
5656

5757
use super::*;
58-
use crate::test_helpers::{generate_certificate_chain, generate_tls_config};
58+
use crate::test_helpers::{generate_certificate_chain_for_host, generate_tls_config};
5959
use tempfile::tempdir;
6060

6161
/// Given a URL, fetch response body and content type header
@@ -74,7 +74,7 @@ mod tests {
7474
(body.to_vec(), content_type)
7575
}
7676

77-
#[tokio::test]
77+
#[tokio::test(flavor = "multi_thread")]
7878
async fn test_static_file_server() {
7979
// Create a temporary directory with some files to serve
8080
let dir = tempdir().unwrap();
@@ -94,7 +94,7 @@ mod tests {
9494
let target_addr = static_file_server(dir.path().to_path_buf()).await.unwrap();
9595

9696
// Create TLS configuration
97-
let (cert_chain, private_key) = generate_certificate_chain("127.0.0.1".parse().unwrap());
97+
let (cert_chain, private_key) = generate_certificate_chain_for_host("localhost");
9898
let (server_config, client_config) = generate_tls_config(cert_chain.clone(), private_key);
9999

100100
// Setup a proxy server targetting the static file server
@@ -118,7 +118,7 @@ mod tests {
118118
let proxy_client = ProxyClient::new_with_tls_config(
119119
client_config,
120120
"127.0.0.1:0".to_string(),
121-
proxy_addr.to_string(),
121+
format!("localhost:{}", proxy_addr.port()),
122122
AttestationGenerator::with_no_attestation(),
123123
AttestationVerifier::mock(),
124124
None,
@@ -128,9 +128,11 @@ mod tests {
128128

129129
let proxy_client_addr = proxy_client.local_addr().unwrap();
130130

131-
// Proxy cient accepts a single connection
131+
// Accept one client connection per request.
132132
tokio::spawn(async move {
133133
proxy_client.accept().await.unwrap();
134+
proxy_client.accept().await.unwrap();
135+
proxy_client.accept().await.unwrap();
134136
});
135137

136138
let client = reqwest::Client::new();

0 commit comments

Comments
 (0)