Skip to content

Commit 1b8cd8b

Browse files
committed
config: Skip validation of keylime_dir during tests
When running tests on machines where /var/lib/keylime does not exist (e.g. build machines where keylime is not installed), the tests would fail on the check if keylime_dir exists. Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
1 parent cf6c4f0 commit 1b8cd8b

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

keylime-agent/src/config.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -608,51 +608,54 @@ fn config_translate_keywords(
608608
Some(ref dir) => {
609609
if dir.is_empty() {
610610
match &config.agent.keylime_dir {
611-
s => s.clone(),
612-
_ => DEFAULT_KEYLIME_DIR.to_string(),
611+
s => Path::new(s),
612+
_ => Path::new(DEFAULT_KEYLIME_DIR),
613613
}
614614
} else {
615-
dir.to_string()
615+
Path::new(dir)
616616
}
617617
}
618618
None => match &config.agent.keylime_dir {
619-
s => s.clone(),
620-
_ => DEFAULT_KEYLIME_DIR.to_string(),
619+
s => Path::new(s),
620+
_ => Path::new(DEFAULT_KEYLIME_DIR),
621621
},
622622
};
623623

624624
// Validate that keylime_dir exists
625-
let keylime_dir = Path::new(&keylime_dir).canonicalize().map_err(|e| {
625+
#[cfg(not(test))]
626+
let keylime_dir = &keylime_dir.canonicalize().map_err(|e| {
626627
Error::Configuration(format!(
627-
"Path {keylime_dir} set in keylime_dir configuration option not found: {e}"
628+
"Path {} set in keylime_dir configuration option not found: {}",
629+
keylime_dir.display(),
630+
e
628631
))
629632
})?;
630633

631634
let mut agent_data_path = config_get_file_path(
632635
"agent_data_path",
633636
&config.agent.agent_data_path,
634-
&keylime_dir,
637+
keylime_dir,
635638
DEFAULT_AGENT_DATA_PATH,
636639
);
637640

638641
let mut server_key = config_get_file_path(
639642
"server_key",
640643
&config.agent.server_key,
641-
&keylime_dir,
644+
keylime_dir,
642645
DEFAULT_SERVER_KEY,
643646
);
644647

645648
let mut server_cert = config_get_file_path(
646649
"server_cert",
647650
&config.agent.server_cert,
648-
&keylime_dir,
651+
keylime_dir,
649652
DEFAULT_SERVER_CERT,
650653
);
651654

652655
let mut trusted_client_ca = config_get_file_path(
653656
"trusted_client_ca",
654657
&config.agent.trusted_client_ca,
655-
&keylime_dir,
658+
keylime_dir,
656659
DEFAULT_TRUSTED_CLIENT_CA,
657660
);
658661

@@ -686,7 +689,7 @@ fn config_translate_keywords(
686689
let mut revocation_cert = config_get_file_path(
687690
"revocation_cert",
688691
&config.agent.revocation_cert,
689-
&keylime_dir,
692+
keylime_dir,
690693
&format!("secure/unzipped/{DEFAULT_REVOCATION_CERT}"),
691694
);
692695

0 commit comments

Comments
 (0)