Add a test that checks whether 3 known subject attributes can be retrieved by NID
This commit is contained in:
parent
1d214bce61
commit
9074af5bdd
|
|
@ -69,3 +69,32 @@ fn test_subject_read_cn() {
|
||||||
|
|
||||||
assert_eq!(&cn as &str, "test_cert")
|
assert_eq!(&cn as &str, "test_cert")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_nid_values() {
|
||||||
|
let cert_path = Path::new("test/nid_test_cert.pem");
|
||||||
|
let mut file = File::open(&cert_path)
|
||||||
|
.ok()
|
||||||
|
.expect("Failed to open `test/nid_test_cert.pem`");
|
||||||
|
|
||||||
|
let cert = X509::from_pem(&mut file).ok().expect("Failed to load PEM");
|
||||||
|
let subject = cert.subject_name();
|
||||||
|
|
||||||
|
let cn = match subject.text_by_nid(Nid::CN) {
|
||||||
|
Some(x) => x,
|
||||||
|
None => panic!("Failed to read CN from cert")
|
||||||
|
};
|
||||||
|
assert_eq!(&cn as &str, "example.com");
|
||||||
|
|
||||||
|
let email = match subject.text_by_nid(Nid::Email) {
|
||||||
|
Some(x) => x,
|
||||||
|
None => panic!("Failed to read subject email address from cert")
|
||||||
|
};
|
||||||
|
assert_eq!(&email as &str, "test@example.com");
|
||||||
|
|
||||||
|
let friendly = match subject.text_by_nid(Nid::FriendlyName) {
|
||||||
|
Some(x) => x,
|
||||||
|
None => panic!("Failed to read subject friendly name from cert")
|
||||||
|
};
|
||||||
|
assert_eq!(&friendly as &str, "Example");
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIB1DCCAX6gAwIBAgIJAMzXWZGWHleWMA0GCSqGSIb3DQEBCwUAMFYxHzAdBgkq
|
||||||
|
hkiG9w0BCQEWEHRlc3RAZXhhbXBsZS5jb20xFDASBgNVBAMMC2V4YW1wbGUuY29t
|
||||||
|
MR0wGwYJKoZIhvcNAQkUHg4ARQB4AGEAbQBwAGwAZTAeFw0xNTA3MDEwNjQ3NDRa
|
||||||
|
Fw0xNTA3MzEwNjQ3NDRaMFYxHzAdBgkqhkiG9w0BCQEWEHRlc3RAZXhhbXBsZS5j
|
||||||
|
b20xFDASBgNVBAMMC2V4YW1wbGUuY29tMR0wGwYJKoZIhvcNAQkUHg4ARQB4AGEA
|
||||||
|
bQBwAGwAZTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQCmejzp4+o35FD0hAnx2trL
|
||||||
|
08h07X5jZca9DgZH35hWXPh7fMucLt/IPXIRnz2zKEa/Mo6D2V/fx03Mqo0epid7
|
||||||
|
AgMBAAGjLzAtMB0GA1UdDgQWBBRQa57tXz3rZNRz+fTbo3w3jQJMBTAMBgNVHRME
|
||||||
|
BTADAQH/MA0GCSqGSIb3DQEBCwUAA0EAm0iY9cr+gvC+vcQIebdofpQ4GcDW8U6W
|
||||||
|
Bxs8ZXinLl69P0jYLum3+XITNFRiyQqcivaxdxthxDNOX7P+aKwkJA==
|
||||||
|
-----END CERTIFICATE-----
|
||||||
Loading…
Reference in New Issue