Skip to content

Commit

Permalink
[antlir2][tests] add idmap test to basic rust test
Browse files Browse the repository at this point in the history
Summary:
As I start to enable more rootless test execution, it's important to exercise
the tests-for-the-tests that we have here.
This diff makes sure that in the test container `root` is id `0` and `antlir`
is `1000`, as set in the `antlir` uidmap.

Test Plan:
```
❯ buck2 targets fbcode//antlir/antlir2/testing/tests: | grep rootless | xargs buck2 test
Buck UI: https://www.internalfb.com/buck2/0f869c2e-df9e-4a80-8956-813d1c69ad71
Test UI: https://www.internalfb.com/intern/testinfra/testrun/10133099228309166
Tests finished: Pass 52. Fail 0. Fatal 0. Skip 0. Build failure 0
```

Reviewed By: justintrudell

Differential Revision: D68905617

fbshipit-source-id: 36872d9c60b5c3ada03f00defbb8daa17fa1aa75
  • Loading branch information
vmagro authored and facebook-github-bot committed Jan 30, 2025
1 parent dccabc8 commit 9c16c93
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions antlir/antlir2/testing/tests/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ image.layer(
"slow-unit.service",
target = "default.target",
),
feature.user_add(
home_dir = "/",
primary_group = "antlir",
shell = "/bin/bash",
uidmap = "antlir",
username = "antlir",
),
feature.group_add(
groupname = "antlir",
uidmap = "antlir",
),
feature.install_text(
dst = "/antlir.txt",
group = "antlir",
text = "I am antlir\n",
user = "antlir",
),
],
)

Expand Down
12 changes: 12 additions & 0 deletions antlir/antlir2/testing/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

use std::os::unix::fs::MetadataExt;
use std::path::Path;

use nix::unistd::getuid;
Expand Down Expand Up @@ -55,3 +56,14 @@ fn tmpfs_tmp() {
fn tmpfs_run() {
test_tmpfs("/run");
}

#[test]
fn id_mapping() {
let meta = std::fs::metadata("/").expect("failed to stat /");
assert_eq!(0, meta.uid());
assert_eq!(0, meta.gid());

let meta = std::fs::metadata("/antlir.txt").expect("failed to stat /antlir.txt");
assert_eq!(1000, meta.uid());
assert_eq!(1000, meta.gid());
}

0 comments on commit 9c16c93

Please sign in to comment.