Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dep/verifier: fix eventlog with extra blank chars #443

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions deps/verifier/src/eventlog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use hash::HashAlgorithm;
use serde_json::{Map, Value};
use sha2::{digest::FixedOutput, Digest, Sha256, Sha384, Sha512};

#[derive(Clone)]
#[derive(Clone, PartialEq, Debug)]
pub struct AAEvent {
pub domain: String,
pub operation: String,
Expand All @@ -24,10 +24,7 @@ impl FromStr for AAEvent {

fn from_str(input: &str) -> Result<Self> {
let input_trimed = input.trim_end();
let sections: Vec<&str> = input_trimed.split(' ').collect();
if sections.len() != 3 {
bail!("Illegal AA event entry format. Should be `<domain> <operation> <content>`");
}
let sections: Vec<&str> = input_trimed.splitn(3, ' ').collect();
Xynnn007 marked this conversation as resolved.
Show resolved Hide resolved
Ok(Self {
domain: sections[0].into(),
operation: sections[1].into(),
Expand Down Expand Up @@ -168,10 +165,12 @@ impl AAEventlog {

#[cfg(test)]
mod tests {
use std::fs;
use std::{fs, str::FromStr};

use rstest::rstest;

use super::AAEvent;

#[rstest]
#[case("./test_data/aael/AAEL_data_1", b"71563a23b430b8637970b866169052815ef9434056516dc9f78c1b3bfb745cee18a2ca92aa53c8122be5cbe59a100764")]
#[case("./test_data/aael/AAEL_data_2", b"31fa17881137923029b1da5b368e92d8b22b14bbb4deaa360da61fce7aa530bd2f4c59ac7bd27021ef64104ff4dd04f9")]
Expand All @@ -186,4 +185,15 @@ mod tests {
let sum = hex::decode(sum).unwrap();
aael.integrity_check(&sum).unwrap();
}

#[rstest]
#[case("domain operation con tent", AAEvent { domain: "domain".into(), operation: "operation".into(), content: "con tent".into() })]
#[case("domain operation content", AAEvent { domain: "domain".into(), operation: "operation".into(), content: "content".into() })]
#[case("dom ain operation content", AAEvent { domain: "dom".into(), operation: "ain".into(), content: "operation content".into() })]
#[case(r#"github.com/confidential-containers EventWithJSONParams { "key1":"value1\tmore values and 'quotes'\n", "key2": [ "value2", 2, true, null ] }"#, AAEvent { domain: "github.com/confidential-containers".into(), operation: "EventWithJSONParams".into(), content: r#"{ "key1":"value1\tmore values and 'quotes'\n", "key2": [ "value2", 2, true, null ] }"#.into() })]

fn test_parse_log_entry(#[case] entry: &str, #[case] expect: AAEvent) {
let entry = AAEvent::from_str(entry).unwrap();
assert_eq!(entry, expect);
}
}
Loading