|
4 | 4 | //! CLI command implementations. |
5 | 5 |
|
6 | 6 | pub use crate::commands::common::{ |
7 | | - PolicyGetView, parse_credential_expiry_cli_value, parse_env_pairs, parse_key_value_pairs, |
8 | | - parse_secret_material_env_pairs, warn_credential_env_vars, |
| 7 | + PolicyGetView, parse_credential_expiry_cli_value, parse_env_from_pairs, parse_env_pairs, |
| 8 | + parse_key_value_pairs, parse_secret_material_env_pairs, warn_credential_env_vars, |
9 | 9 | }; |
10 | 10 | use crate::commands::common::{ |
11 | 11 | ProvisioningDisplay, ProvisioningStep, confirm_global_setting_delete, |
@@ -6911,12 +6911,12 @@ mod tests { |
6911 | 6911 | ForwardTcpConnectionError, PolicyGetView, ProvisioningStep, build_sandbox_resource_limits, |
6912 | 6912 | format_endpoint, format_log_line, forward_requires_session_token, git_sync_files, |
6913 | 6913 | has_main_process_result, parse_cli_setting_value, parse_credential_expiry_cli_value, |
6914 | | - parse_driver_config_json, parse_secret_material_env_pairs, policy_revision_list_json, |
6915 | | - policy_revision_to_json, proto_execution_timeout, provisioning_timeout_message, |
6916 | | - ready_false_condition_message, relay_local_socket, resolve_from, |
6917 | | - rootfs_tar_sources_supported_for_gateway, sandbox_should_persist, sandbox_upload_plan, |
6918 | | - service_endpoint_to_json, service_status_error, service_url_for_gateway, |
6919 | | - workspace_member_to_json, |
| 6914 | + parse_driver_config_json, parse_env_from_pairs, parse_secret_material_env_pairs, |
| 6915 | + policy_revision_list_json, policy_revision_to_json, proto_execution_timeout, |
| 6916 | + provisioning_timeout_message, ready_false_condition_message, relay_local_socket, |
| 6917 | + resolve_from, rootfs_tar_sources_supported_for_gateway, sandbox_should_persist, |
| 6918 | + sandbox_upload_plan, service_endpoint_to_json, service_status_error, |
| 6919 | + service_url_for_gateway, workspace_member_to_json, |
6920 | 6920 | }; |
6921 | 6921 | use openshell_core::proto::TcpForwardFrame; |
6922 | 6922 |
|
@@ -7181,6 +7181,57 @@ mod tests { |
7181 | 7181 | }); |
7182 | 7182 | } |
7183 | 7183 |
|
| 7184 | + #[test] |
| 7185 | + fn parse_env_from_pairs_reads_named_and_same_name_environment_variables() { |
| 7186 | + Environment::new() |
| 7187 | + .set("NAV_PARSE_ENV_FROM_NAMED", "named-value") |
| 7188 | + .set("NAV_PARSE_ENV_FROM_SAME", "same-name-value") |
| 7189 | + .run(|| { |
| 7190 | + let parsed = parse_env_from_pairs(&[ |
| 7191 | + "SANDBOX_NAMED=NAV_PARSE_ENV_FROM_NAMED".to_string(), |
| 7192 | + "NAV_PARSE_ENV_FROM_SAME".to_string(), |
| 7193 | + ]) |
| 7194 | + .expect("parse"); |
| 7195 | + assert_eq!( |
| 7196 | + parsed.get("SANDBOX_NAMED"), |
| 7197 | + Some(&"named-value".to_string()) |
| 7198 | + ); |
| 7199 | + assert_eq!( |
| 7200 | + parsed.get("NAV_PARSE_ENV_FROM_SAME"), |
| 7201 | + Some(&"same-name-value".to_string()) |
| 7202 | + ); |
| 7203 | + }); |
| 7204 | + } |
| 7205 | + |
| 7206 | + #[test] |
| 7207 | + fn parse_env_from_pairs_rejects_missing_invalid_reserved_and_duplicate_keys() { |
| 7208 | + Environment::new() |
| 7209 | + .remove("NAV_PARSE_ENV_FROM_MISSING") |
| 7210 | + .set("NAV_PARSE_ENV_FROM_PRESENT", "value") |
| 7211 | + .run(|| { |
| 7212 | + for (input, expected) in [ |
| 7213 | + ("TARGET=NAV_PARSE_ENV_FROM_MISSING", "is not set"), |
| 7214 | + ("1BAD=NAV_PARSE_ENV_FROM_PRESENT", "key must match"), |
| 7215 | + ("TARGET=BAD-NAME", "source must match"), |
| 7216 | + ("OPENSHELL_RESERVED=NAV_PARSE_ENV_FROM_PRESENT", "reserved"), |
| 7217 | + ] { |
| 7218 | + let error = |
| 7219 | + parse_env_from_pairs(&[input.to_string()]).expect_err("must reject"); |
| 7220 | + assert!( |
| 7221 | + error.to_string().contains(expected), |
| 7222 | + "unexpected error: {error}" |
| 7223 | + ); |
| 7224 | + } |
| 7225 | + |
| 7226 | + let error = parse_env_from_pairs(&[ |
| 7227 | + "TARGET=NAV_PARSE_ENV_FROM_PRESENT".to_string(), |
| 7228 | + "TARGET=NAV_PARSE_ENV_FROM_PRESENT".to_string(), |
| 7229 | + ]) |
| 7230 | + .expect_err("duplicate must reject"); |
| 7231 | + assert!(error.to_string().contains("duplicate --env-from")); |
| 7232 | + }); |
| 7233 | + } |
| 7234 | + |
7184 | 7235 | #[test] |
7185 | 7236 | fn parse_secret_material_env_pairs_reads_value_from_named_environment_variable() { |
7186 | 7237 | Environment::new() |
|
0 commit comments