diff options
| author | Jethro Beekman <[email protected]> | 2015-06-30 23:51:54 -0700 |
|---|---|---|
| committer | Jethro Beekman <[email protected]> | 2015-06-30 23:51:54 -0700 |
| commit | 9074af5bdd0d88521979174e287748b0422c12e2 (patch) | |
| tree | 879cc0ed1bcb1a095e975e1249b0fe4195fc91b9 /openssl/src | |
| parent | Fix NID definitions to match OpenSSL. The previous numbers were introduced in... (diff) | |
| download | rust-openssl-9074af5bdd0d88521979174e287748b0422c12e2.tar.xz rust-openssl-9074af5bdd0d88521979174e287748b0422c12e2.zip | |
Add a test that checks whether 3 known subject attributes can be retrieved by NID
Diffstat (limited to 'openssl/src')
| -rw-r--r-- | openssl/src/x509/tests.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs index 6d95b966..4e1c4f15 100644 --- a/openssl/src/x509/tests.rs +++ b/openssl/src/x509/tests.rs @@ -69,3 +69,32 @@ fn test_subject_read_cn() { 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, "[email protected]"); + + 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"); +} |