Skip to content

Commit

Permalink
test ConfigState::get_certificate_by_fingerprint
Browse files Browse the repository at this point in the history
rename ConfigState::get_certificate to get_certificate_by_fingerprint
  • Loading branch information
Keksoj committed May 22, 2023
1 parent cf5964b commit f193370
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bin/src/command/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,8 @@ impl CommandServer {
}
}

debug!("Received these worker responses: {:?}", responses);

let mut worker_responses: BTreeMap<String, ResponseContent> = responses
.into_iter()
.filter_map(|(worker_id, proxy_response)| {
Expand Down
1 change: 1 addition & 0 deletions bin/src/ctl/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ impl CommandManager {
}
}
ResponseStatus::Ok => {
info!("We did get a response from the proxy");
match response.content {
Some(ResponseContent {
content_type: Some(ContentType::WorkerResponses(worker_responses)),
Expand Down
40 changes: 39 additions & 1 deletion command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,10 @@ impl ConfigState {
cluster_ids
}

pub fn get_certificate(&self, fingerprint: &[u8]) -> Option<CertificateWithNames> {
pub fn get_certificate_by_fingerprint(
&self,
fingerprint: &[u8],
) -> Option<CertificateWithNames> {
self.certificates
.values()
.filter_map(|h| h.get(&Fingerprint(fingerprint.to_vec())))
Expand Down Expand Up @@ -1957,4 +1960,39 @@ mod tests {

assert_eq!(diff, e);
}

#[test]
fn certificate_retrieval() {
let mut state: ConfigState = Default::default();
let certificate_and_key = CertificateAndKey {
certificate: String::from(include_str!("../assets/certificate.pem")),
key: String::from(include_str!("../assets/key.pem")),
certificate_chain: vec![],
versions: vec![],
names: vec!["lolcatho.st".to_string()],
};
let add_certificate = AddCertificate {
address: "127.0.0.1:8080".to_string(),
certificate: certificate_and_key,
expired_at: None,
};
state
.dispatch(&Request {
request_type: Some(RequestType::AddCertificate(add_certificate)),
})
.expect("Could not add certificate");

println!("state: {:#?}", state);

let fingerprint: Fingerprint = serde_json::from_str(
"\"ab2618b674e15243fd02a5618c66509e4840ba60e7d64cebec84cdbfeceee0c5\"",
)
.expect("Could not deserialize the fingerprint");

let certificate_found_by_fingerprint = state
.get_certificate_by_fingerprint(&fingerprint.0)
.expect("could not retrieve certificate by fingerprint");

println!("found certificate: {:#?}", certificate_found_by_fingerprint);
}
}
2 changes: 1 addition & 1 deletion lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ impl Server {
return;
}
Some(RequestType::QueryCertificateByFingerprint(f)) => {
let response = match self.config_state.get_certificate(f) {
let response = match self.config_state.get_certificate_by_fingerprint(f) {
Some(cert) => WorkerResponse::ok_with_content(
message.id.clone(),
ContentType::CertificateByFingerprint(cert).into(),
Expand Down

0 comments on commit f193370

Please sign in to comment.