Skip to content

Commit f3f3dac

Browse files
test(e2ei/pki): add e2e test to fetch CRLs
1 parent 7416706 commit f3f3dac

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

e2e-identity/tests/e2e.rs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323

2424
#![cfg(not(target_os = "unknown"))]
2525

26-
use std::{collections::HashMap, net::SocketAddr, sync::Arc};
26+
use std::{
27+
collections::{HashMap, HashSet},
28+
net::SocketAddr,
29+
sync::Arc,
30+
};
2731

2832
use core_crypto_keystore::{ConnectionType, Database, DatabaseKey};
2933
use jwt_simple::prelude::*;
@@ -37,7 +41,11 @@ use utils::{
3741
rand_client_id, rand_str,
3842
stepca::CaCfg,
3943
};
40-
use wire_e2e_identity::{X509CredentialAcquisition, acquisition::X509CredentialConfiguration, pki_env::PkiEnvironment};
44+
use wire_e2e_identity::{
45+
X509CredentialAcquisition, acquisition::X509CredentialConfiguration, pki_env::PkiEnvironment,
46+
x509_check::extract_crl_uris,
47+
};
48+
use x509_cert::{crl::CertificateList, der::Decode as _};
4149

4250
#[path = "utils/mod.rs"]
4351
mod utils;
@@ -246,6 +254,54 @@ async fn x509_cert_acquisition_works(test_env: TestEnvironment, #[case] sign_alg
246254
.unwrap();
247255
}
248256

257+
#[tokio::test]
258+
#[ignore]
259+
#[rstest]
260+
#[case(JwsAlgorithm::P256)]
261+
#[case(JwsAlgorithm::P384)]
262+
#[case(JwsAlgorithm::P521)]
263+
#[case(JwsAlgorithm::Ed25519)]
264+
async fn fetching_crls_works(test_env: TestEnvironment, #[case] sign_alg: JwsAlgorithm) {
265+
let (pki_env, config) = prepare_pki_env_and_config(&test_env, sign_alg).await;
266+
let acq = X509CredentialAcquisition::try_new(Arc::new(pki_env.clone()), config).unwrap();
267+
let (_sign_kp, certs) = acq
268+
.complete_dpop_challenge()
269+
.await
270+
.unwrap()
271+
.complete_oidc_challenge()
272+
.await
273+
.unwrap();
274+
275+
let crl_uris: HashSet<String> = certs
276+
.iter()
277+
.map(|cert| x509_cert::Certificate::from_der(cert).expect("certificate in chain parses"))
278+
.filter_map(|cert| extract_crl_uris(&cert).expect("CRL distribution points can be extracted"))
279+
.flatten()
280+
.collect();
281+
282+
assert!(
283+
!crl_uris.is_empty(),
284+
"issued certificate chain should advertise at least one CRL"
285+
);
286+
287+
let result = pki_env
288+
.fetch_crls(crl_uris.iter().map(String::as_str))
289+
.await
290+
.expect("fetched CRL URLs");
291+
292+
assert_eq!(result.len(), crl_uris.len(), "each advertised CRL should be fetched");
293+
assert_eq!(
294+
result.keys().cloned().collect::<HashSet<_>>(),
295+
crl_uris,
296+
"fetched CRLs should match the advertised distribution points",
297+
);
298+
299+
for crl_der in result.values() {
300+
assert!(!crl_der.is_empty(), "fetched CRL should not be empty");
301+
let _ = CertificateList::from_der(crl_der).expect("fetched body is a valid DER CRL");
302+
}
303+
}
304+
249305
// @SF.PROVISIONING @TSFI.ACME
250306
// TODO: ignore this test for now, until the relevant PKI environment checks are in place
251307
#[ignore]

0 commit comments

Comments
 (0)