This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-teaclave.git


The following commit(s) were added to refs/heads/develop by this push:
     new abc0cf9  [attestation] Add unit test for AttestationReport::from_cert()
abc0cf9 is described below

commit abc0cf9e4419ecd404db12144558e2839d5d71e3
Author: Mingshen Sun <[email protected]>
AuthorDate: Fri Feb 14 13:52:58 2020 -0800

    [attestation] Add unit test for AttestationReport::from_cert()
---
 attestation/src/report.rs           |  34 +++++++++++++++++++++++++++++++---
 tests/fixtures/ias_root_ca_cert.der | Bin 0 -> 1359 bytes
 tests/fixtures/tls_ra_cert.der      | Bin 0 -> 8985 bytes
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/attestation/src/report.rs b/attestation/src/report.rs
index 9b80159..7531b7a 100644
--- a/attestation/src/report.rs
+++ b/attestation/src/report.rs
@@ -413,9 +413,27 @@ impl AttestationReport {
 pub mod tests {
     use super::*;
     use serde_json::json;
+    use std::io::Read;
+    use std::untrusted::fs::File;
     use teaclave_test_utils::*;
 
-    fn report_fixture() -> Value {
+    fn tls_ra_cert_der() -> Vec<u8> {
+        let mut cert = vec![];
+        let mut f = File::open("fixtures/tls_ra_cert.der").unwrap();
+        f.read_to_end(&mut cert).unwrap();
+
+        cert
+    }
+
+    fn ias_root_ca_cert_der() -> Vec<u8> {
+        let mut cert = vec![];
+        let mut f = File::open("fixtures/ias_root_ca_cert.der").unwrap();
+        f.read_to_end(&mut cert).unwrap();
+
+        cert
+    }
+
+    fn attesation_report() -> Value {
         let report = json!({
             "version": 3,
             "timestamp": "2020-02-11T22:25:59.682915",
@@ -448,11 +466,11 @@ pub mod tests {
     }
 
     pub fn run_tests() -> bool {
-        run_tests!(test_sgx_quote_parse_from,)
+        run_tests!(test_sgx_quote_parse_from, 
test_attestation_report_from_cert,)
     }
 
     fn test_sgx_quote_parse_from() {
-        let attn_report = report_fixture();
+        let attn_report = attesation_report();
         let sgx_quote_body_encoded = 
attn_report["isvEnclaveQuoteBody"].as_str().unwrap();
         let quote_raw = 
base64::decode(&sgx_quote_body_encoded.as_bytes()).unwrap();
         let sgx_quote = SgxQuote::parse_from(quote_raw.as_slice()).unwrap();
@@ -510,4 +528,14 @@ pub mod tests {
             .to_vec()
         );
     }
+
+    fn test_attestation_report_from_cert() {
+        let tls_ra_cert = tls_ra_cert_der();
+        let ias_root_ca_cert = ias_root_ca_cert_der();
+        let report = AttestationReport::from_cert(&tls_ra_cert, 
&ias_root_ca_cert);
+        assert!(report.is_ok());
+
+        let report = report.unwrap();
+        assert_eq!(report.sgx_quote_status, SgxQuoteStatus::TcbOutOfDate);
+    }
 }
diff --git a/tests/fixtures/ias_root_ca_cert.der 
b/tests/fixtures/ias_root_ca_cert.der
new file mode 100644
index 0000000..a11a49f
Binary files /dev/null and b/tests/fixtures/ias_root_ca_cert.der differ
diff --git a/tests/fixtures/tls_ra_cert.der b/tests/fixtures/tls_ra_cert.der
new file mode 100644
index 0000000..fe981bb
Binary files /dev/null and b/tests/fixtures/tls_ra_cert.der differ


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to