Skip to content

Commit 2d57ea0

Browse files
committed
fix: dev
1 parent 9ff34cc commit 2d57ea0

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/test_utils/git/docker.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,40 @@ impl DockerGit {
2929
}
3030

3131
fn run_docker_command(&self, test_dir: &TestDir, script: &str) -> io::Result<String> {
32-
let args = [
32+
// Use current user on Unix systems, root on others
33+
#[cfg(unix)]
34+
let user_args = {
35+
let uid = unsafe { libc::getuid() };
36+
let gid = unsafe { libc::getgid() };
37+
vec!["--user".to_string(), format!("{uid}:{gid}")]
38+
};
39+
#[cfg(not(unix))]
40+
let user_args: Vec<String> = vec![];
41+
42+
let mut args = vec![
3343
"run",
3444
"--rm",
3545
"--security-opt=no-new-privileges", // Strict mode: remove permissive layers
3646
"--cap-drop=ALL", // Strict mode: drop all capabilities
47+
];
48+
49+
// Add user args if present
50+
for arg in &user_args {
51+
args.push(arg);
52+
}
53+
54+
let volume_mount = format!("{}:/workspace", test_dir.path().display());
55+
args.extend([
3756
"--entrypoint",
3857
"sh",
3958
"-v",
40-
&format!("{}:/workspace", test_dir.path().display()),
59+
&volume_mount,
4160
"-w",
4261
"/workspace",
4362
"alpine/git:latest",
4463
"-c",
4564
script,
46-
];
65+
]);
4766

4867
#[cfg(test)]
4968
if let Err(e) = validate_docker_args(&args) {
@@ -200,15 +219,13 @@ mod tests {
200219

201220
#[test]
202221
#[ignore = "docker"]
203-
#[cfg(target_os = "linux")]
204222
fn test_docker_git_init() {
205223
let (dir, _docker_git) = setup_initialized_repo();
206224
assert!(dir.path().join(".git").exists());
207225
}
208226

209227
#[test]
210228
#[ignore = "docker"]
211-
#[cfg(target_os = "linux")]
212229
fn test_docker_git_commit() {
213230
let (dir, docker_git) = setup_initialized_repo();
214231
dir.create_file("test.txt", "test content").unwrap();
@@ -219,7 +236,6 @@ mod tests {
219236

220237
#[test]
221238
#[ignore = "docker"]
222-
#[cfg(target_os = "linux")]
223239
fn test_docker_git_tag() {
224240
let (dir, docker_git) = setup_repo_with_commit();
225241
docker_git
@@ -229,7 +245,6 @@ mod tests {
229245

230246
#[test]
231247
#[ignore = "docker"]
232-
#[cfg(target_os = "linux")]
233248
fn test_docker_git_integration() {
234249
let (dir, docker_git) = setup_repo_with_commit();
235250
docker_git

0 commit comments

Comments
 (0)