|
13 | 13 | compact_native_codex_profile_receipt, |
14 | 14 | inspect_native_codex_profile, |
15 | 15 | install_native_codex_profile, |
16 | | - native_codex_app_server_environment, |
| 16 | + native_codex_app_server_shell_policy_args, |
17 | 17 | native_codex_profile_environment, |
18 | 18 | render_native_codex_goal_prompt, |
19 | 19 | ) |
@@ -84,51 +84,47 @@ def test_compact_profile_receipt_excludes_local_paths() -> None: |
84 | 84 | assert "/private" not in rendered |
85 | 85 |
|
86 | 86 |
|
87 | | -def test_app_server_environment_explicitly_admits_only_provider_value( |
88 | | - tmp_path: Path, |
89 | | -) -> None: |
| 87 | +def test_profile_environment_excludes_ambient_provider_values(tmp_path: Path) -> None: |
90 | 88 | profile = _fake_profile(tmp_path) |
91 | 89 | base_env = { |
92 | 90 | "PATH": "/usr/bin:/bin", |
93 | 91 | "CODEX_GOAL_API_KEY": "provider-value", |
94 | 92 | "UNRELATED_PRIVATE_VALUE": "must-not-pass", |
95 | 93 | } |
96 | | - original_base_env = dict(base_env) |
97 | | - |
98 | 94 | profile_env = native_codex_profile_environment(profile, base_env=base_env) |
99 | | - app_server_env = native_codex_app_server_environment( |
100 | | - profile, |
101 | | - provider_env_key="CODEX_GOAL_API_KEY", |
102 | | - base_env=base_env, |
103 | | - ) |
104 | 95 |
|
105 | 96 | assert "CODEX_GOAL_API_KEY" not in profile_env |
106 | 97 | assert "UNRELATED_PRIVATE_VALUE" not in profile_env |
107 | | - assert app_server_env["CODEX_GOAL_API_KEY"] == "provider-value" |
108 | | - assert "UNRELATED_PRIVATE_VALUE" not in app_server_env |
109 | | - assert app_server_env["CODEX_HOME"] == str(profile.codex_home) |
110 | | - assert base_env == original_base_env |
| 98 | + assert profile_env["CODEX_HOME"] == str(profile.codex_home) |
111 | 99 |
|
112 | 100 |
|
113 | | -def test_app_server_environment_rejects_invalid_or_missing_provider_key( |
114 | | - tmp_path: Path, |
115 | | -) -> None: |
116 | | - profile = _fake_profile(tmp_path) |
| 101 | +def test_native_codex_app_server_shell_policy_is_explicit_and_fail_closed() -> None: |
| 102 | + args = native_codex_app_server_shell_policy_args( |
| 103 | + excluded_env_keys=("SECOND_PROVIDER_KEY", "PRIMARY_PROVIDER_KEY"), |
| 104 | + ) |
| 105 | + assert args == ( |
| 106 | + "-c", |
| 107 | + 'shell_environment_policy.inherit="core"', |
| 108 | + "-c", |
| 109 | + "shell_environment_policy.ignore_default_excludes=false", |
| 110 | + "-c", |
| 111 | + ( |
| 112 | + 'shell_environment_policy.include_only=["HOME", "LANG", "LC_ALL", ' |
| 113 | + '"LC_CTYPE", "LOGNAME", "PATH", "SHELL", "SSL_CERT_DIR", ' |
| 114 | + '"SSL_CERT_FILE", "TERM", "TMPDIR", "TZ", "USER"]' |
| 115 | + ), |
| 116 | + "-c", |
| 117 | + 'shell_environment_policy.exclude=["PRIMARY_PROVIDER_KEY", "SECOND_PROVIDER_KEY"]', |
| 118 | + ) |
117 | 119 |
|
118 | | - with pytest.raises(ValueError, match="provider_env_key"): |
119 | | - native_codex_app_server_environment( |
120 | | - profile, |
121 | | - provider_env_key="invalid-key", |
122 | | - base_env={"invalid-key": "value"}, |
123 | | - ) |
124 | | - with pytest.raises( |
125 | | - NativeCodexProfileError, |
126 | | - match="provider_environment_value_missing:CODEX_GOAL_API_KEY", |
127 | | - ): |
128 | | - native_codex_app_server_environment( |
129 | | - profile, |
130 | | - provider_env_key="CODEX_GOAL_API_KEY", |
131 | | - base_env={"PATH": "/usr/bin:/bin"}, |
| 120 | + |
| 121 | +@pytest.mark.parametrize("excluded_env_key", ("", "invalid-key", "WITH SPACE")) |
| 122 | +def test_native_codex_app_server_shell_policy_rejects_unsafe_keys( |
| 123 | + excluded_env_key: str, |
| 124 | +) -> None: |
| 125 | + with pytest.raises(ValueError, match="excluded_env_keys"): |
| 126 | + native_codex_app_server_shell_policy_args( |
| 127 | + excluded_env_keys=(excluded_env_key,), |
132 | 128 | ) |
133 | 129 |
|
134 | 130 |
|
|
0 commit comments