Skip to content

Commit 4b3612a

Browse files
committed
test: add a test to check that the compression is enabled in signer and aggregator
1 parent 92a808d commit 4b3612a

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

internal/mithril-aggregator-client/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ mod client;
77
mod error;
88
mod external_trait_impls;
99
pub mod query;
10-
#[cfg(test)]
1110
mod test;
1211

1312
pub use builder::AggregatorClientBuilder;

internal/mithril-aggregator-client/src/test/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#[cfg(test)]
12
use httpmock::MockServer;
23

4+
#[cfg(test)]
35
use crate::AggregatorHttpClient;
46

57
#[cfg(test)]
@@ -29,3 +31,36 @@ macro_rules! assert_error_matches {
2931
}
3032
#[cfg(test)]
3133
pub(crate) use assert_error_matches;
34+
35+
/// Define a test that checks that http compression is enabled for the client.
36+
///
37+
/// Requires `httpmock` in dev-dependencies
38+
#[macro_export]
39+
macro_rules! test_http_compression_is_enabled {
40+
() => {
41+
#[tokio::test]
42+
async fn test_http_compression_is_enabled_and_send_accept_encoding_header_with_correct_values() {
43+
let server = httpmock::MockServer::start();
44+
server.mock(|when, then| {
45+
when.is_true(|req| {
46+
let headers = req.headers();
47+
let accept_encoding_header = headers
48+
.get("accept-encoding")
49+
.expect("Accept-Encoding header not found");
50+
51+
["gzip", "br", "deflate", "zstd"].iter().all(|&encoding| {
52+
accept_encoding_header.to_str().is_ok_and(|h| h.contains(encoding))
53+
})
54+
});
55+
56+
then.status(200).body("[]");
57+
});
58+
59+
let client = $crate::AggregatorHttpClient::builder(server.base_url()).build().unwrap();
60+
client
61+
.send($crate::query::GetCertificatesListQuery::latest())
62+
.await
63+
.expect("GET request should succeed with Accept-Encoding header");
64+
}
65+
};
66+
}

mithril-aggregator/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,8 @@ use tikv_jemallocator::Jemalloc;
6969
#[cfg(all(not(target_env = "msvc"), feature = "jemallocator"))]
7070
#[global_allocator]
7171
static GLOBAL: Jemalloc = Jemalloc;
72+
73+
#[cfg(test)]
74+
mod tests {
75+
mithril_aggregator_client::test_http_compression_is_enabled!();
76+
}

mithril-signer/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ static GLOBAL: Jemalloc = Jemalloc;
4343
pub(crate) mod test_tools {
4444
mithril_common::define_test_logger!();
4545
}
46+
47+
#[cfg(test)]
48+
mod tests {
49+
mithril_aggregator_client::test_http_compression_is_enabled!();
50+
}

0 commit comments

Comments
 (0)