()
| 580 | |
| 581 | #[test] |
| 582 | fn test_tmpfiles_d_translation() -> anyhow::Result<()> { |
| 583 | // Prepare a minimal rootfs as playground. |
| 584 | let rootfs = &newroot()?; |
| 585 | let userdb = &mock_userdb(); |
| 586 | |
| 587 | let mut db = DirBuilder::new(); |
| 588 | db.recursive(true); |
| 589 | db.mode(0o755); |
| 590 | |
| 591 | rootfs.write( |
| 592 | Path::new(TMPFILESD).join("systemd.conf"), |
| 593 | indoc::indoc! { r#" |
| 594 | d /var/lib 0755 - - - |
| 595 | d /var/lib/private 0700 root root - |
| 596 | d /var/log/private 0700 root root - |
| 597 | "#}, |
| 598 | )?; |
| 599 | |
| 600 | // Also test /etc/tmpfiles.d (user-provided configs) |
| 601 | rootfs.create_dir_all(ETC_TMPFILESD)?; |
| 602 | rootfs.write( |
| 603 | Path::new(ETC_TMPFILESD).join("user.conf"), |
| 604 | "d /var/lib/user 0755 root root - -\n", |
| 605 | )?; |
| 606 | |
| 607 | // Add test content. |
| 608 | rootfs.ensure_dir_with("var/lib/systemd", &db)?; |
| 609 | rootfs.ensure_dir_with("var/lib/private", &db)?; |
| 610 | rootfs.ensure_dir_with("var/lib/nfs", &db)?; |
| 611 | rootfs.ensure_dir_with("var/lib/user", &db)?; |
| 612 | let global_rwx = Permissions::from_mode(0o777); |
| 613 | rootfs.ensure_dir_with("var/lib/test/nested", &db).unwrap(); |
| 614 | rootfs.set_permissions("var/lib/test", global_rwx.clone())?; |
| 615 | rootfs.set_permissions("var/lib/test/nested", global_rwx)?; |
| 616 | rootfs.symlink("../", "var/lib/test/nested/symlink")?; |
| 617 | rootfs.symlink_contents("/var/lib/foo", "var/lib/test/absolute-symlink")?; |
| 618 | |
| 619 | var_to_tmpfiles(rootfs, userdb, userdb).unwrap(); |
| 620 | |
| 621 | // This is the first run |
| 622 | let mut tmp_gen = BootcTmpfilesGeneration(0); |
| 623 | let autovar_path = &tmp_gen.path(); |
| 624 | assert!(rootfs.try_exists(autovar_path).unwrap()); |
| 625 | let entries: Vec<String> = rootfs |
| 626 | .read_to_string(autovar_path) |
| 627 | .unwrap() |
| 628 | .lines() |
| 629 | .map(|s| s.to_owned()) |
| 630 | .collect(); |
| 631 | let expected = &[ |
| 632 | "L /var/lib/test/absolute-symlink - - - - /var/lib/foo", |
| 633 | "L /var/lib/test/nested/symlink - - - - ../", |
| 634 | "d /var/lib/nfs 0755 testuser testgroup - -", |
| 635 | "d /var/lib/systemd 0755 testuser testgroup - -", |
| 636 | "d /var/lib/test 0777 testuser testgroup - -", |
| 637 | "d /var/lib/test/nested 0777 testuser testgroup - -", |
| 638 | ]; |
| 639 | similar_asserts::assert_eq!(entries, expected); |
nothing calls this directly
no test coverage detected