-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(auth): show env credential overrides #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1260,6 +1260,8 @@ async fn handle_status() -> Result<(), GwsError> { | |
| } | ||
| } | ||
|
|
||
| add_oauth_env_status_fields(&mut output, has_config); | ||
|
|
||
| // Show credential source by attempting actual resolution | ||
| let has_token_env = std::env::var("GOOGLE_WORKSPACE_CLI_TOKEN") | ||
| .ok() | ||
|
|
@@ -1453,6 +1455,25 @@ async fn handle_status() -> Result<(), GwsError> { | |
| Ok(()) | ||
| } | ||
|
|
||
| fn add_oauth_env_status_fields(output: &mut serde_json::Value, has_config: bool) { | ||
| let env_client_id = std::env::var("GOOGLE_WORKSPACE_CLI_CLIENT_ID") | ||
| .ok() | ||
| .filter(|value| !value.is_empty()); | ||
| let env_client_secret_set = std::env::var("GOOGLE_WORKSPACE_CLI_CLIENT_SECRET") | ||
| .ok() | ||
| .filter(|value| !value.is_empty()) | ||
| .is_some(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The environment variable check here is inconsistent with the actual credential resolution logic in let env_client_id = std::env::var("GOOGLE_WORKSPACE_CLI_CLIENT_ID").ok();
let env_client_secret_set = std::env::var("GOOGLE_WORKSPACE_CLI_CLIENT_SECRET").is_ok(); |
||
|
|
||
| output["env_client_id_set"] = json!(env_client_id.is_some()); | ||
| output["env_client_secret_set"] = json!(env_client_secret_set); | ||
| output["env_overrides_client_config"] = | ||
| json!(has_config && env_client_id.is_some() && env_client_secret_set); | ||
|
|
||
| if let Some(client_id) = env_client_id { | ||
| output["env_client_id"] = json!(mask_secret(&client_id)); | ||
| } | ||
| } | ||
|
|
||
| fn handle_logout() -> Result<(), GwsError> { | ||
| let plain_path = plain_credentials_path(); | ||
| let enc_path = credential_store::encrypted_credentials_path(); | ||
|
|
@@ -1982,6 +2003,31 @@ mod tests { | |
| assert!(result.is_ok()); | ||
| } | ||
|
|
||
| #[test] | ||
| #[serial_test::serial] | ||
| fn add_oauth_env_status_fields_marks_env_override() { | ||
| unsafe { | ||
| std::env::set_var( | ||
| "GOOGLE_WORKSPACE_CLI_CLIENT_ID", | ||
| "1234567890abcdef.apps.googleusercontent.com", | ||
| ); | ||
| std::env::set_var("GOOGLE_WORKSPACE_CLI_CLIENT_SECRET", "test-secret"); | ||
| } | ||
|
|
||
| let mut output = json!({}); | ||
| add_oauth_env_status_fields(&mut output, true); | ||
|
|
||
| unsafe { | ||
| std::env::remove_var("GOOGLE_WORKSPACE_CLI_CLIENT_ID"); | ||
| std::env::remove_var("GOOGLE_WORKSPACE_CLI_CLIENT_SECRET"); | ||
| } | ||
|
|
||
| assert_eq!(output["env_client_id_set"], json!(true)); | ||
| assert_eq!(output["env_client_secret_set"], json!(true)); | ||
| assert_eq!(output["env_overrides_client_config"], json!(true)); | ||
| assert_eq!(output["env_client_id"], json!("1234....com")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn credential_store_save_load_round_trip() { | ||
| // Use encrypt/decrypt directly to avoid writing to the real config dir | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The addition of
add_oauth_env_status_fieldsintroduces a logic inconsistency with thecredential_sourcedetection later in this function (lines 1281-1284 in the full file). While the new status fields correctly filter out empty environment variables, thecredential_sourcelogic still usesis_ok(), which will incorrectly reportenvironment_variablesas the source if the variables are present but empty. This directly contradicts the PR's goal of accurately showing environment overrides.