Skip to content

Commit

Permalink
Add more CSR roundtrip unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lvkv authored and cpu committed Nov 13, 2024
1 parent d4a063f commit d3dea5e
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions rcgen/tests/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ mod test_parse_other_name_alt_name {

#[cfg(feature = "x509-parser")]
mod test_csr {
use rcgen::{CertificateParams, CertificateSigningRequestParams, KeyPair, KeyUsagePurpose};
use rcgen::{
CertificateParams, CertificateSigningRequestParams, ExtendedKeyUsagePurpose, KeyPair,
KeyUsagePurpose,
};

#[test]
fn test_csr_roundtrip() {
Expand All @@ -370,10 +373,7 @@ mod test_csr {
}

#[test]
fn test_nontrivial_csr_roundtrip() {
let key_pair = KeyPair::generate().unwrap();

// We should be able to serialize a CSR, and then parse the CSR.
fn test_csr_with_key_usages_roundtrip() {
let mut params = CertificateParams::default();
params.key_usages = vec![
KeyUsagePurpose::DigitalSignature,
Expand All @@ -391,6 +391,24 @@ mod test_csr {
generate_and_test_parsed_csr(&params);
}

#[test]
fn test_csr_with_extended_key_usages_roundtrip() {
let mut params = CertificateParams::default();
params.extended_key_usages = vec![
ExtendedKeyUsagePurpose::ServerAuth,
ExtendedKeyUsagePurpose::ClientAuth,
];
generate_and_test_parsed_csr(&params);
}

#[test]
fn test_csr_with_key_usgaes_and_extended_key_usages_roundtrip() {
let mut params = CertificateParams::default();
params.key_usages = vec![KeyUsagePurpose::DigitalSignature];
params.extended_key_usages = vec![ExtendedKeyUsagePurpose::ClientAuth];
generate_and_test_parsed_csr(&params);
}

fn generate_and_test_parsed_csr(params: &CertificateParams) {
// Generate a key pair for the CSR
let key_pair = KeyPair::generate().unwrap();
Expand Down

0 comments on commit d3dea5e

Please sign in to comment.