Skip to content

Commit

Permalink
update added tests
Browse files Browse the repository at this point in the history
Signed-off-by: Firas Ghanmi <[email protected]>
  • Loading branch information
fghanmi committed Sep 22, 2024
1 parent 435f7af commit 5b62621
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions tuftool/tests/root_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,61 +475,67 @@ fn set_version_root() {
fn create_root_encrypted_key() {
let out_dir = TempDir::new().unwrap();
let root_json = out_dir.path().join("root.json");
let key_1 = test_utils::test_data().join("snakeoil_3.pem");
let key = test_utils::test_data().join("snakeoil_3.pem");

// Password used to decrypt key
let password = "test_password";
// Create and initialise root.json
initialize_root_json(root_json.to_str().unwrap());
// Add key for all roles
add_key_root(
&vec![key_1.to_str().unwrap()],
&vec![key.to_str().unwrap()],
root_json.to_str().unwrap(),
Some(password),
);
add_key_timestamp(
key_1.to_str().unwrap(),
key.to_str().unwrap(),
root_json.to_str().unwrap(),
Some(password),
);
add_key_snapshot(
key_1.to_str().unwrap(),
key.to_str().unwrap(),
root_json.to_str().unwrap(),
Some(password),
);
add_key_targets(
key_1.to_str().unwrap(),
key.to_str().unwrap(),
root_json.to_str().unwrap(),
Some(password),
);

// Sign root.json
sign_root_json(
key_1.to_str().unwrap(),
key.to_str().unwrap(),
root_json.to_str().unwrap(),
Some(password),
);
assert_eq!(get_sign_len(root_json.to_str().unwrap()), 1);
}

#[test]
// Add encryped key with an invalid password
// Add encryped key with an invalid password
fn create_root_encrypted_key_invalid_password() {
let out_dir = TempDir::new().unwrap();
let root_json = out_dir.path().join("root.json");
let key_1 = test_utils::test_data().join("snakeoil_3.pem");
let key = test_utils::test_data().join("snakeoil_3.pem");

// Invalid password
let password = "invalid_password";
// Create and initialise root.json
initialize_root_json(root_json.to_str().unwrap());
// Add key to root role
let mut cmd = Command::cargo_bin("tuftool").unwrap();
cmd.args(["root", "add-key", root_json.to_str().unwrap(), "--role", "root"])
.arg("-k").arg(key_1.to_str().unwrap());
cmd.args([
"root",
"add-key",
root_json.to_str().unwrap(),
"--role",
"root",
])
.arg("-k")
.arg(key.to_str().unwrap());
if !password.is_empty() {
cmd.args(["--password", password]);
}
cmd.assert().failure();

}

0 comments on commit 5b62621

Please sign in to comment.