|
| 1 | +""" |
| 2 | +Test that MISE_TRUSTED_CONFIG_PATHS is set to the workspace path in container shells. |
| 3 | +
|
| 4 | +The env var is written to both /etc/profile.d/coi-mise-trust.sh (login shells) |
| 5 | +and /etc/bash.bashrc (non-login interactive shells) during session setup, |
| 6 | +so mise automatically trusts config files in the workspace. |
| 7 | +""" |
| 8 | + |
| 9 | +import subprocess |
| 10 | + |
| 11 | + |
| 12 | +def test_mise_trust_env_login_shell(coi_binary, cleanup_containers, workspace_dir): |
| 13 | + """ |
| 14 | + Test MISE_TRUSTED_CONFIG_PATHS is set in a login shell. |
| 15 | +
|
| 16 | + Login shells source /etc/profile.d/*.sh, where coi-mise-trust.sh sets the var. |
| 17 | + """ |
| 18 | + result = subprocess.run( |
| 19 | + [ |
| 20 | + coi_binary, |
| 21 | + "run", |
| 22 | + "--workspace", |
| 23 | + workspace_dir, |
| 24 | + "--", |
| 25 | + "bash", |
| 26 | + "-l", |
| 27 | + "-c", |
| 28 | + "echo TRUST_PATH=$MISE_TRUSTED_CONFIG_PATHS", |
| 29 | + ], |
| 30 | + capture_output=True, |
| 31 | + text=True, |
| 32 | + timeout=180, |
| 33 | + ) |
| 34 | + |
| 35 | + assert result.returncode == 0, f"Run should succeed. stderr: {result.stderr}" |
| 36 | + |
| 37 | + combined = result.stdout + result.stderr |
| 38 | + assert "TRUST_PATH=/workspace" in combined, ( |
| 39 | + f"MISE_TRUSTED_CONFIG_PATHS should be /workspace in login shell. Got:\n{combined}" |
| 40 | + ) |
| 41 | + |
| 42 | + |
| 43 | +def test_mise_trust_env_nonlogin_shell(coi_binary, cleanup_containers, workspace_dir): |
| 44 | + """ |
| 45 | + Test MISE_TRUSTED_CONFIG_PATHS is set in a non-login interactive shell. |
| 46 | +
|
| 47 | + Non-login shells source /etc/bash.bashrc (but NOT /etc/profile.d/), |
| 48 | + where coi also injects the var so it's set before ~/.bashrc activates mise. |
| 49 | + """ |
| 50 | + result = subprocess.run( |
| 51 | + [ |
| 52 | + coi_binary, |
| 53 | + "run", |
| 54 | + "--workspace", |
| 55 | + workspace_dir, |
| 56 | + "--", |
| 57 | + "bash", |
| 58 | + "-c", |
| 59 | + # Source /etc/bash.bashrc explicitly since bash -c is non-interactive |
| 60 | + # and won't source it automatically. This mirrors what happens in |
| 61 | + # interactive non-login shells (like tmux bash). |
| 62 | + ". /etc/bash.bashrc 2>/dev/null; echo TRUST_PATH=$MISE_TRUSTED_CONFIG_PATHS", |
| 63 | + ], |
| 64 | + capture_output=True, |
| 65 | + text=True, |
| 66 | + timeout=180, |
| 67 | + ) |
| 68 | + |
| 69 | + assert result.returncode == 0, f"Run should succeed. stderr: {result.stderr}" |
| 70 | + |
| 71 | + combined = result.stdout + result.stderr |
| 72 | + assert "TRUST_PATH=/workspace" in combined, ( |
| 73 | + f"MISE_TRUSTED_CONFIG_PATHS should be /workspace via bash.bashrc. Got:\n{combined}" |
| 74 | + ) |
| 75 | + |
| 76 | + |
| 77 | +def test_mise_trust_profile_d_file_exists(coi_binary, cleanup_containers, workspace_dir): |
| 78 | + """ |
| 79 | + Test that /etc/profile.d/coi-mise-trust.sh is created with correct content. |
| 80 | + """ |
| 81 | + result = subprocess.run( |
| 82 | + [ |
| 83 | + coi_binary, |
| 84 | + "run", |
| 85 | + "--workspace", |
| 86 | + workspace_dir, |
| 87 | + "--", |
| 88 | + "cat", |
| 89 | + "/etc/profile.d/coi-mise-trust.sh", |
| 90 | + ], |
| 91 | + capture_output=True, |
| 92 | + text=True, |
| 93 | + timeout=180, |
| 94 | + ) |
| 95 | + |
| 96 | + assert result.returncode == 0, f"File should exist. stderr: {result.stderr}" |
| 97 | + |
| 98 | + combined = result.stdout + result.stderr |
| 99 | + assert 'MISE_TRUSTED_CONFIG_PATHS="/workspace"' in combined, ( |
| 100 | + f"Profile.d file should contain the workspace path. Got:\n{combined}" |
| 101 | + ) |
0 commit comments