Skip to content

Commit d6001af

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

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

e2e-identity/tests/e2e.rs

Lines changed: 57 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,53 @@ async fn x509_cert_acquisition_works(test_env: TestEnvironment, #[case] sign_alg
246254
.unwrap();
247255
}
248256

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

0 commit comments

Comments
 (0)