Skip to content

Commit

Permalink
Merge pull request #34 from dongx1x/update-test
Browse files Browse the repository at this point in the history
vmsdk/rust: remove invalid input test for event logs replay
  • Loading branch information
dongx1x authored Apr 7, 2024
2 parents d2ca99f + bb01d60 commit f4a5725
Showing 1 changed file with 0 additions and 49 deletions.
49 changes: 0 additions & 49 deletions src/rust/cctrusted_vm/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,53 +719,4 @@ mod sdk_api_tests {
}
}
}

#[test]
fn test_replay_cc_eventlog_with_invalid_input() {
let mut event_logs = match API::get_cc_eventlog(None, None) {
Ok(l) => l,
Err(e) => {
assert_eq!(true, format!("{:?}", e).is_empty());
return;
}
};
assert_ne!(event_logs.len(), 0);

// Generate an invalid event log by tampering with a valid log:
// Randomly choose one entry and set an invalid imr_index for it.
let mut rng = rand::thread_rng();
let entry_idx: usize = rng.gen_range(0..event_logs.len());
let measure_count = match API::get_measurement_count() {
Ok(measure_count) => measure_count,
Err(e) => {
assert_eq!(true, format!("{:?}", e).is_empty());
return;
}
};
let invalid_imr_index: u32 = rng.gen_range(measure_count..std::u8::MAX).into();
let log_entry: &mut EventLogEntry = &mut event_logs[entry_idx];
match log_entry {
EventLogEntry::TcgImrEvent(ref mut tcg_imr_event) => {
tcg_imr_event.imr_index = invalid_imr_index;
}
EventLogEntry::TcgPcClientImrEvent(ref mut tcg_pc_client_imr_event) => {
tcg_pc_client_imr_event.imr_index = invalid_imr_index;
}
EventLogEntry::TcgCanonicalEvent(_) => todo!(),
}

// Test with the invalid event log.
let replay_results = match API::replay_cc_eventlog(event_logs) {
Ok(r) => r,
Err(e) => {
// This is the expected behavior. Invalid log is not replayed.
assert_ne!(true, format!("{:?}", e).is_empty());
return;
}
};
assert!(
replay_results.len() == 0,
"Invalid event log should not be replayed!"
);
}
}

0 comments on commit f4a5725

Please sign in to comment.