test: Refactor log entry parsing integration test to use new api client

This commit is contained in:
Tyler Beckman 2024-10-27 17:18:35 -06:00
parent 03f4151f66
commit c46dfd4457
Signed by: Ty
GPG key ID: 2813440C772555A4

View file

@ -2,41 +2,28 @@ use std::sync::Arc;
use base64ct::Encoding;
use ct::{
merkle::{
api::{responses::GetEntriesResponseEntry, CtApiClient}, merkle::{
consts::EXTRA_DATA_BASE64_BUFFER_SIZE,
types::{MerkleLeafType, Version}
},
parsing::entry::{parse_entry_extra_data_precert, parse_entry_extra_data_x509}
}, parsing::entry::{parse_entry_extra_data_precert, parse_entry_extra_data_x509}
};
use serde::Deserialize;
use tokio::task::JoinSet;
#[derive(Debug, Deserialize)]
pub struct Entry {
leaf_input: String,
extra_data: String
}
#[derive(Debug, Deserialize)]
pub struct GetEntriesResponse {
entries: Vec<Entry>
}
async fn fetch_entries() -> impl Iterator<Item = Entry> {
let client = Arc::new(reqwest::Client::new());
let mut join_set: JoinSet<GetEntriesResponse> = JoinSet::new();
for i in 0..12u32 {
async fn fetch_entries() -> impl Iterator<Item = GetEntriesResponseEntry> {
let client = Arc::new(
CtApiClient::new_with_client(
"https://oak.ct.letsencrypt.org/2024h2/ct/v1/get-entries",
Arc::new(reqwest::Client::new())
)
);
let mut join_set: JoinSet<_> = JoinSet::new();
for i in 0..12u64 {
let client = client.clone();
join_set.spawn(async move {
client
.get("https://oak.ct.letsencrypt.org/2024h2/ct/v1/get-entries")
.query(&[("start", i * 256), ("end", (i + 1) * 256 - 1)])
.send()
.get_log_entries(i * 256, (i+1) * 256 - 1)
.await
.expect("Request to ct log should succeed")
.json()
.await
.expect("Request to ct log should parse properly")
.expect("Request should succeed")
});
}
join_set