Skip to content

Commit 0393c0f

Browse files
committed
test: ✅ add test to check if cert chain is not included if set to false
1 parent 07588a9 commit 0393c0f

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

test-certs/src/configuration/certificates.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,25 @@ impl CertificateType {
122122
}
123123

124124
impl ServerConfiguration {
125-
fn default_export_key() -> bool {
125+
/// Default value for the export_key property.
126+
pub fn default_export_key() -> bool {
126127
true
127128
}
128-
fn default_include_certificate_chain() -> bool {
129+
130+
/// Default value for the include_certificate_chain property.
131+
pub fn default_include_certificate_chain() -> bool {
129132
true
130133
}
131134
}
132135

133136
impl ClientConfiguration {
134-
fn default_export_key() -> bool {
137+
/// Default value for the export_key property.
138+
pub fn default_export_key() -> bool {
135139
true
136140
}
137-
fn default_include_certificate_chain() -> bool {
141+
142+
/// Default value for the include_certificate_chain property.
143+
pub fn default_include_certificate_chain() -> bool {
138144
true
139145
}
140146
}

test-certs/src/generation.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ fn certificate_params(
164164

165165
#[cfg(test)]
166166
mod tests {
167+
use std::net::{IpAddr, Ipv4Addr};
168+
167169
use crate::configuration::certificates::fixtures::{
168170
ca_certificate_type, client_certificate_type, server_certificate_type,
169171
};
@@ -205,5 +207,21 @@ mod tests {
205207
assert_eq!(parent, ca_cert);
206208
}
207209

210+
#[test]
211+
fn should_not_include_certificate_chain() {
212+
let ca = ca_certificate_type();
213+
let ca_cert = Issuer::new(ca.build("my-ca", None).unwrap());
214+
let client = CertificateType::Client(ClientConfiguration {
215+
subject_alternative_names: SubjectAlternativeNames {
216+
ip: vec![IpAddr::V4(Ipv4Addr::LOCALHOST)],
217+
dns_name: vec!["my-client.org".to_string()],
218+
},
219+
include_certificate_chain: false,
220+
export_key: ClientConfiguration::default_export_key(),
221+
});
222+
let client_cert = client.build("client", Some(&ca_cert)).unwrap();
223+
assert!(client_cert.issuer.is_none());
224+
}
225+
208226
// TODO: write test to check wether client/server certs are really issued by a ca
209227
}

0 commit comments

Comments
 (0)