| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
use crate::cli::{Invocation, Secret}; |
| 10 |
use crate::run::Stage; |
| 11 |
|
| 12 |
use super::account::{ |
| 13 |
HOME_MODE, HOME_PARENT, LOGIN_SHELL, SSH_DIR_MODE, SSH_FILE_MODE, hash_password, passwd_ids, |
| 14 |
shell_is_registered, video_group_line, |
| 15 |
}; |
| 16 |
use super::encryption::{Encryption, enroll_plan}; |
| 17 |
use super::image::{relabel_stages, update_timer_stages, updates_scheduled}; |
| 18 |
use super::target::{in_target, stateroot_var}; |
| 19 |
use super::timezone::timezone_stages; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#[derive(Debug, Default)] |
| 29 |
pub(super) struct HomeSeeds<'a> { |
| 30 |
|
| 31 |
pub(super) pubkey: Option<&'a str>, |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
pub(super) screens: &'a [crate::display::Output], |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
pub(super) fn configure_plan( |
| 50 |
hostname: &str, |
| 51 |
username: &str, |
| 52 |
password: &str, |
| 53 |
seeds: &HomeSeeds<'_>, |
| 54 |
locate_timezone: bool, |
| 55 |
encryption: Option<&Encryption<'_>>, |
| 56 |
root: &str, |
| 57 |
) -> Result<Vec<Stage>, String> { |
| 58 |
let var = stateroot_var(root)?; |
| 59 |
|
| 60 |
let home = format!("{var}/home/{username}"); |
| 61 |
|
| 62 |
let installed_home = format!("{HOME_PARENT}/{username}"); |
| 63 |
|
| 64 |
let hash = hash_password(password)?; |
| 65 |
|
| 66 |
let ids_root = root.to_string(); |
| 67 |
let ids_user = username.to_string(); |
| 68 |
let ids_home = home.clone(); |
| 69 |
|
| 70 |
let group_root = root.to_string(); |
| 71 |
let group_file = format!("{root}/etc/group"); |
| 72 |
|
| 73 |
let useradd_root = root.to_string(); |
| 74 |
let useradd_user = username.to_string(); |
| 75 |
let useradd_home = installed_home.clone(); |
| 76 |
|
| 77 |
let mut stages = vec![ |
| 78 |
|
| 79 |
|
| 80 |
Stage::Resolve { |
| 81 |
invocation: Invocation::new("cat").arg(format!("{root}/etc/shells")), |
| 82 |
then: Box::new(move |listing| { |
| 83 |
shell_is_registered(listing, LOGIN_SHELL)?; |
| 84 |
Ok(Vec::new()) |
| 85 |
}), |
| 86 |
}, |
| 87 |
Stage::Run( |
| 88 |
Invocation::new("systemd-firstboot") |
| 89 |
.arg(format!("--root={root}")) |
| 90 |
.arg(format!("--hostname={hostname}")) |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
.arg("--force"), |
| 100 |
), |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
Stage::Resolve { |
| 111 |
invocation: Invocation::new("cat").arg(format!("{group_root}/etc/group")), |
| 112 |
then: Box::new(move |etc_group| { |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
let lib_group = std::fs::read_to_string(format!("{group_root}/usr/lib/group")) |
| 119 |
.unwrap_or_default(); |
| 120 |
let Some(line) = video_group_line(etc_group, &lib_group) else { |
| 121 |
return Ok(Vec::new()); |
| 122 |
}; |
| 123 |
Ok(vec![Stage::Run( |
| 124 |
Invocation::new("tee") |
| 125 |
.arg("-a") |
| 126 |
.arg(&group_file) |
| 127 |
.stdin(Secret::new(line)), |
| 128 |
)]) |
| 129 |
}), |
| 130 |
}, |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
Stage::Resolve { |
| 167 |
invocation: Invocation::new("cat").arg(format!("{useradd_root}/etc/passwd")), |
| 168 |
then: Box::new(move |listing| { |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
if passwd_ids(listing, &useradd_user).is_ok() { |
| 180 |
return Ok(Vec::new()); |
| 181 |
} |
| 182 |
Ok(vec![Stage::Run( |
| 183 |
in_target(&useradd_root, "useradd") |
| 184 |
.arg("--no-create-home") |
| 185 |
.args(["--home-dir", &useradd_home]) |
| 186 |
.args(["--shell", LOGIN_SHELL]) |
| 187 |
.args(["--groups", "wheel,video"]) |
| 188 |
.arg(&useradd_user), |
| 189 |
)]) |
| 190 |
}), |
| 191 |
}, |
| 192 |
|
| 193 |
Stage::Run(Invocation::new("mkdir").args(["-p", &home])), |
| 194 |
|
| 195 |
|
| 196 |
Stage::Run( |
| 197 |
Invocation::new("cp") |
| 198 |
.arg("-a") |
| 199 |
.arg(format!("{root}/etc/skel/.")) |
| 200 |
.arg(&home), |
| 201 |
), |
| 202 |
]; |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
if let Some(key) = seeds.pubkey { |
| 210 |
let ssh_dir = format!("{home}/.ssh"); |
| 211 |
let authorized = format!("{ssh_dir}/authorized_keys"); |
| 212 |
stages.extend([ |
| 213 |
Stage::Run(Invocation::new("mkdir").args(["-p", &ssh_dir])), |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
Stage::Run( |
| 230 |
Invocation::new("tee") |
| 231 |
.arg(&authorized) |
| 232 |
.stdin(Secret::new(format!("{key}\n"))), |
| 233 |
), |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
Stage::Run(Invocation::new("chmod").args([SSH_DIR_MODE, &ssh_dir])), |
| 239 |
Stage::Run(Invocation::new("chmod").args([SSH_FILE_MODE, &authorized])), |
| 240 |
]); |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
if !seeds.screens.is_empty() { |
| 254 |
let file = format!("{home}/{}", crate::display::FILE); |
| 255 |
let dir = file |
| 256 |
.rsplit_once('/') |
| 257 |
.map_or_else(|| home.clone(), |(parent, _)| parent.to_string()); |
| 258 |
stages.extend([ |
| 259 |
Stage::Run(Invocation::new("mkdir").args(["-p", &dir])), |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
Stage::Run( |
| 266 |
Invocation::new("tee") |
| 267 |
.arg(&file) |
| 268 |
.stdin(Secret::new(crate::display::config_file(seeds.screens))), |
| 269 |
), |
| 270 |
]); |
| 271 |
} |
| 272 |
|
| 273 |
stages.extend([ |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
Stage::Resolve { |
| 283 |
invocation: Invocation::new("cat").arg(format!("{ids_root}/etc/passwd")), |
| 284 |
then: Box::new(move |listing| { |
| 285 |
let ids = passwd_ids(listing, &ids_user)?; |
| 286 |
Ok(vec![ |
| 287 |
Stage::Run(Invocation::new("chown").args(["-R", &ids, &ids_home])), |
| 288 |
Stage::Run(Invocation::new("chmod").args([HOME_MODE, &ids_home])), |
| 289 |
]) |
| 290 |
}), |
| 291 |
}, |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
Stage::Run( |
| 297 |
in_target(root, "chpasswd") |
| 298 |
.arg("--encrypted") |
| 299 |
.stdin(Secret::new(format!("{username}:{hash}\n"))), |
| 300 |
), |
| 301 |
]); |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
stages.extend(timezone_stages(locate_timezone, root)); |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
stages.extend(update_timer_stages(updates_scheduled(), root)); |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
stages.extend(relabel_stages(root)); |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
if let Some(encryption) = encryption { |
| 330 |
stages.extend(enroll_plan( |
| 331 |
encryption.partition, |
| 332 |
encryption.passphrase, |
| 333 |
encryption.recovery, |
| 334 |
)); |
| 335 |
} |
| 336 |
|
| 337 |
Ok(stages) |
| 338 |
} |
| 339 |
#[cfg(test)] |
| 340 |
mod tests { |
| 341 |
use super::super::encryption::Encryption; |
| 342 |
use super::super::fixtures::{ |
| 343 |
DEPLOYMENT, ED25519_BODY, command_starting, configured, runs, shown, |
| 344 |
}; |
| 345 |
use super::super::timezone::GEO_HOST; |
| 346 |
use super::*; |
| 347 |
use crate::run::Stage; |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
#[test] |
| 353 |
fn an_unencrypted_configure_enrolls_nothing() { |
| 354 |
let shown = configured(); |
| 355 |
for line in &shown { |
| 356 |
assert!(!line.contains("cryptenroll"), "{line}"); |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 360 |
#[test] |
| 361 |
fn an_encrypted_configure_enrolls_last() { |
| 362 |
let encryption = Encryption { |
| 363 |
partition: "/dev/sda3", |
| 364 |
passphrase: "opensesame", |
| 365 |
recovery: "eight words here", |
| 366 |
}; |
| 367 |
let stages = configure_plan( |
| 368 |
"workshop", |
| 369 |
"max", |
| 370 |
"hunter2", |
| 371 |
&HomeSeeds::default(), |
| 372 |
false, |
| 373 |
Some(&encryption), |
| 374 |
DEPLOYMENT, |
| 375 |
) |
| 376 |
.expect("a well-formed deployment path"); |
| 377 |
let shown = shown(stages); |
| 378 |
|
| 379 |
assert_eq!( |
| 380 |
shown.iter().filter(|l| l.contains("cryptenroll")).count(), |
| 381 |
2, |
| 382 |
"{shown:#?}" |
| 383 |
); |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
assert!( |
| 389 |
shown[shown.len() - 2..] |
| 390 |
.iter() |
| 391 |
.all(|line| line.contains("cryptenroll")), |
| 392 |
"the configuration does not end with the enrollment: {shown:#?}" |
| 393 |
); |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
#[test] |
| 400 |
fn firstboot_forces_over_the_images_baked_in_hostname() { |
| 401 |
let firstboot = command_starting("systemd-firstboot"); |
| 402 |
|
| 403 |
assert!(firstboot.contains("--hostname=workshop"), "{firstboot}"); |
| 404 |
assert!(firstboot.contains("--force"), "{firstboot}"); |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
#[test] |
| 411 |
fn configuration_targets_the_deployment_not_the_mountpoint() { |
| 412 |
for line in configured() { |
| 413 |
|
| 414 |
if line.starts_with("bootc") || line.starts_with("umount") { |
| 415 |
continue; |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
if line.starts_with("sh -c") { |
| 423 |
continue; |
| 424 |
} |
| 425 |
assert!( |
| 426 |
line.contains("/ostree/deploy/"), |
| 427 |
"configured the sysroot instead of the deployment: {line}" |
| 428 |
); |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
#[test] |
| 436 |
fn an_install_that_was_not_asked_does_not_look_anything_up() { |
| 437 |
for line in configured() { |
| 438 |
assert!(!line.contains("curl"), "network call unasked: {line}"); |
| 439 |
assert!(!line.contains(GEO_HOST), "network call unasked: {line}"); |
| 440 |
assert!(!line.contains("--timezone"), "timezone unasked: {line}"); |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
#[test] |
| 445 |
fn a_located_install_asks_and_bounds_the_asking() { |
| 446 |
let stages = configure_plan( |
| 447 |
"workshop", |
| 448 |
"max", |
| 449 |
"hunter2", |
| 450 |
&HomeSeeds::default(), |
| 451 |
true, |
| 452 |
None, |
| 453 |
DEPLOYMENT, |
| 454 |
) |
| 455 |
.expect("a well-formed deployment path"); |
| 456 |
let shown = shown(stages); |
| 457 |
|
| 458 |
let lookup = shown |
| 459 |
.iter() |
| 460 |
.find(|line| line.contains(GEO_HOST)) |
| 461 |
.expect("the box was ticked and nothing asks"); |
| 462 |
|
| 463 |
assert!(lookup.contains("--max-time"), "{lookup}"); |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
#[test] |
| 469 |
fn a_key_becomes_an_authorized_keys_with_the_modes_sshd_demands() { |
| 470 |
let key = &format!("ssh-ed25519 {ED25519_BODY} max@fw13"); |
| 471 |
let stages = configure_plan( |
| 472 |
"workshop", |
| 473 |
"max", |
| 474 |
"hunter2", |
| 475 |
&HomeSeeds { |
| 476 |
pubkey: Some(key), |
| 477 |
..HomeSeeds::default() |
| 478 |
}, |
| 479 |
false, |
| 480 |
None, |
| 481 |
DEPLOYMENT, |
| 482 |
) |
| 483 |
.unwrap(); |
| 484 |
let shown = shown(stages); |
| 485 |
let joined = shown.join("\n"); |
| 486 |
|
| 487 |
assert!(joined.contains(".ssh"), "{joined}"); |
| 488 |
assert!(joined.contains("authorized_keys"), "{joined}"); |
| 489 |
assert!( |
| 490 |
joined.contains(&format!("chmod {SSH_DIR_MODE}")), |
| 491 |
"the directory mode is missing: {joined}", |
| 492 |
); |
| 493 |
assert!( |
| 494 |
joined.contains(&format!("chmod {SSH_FILE_MODE}")), |
| 495 |
"the file mode is missing: {joined}", |
| 496 |
); |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
assert!( |
| 501 |
!joined.contains("AAAAC3NzaC1lZDI1NTE5"), |
| 502 |
"the key body reached a rendered command line: {joined}", |
| 503 |
); |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
#[test] |
| 511 |
fn the_key_is_written_before_the_recursive_chown_that_owns_it() { |
| 512 |
let key = &format!("ssh-ed25519 {ED25519_BODY}"); |
| 513 |
let stages = configure_plan( |
| 514 |
"workshop", |
| 515 |
"max", |
| 516 |
"hunter2", |
| 517 |
&HomeSeeds { |
| 518 |
pubkey: Some(key), |
| 519 |
..HomeSeeds::default() |
| 520 |
}, |
| 521 |
false, |
| 522 |
None, |
| 523 |
DEPLOYMENT, |
| 524 |
) |
| 525 |
.unwrap(); |
| 526 |
let shown = shown(stages); |
| 527 |
|
| 528 |
let wrote = shown |
| 529 |
.iter() |
| 530 |
.position(|line| line.contains("authorized_keys")) |
| 531 |
.expect("the plan writes the key"); |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
let discovers = shown |
| 537 |
.iter() |
| 538 |
.rposition(|line| line.contains("etc/passwd")) |
| 539 |
.expect("the plan discovers the numeric ids"); |
| 540 |
assert!( |
| 541 |
wrote < discovers, |
| 542 |
"the key is written after ownership is settled: {shown:#?}", |
| 543 |
); |
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
#[test] |
| 550 |
fn no_key_writes_no_ssh_directory() { |
| 551 |
let joined = configure_plan( |
| 552 |
"workshop", |
| 553 |
"max", |
| 554 |
"hunter2", |
| 555 |
&HomeSeeds::default(), |
| 556 |
false, |
| 557 |
None, |
| 558 |
DEPLOYMENT, |
| 559 |
) |
| 560 |
.unwrap() |
| 561 |
.iter() |
| 562 |
.map(Stage::display) |
| 563 |
.collect::<Vec<_>>() |
| 564 |
.join("\n"); |
| 565 |
assert!(!joined.contains("authorized_keys"), "{joined}"); |
| 566 |
assert!(!joined.contains(".ssh"), "{joined}"); |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
fn screen(name: &str, scale: f64) -> crate::display::Output { |
| 572 |
crate::display::Output { |
| 573 |
name: name.into(), |
| 574 |
make: String::new(), |
| 575 |
model: String::new(), |
| 576 |
serial: String::new(), |
| 577 |
active: true, |
| 578 |
dpms: true, |
| 579 |
focused: false, |
| 580 |
rect: crate::display::Rectangle::default(), |
| 581 |
scale, |
| 582 |
transform: "normal".into(), |
| 583 |
current_mode: None, |
| 584 |
modes: Vec::new(), |
| 585 |
} |
| 586 |
} |
| 587 |
|
| 588 |
fn plan_with_screens(screens: &[crate::display::Output]) -> Vec<String> { |
| 589 |
configure_plan( |
| 590 |
"workshop", |
| 591 |
"max", |
| 592 |
"hunter2", |
| 593 |
&HomeSeeds { |
| 594 |
screens, |
| 595 |
..HomeSeeds::default() |
| 596 |
}, |
| 597 |
false, |
| 598 |
None, |
| 599 |
DEPLOYMENT, |
| 600 |
) |
| 601 |
.expect("a well-formed deployment path") |
| 602 |
.iter() |
| 603 |
.map(Stage::display) |
| 604 |
.collect() |
| 605 |
} |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
#[test] |
| 611 |
fn a_detected_panel_seeds_the_per_user_display_config() { |
| 612 |
let shown = plan_with_screens(&[screen("eDP-1", 1.25)]); |
| 613 |
let joined = shown.join("\n"); |
| 614 |
assert!(joined.contains(crate::display::FILE), "{joined}"); |
| 615 |
|
| 616 |
let made = shown |
| 617 |
.iter() |
| 618 |
.position(|line| line.contains("mkdir") && line.contains("sway/config.d")) |
| 619 |
.expect("the plan makes the directory"); |
| 620 |
let wrote = shown |
| 621 |
.iter() |
| 622 |
.position(|line| line.contains(crate::display::FILE)) |
| 623 |
.expect("the plan writes the file"); |
| 624 |
assert!(made < wrote, "{shown:#?}"); |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
#[test] |
| 632 |
fn the_seed_is_written_before_the_recursive_chown_that_owns_it() { |
| 633 |
let shown = plan_with_screens(&[screen("eDP-1", 1.25)]); |
| 634 |
let wrote = shown |
| 635 |
.iter() |
| 636 |
.position(|line| line.contains(crate::display::FILE)) |
| 637 |
.expect("the plan writes the file"); |
| 638 |
|
| 639 |
|
| 640 |
let discovers = shown |
| 641 |
.iter() |
| 642 |
.rposition(|line| line.contains("etc/passwd")) |
| 643 |
.expect("the plan discovers the numeric ids"); |
| 644 |
assert!(wrote < discovers, "{shown:#?}"); |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
#[test] |
| 651 |
fn no_detected_panel_seeds_nothing() { |
| 652 |
let joined = plan_with_screens(&[]).join("\n"); |
| 653 |
assert!(!joined.contains("50-display.conf"), "{joined}"); |
| 654 |
assert!(!joined.contains("sway"), "{joined}"); |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
#[test] |
| 665 |
fn a_machine_with_no_built_in_panel_still_seeds_its_screen() { |
| 666 |
let joined = plan_with_screens(&[screen("DP-3", 1.0)]).join("\n"); |
| 667 |
assert!(joined.contains(crate::display::FILE), "{joined}"); |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
#[test] |
| 673 |
fn the_screens_are_seeded_in_a_single_write() { |
| 674 |
let shown = plan_with_screens(&[screen("eDP-1", 1.75), screen("DP-3", 1.0)]); |
| 675 |
let writes = shown |
| 676 |
.iter() |
| 677 |
.filter(|line| line.contains(crate::display::FILE)) |
| 678 |
.count(); |
| 679 |
assert_eq!(writes, 1, "{shown:#?}"); |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
#[test] |
| 686 |
fn the_account_is_not_created_twice() { |
| 687 |
let stages = configure_plan( |
| 688 |
"workshop", |
| 689 |
"max", |
| 690 |
"hunter2", |
| 691 |
&HomeSeeds::default(), |
| 692 |
false, |
| 693 |
None, |
| 694 |
DEPLOYMENT, |
| 695 |
) |
| 696 |
.expect("a well-formed deployment path"); |
| 697 |
|
| 698 |
let gate = stages |
| 699 |
.into_iter() |
| 700 |
.find_map(|stage| match stage { |
| 701 |
Stage::Resolve { invocation, then } if invocation.display().contains("passwd") => { |
| 702 |
Some(then) |
| 703 |
} |
| 704 |
_ => None, |
| 705 |
}) |
| 706 |
.expect("the plan checks the passwd file before creating the account"); |
| 707 |
|
| 708 |
|
| 709 |
let existing = "root:x:0:0::/root:/bin/bash\nmax:x:1000:1000::/var/home/max:/usr/bin/nu\n"; |
| 710 |
assert!(gate(existing).expect("a verdict").is_empty()); |
| 711 |
} |
| 712 |
|
| 713 |
#[test] |
| 714 |
fn the_account_is_created_when_it_is_missing() { |
| 715 |
let shown = configured(); |
| 716 |
assert!(shown.iter().any(|line| runs(line, "useradd")), "{shown:#?}"); |
| 717 |
} |
| 718 |
} |
| 719 |
|