From 013d80a729ae9bd34f348c324a30d5b217e06dbf Mon Sep 17 00:00:00 2001 From: Krish Dandiwala Date: Fri, 7 Aug 2026 21:30:30 +0000 Subject: [PATCH] fix: improve PasswordChangeRequired error handling Signed-off-by: Krish Dandiwala --- src/error.rs | 2 +- src/network.rs | 8 +++++--- tests/integration_test.rs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/error.rs b/src/error.rs index 6ca872aa7..120bc86cb 100644 --- a/src/error.rs +++ b/src/error.rs @@ -98,7 +98,7 @@ pub enum RedfishError { MissingVendor, #[error("Password change required")] - PasswordChangeRequired, + PasswordChangeRequired { account_uri: Option }, #[error("Maximum amount of user accounts reached. Delete one to continue.")] TooManyUsers, diff --git a/src/network.rs b/src/network.rs index 0dd7b24ee..810651b7d 100644 --- a/src/network.rs +++ b/src/network.rs @@ -698,16 +698,18 @@ impl RedfishHttpClient { // If PasswordChangeRequired is in the response, return a PasswordChangeRequired error. if let Ok(err) = serde_json::from_str::(&response_body) { - if err + if let Some(password_change_required) = err .error .extended .iter() // TODO(ajf) The actual message ID is specified in DTMF RedFish 9.5.11.2 so we // should properly parse it into a type since the error may come from different // MessageRegistries - .any(|ext| ext.message_id.ends_with("PasswordChangeRequired")) + .find(|ext| ext.message_id.ends_with("PasswordChangeRequired")) { - return Err(RedfishError::PasswordChangeRequired); + return Err(RedfishError::PasswordChangeRequired { + account_uri: password_change_required.message_args.first().cloned(), + }); } } // If we can't decode the error JSON, just return the normal HTTPErrorCode. Some diff --git a/tests/integration_test.rs b/tests/integration_test.rs index c93770165..6611dc5f8 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -157,7 +157,7 @@ async fn test_forbidden_error_handling() -> anyhow::Result<()> { match redfish.get_chassis_all().await { Ok(_) => panic!("Request should have failed with password change required"), - Err(libredfish::RedfishError::PasswordChangeRequired) => {} // what we want + Err(libredfish::RedfishError::PasswordChangeRequired { .. }) => {} // what we want Err(err) => panic!("Unexpected error response: {}", err), }