in libazureinit/src/provision/user.rs [215:239]
fn test_passwordless_sudo_configured_successful() {
let dir = tempdir().unwrap();
let path = dir.path().join("sudoers_file");
let path_str = path.to_str().unwrap();
let _user_insecure = User::new("azureuser", []);
let ret =
add_user_for_passwordless_sudo(&_user_insecure.name, path_str);
assert!(ret.is_ok());
assert!(
fs::metadata(path.clone()).is_ok(),
"{path_str} file not created"
);
let mode = fs::metadata(path_str)
.expect("Sudoer file not created")
.permissions()
.mode();
assert_eq!(mode & 0o777, 0o600, "Permissions are not set properly");
assert_eq!(
fs::read_to_string(path).unwrap(),
"azureuser ALL=(ALL) NOPASSWD: ALL\n",
"Contents of the file are not as expected"
);
}