Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(user): add checks for change password (#3078)
Apoorv Dixit26a261131b4d
diff --git a/crates/router/src/core/errors/user.rs b/crates/router/src/core/errors/user.rsindex 9a53088522..eaa80c07b1 100644--- a/crates/router/src/core/errors/user.rs+++ b/crates/router/src/core/errors/user.rs@@ -48,6 +48,8 @@ pub enum UserErrors {InvalidMetadataRequest,#[error("MerchantIdParsingError")]MerchantIdParsingError,+ #[error("ChangePasswordError")]+ ChangePasswordError,}impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorResponse> for UserErrors {@@ -136,6 +138,12 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorResponSelf::MerchantIdParsingError => {AER::BadRequest(ApiError::new(sub_code, 28, "Invalid Merchant Id", None))}+ Self::ChangePasswordError => AER::BadRequest(ApiError::new(+ sub_code,+ 29,+ "Old and new password cannot be same",+ None,+ )),}}}diff --git a/crates/router/src/core/errors/user/sample_data.rs b/crates/router/src/core/errors/user/sample_data.rsindex 11233b27b5..84c6c9fa43 100644--- a/crates/router/src/core/errors/user/sample_data.rs+++ b/crates/router/src/core/errors/user/sample_data.rs@@ -10,10 +10,6 @@ pub enum SampleDataError {InternalServerError,#[error("Data Does Not Exist")]DataDoesNotExist,- #[error("Server Error")]- DatabaseError,- #[error("Merchant Id Not Found")]- MerchantIdNotFound,#[error("Invalid Parameters")]InvalidParameters,#[error["Invalid Records"]]@@ -29,33 +25,21 @@ impl ErrorSwitch<ApiErrorResponse> for SampleDataError {"Something went wrong",None,)),- Self::DatabaseError => ApiErrorResponse::InternalServerError(ApiError::new(- "SD",- 1,- "Server Error(DB is down)",- None,- )),Self::DataDoesNotExist => ApiErrorResponse::NotFound(ApiError::new("SD",- 2,+ 1,"Sample Data not present for given request",None,)),- Self::MerchantIdNotFound => ApiErrorResponse::BadRequest(ApiError::new(- "SD",- 3,- "Merchant ID not provided",- None,- )),Self::InvalidParameters => ApiErrorResponse::BadRequest(ApiError::new("SD",- 4,+ 2,"Invalid parameters to generate Sample Data",None,)),Self::InvalidRange => ApiErrorResponse::BadRequest(ApiError::new("SD",- 5,+ 3,"Records to be generated should be between range 10 and 100",None,)),@@ -67,7 +51,7 @@ impl ErrorSwitchFrom<StorageError> for SampleDataError {fn switch_from(error: &StorageError) -> Self {match matches!(error, StorageError::ValueNotFound(_)) {true => Self::DataDoesNotExist,- false => Self::DatabaseError,+ false => Self::InternalServerError,}}}diff --git a/crates/router/src/core/user.rs b/crates/router/src/core/user.rsindex f44042a2dc..8329277117 100644--- a/crates/router/src/core/user.rs+++ b/crates/router/src/core/user.rs@@ -232,10 +232,16 @@ pub async fn change_password(.change_context(UserErrors::InternalServerError)?.into();- user.compare_password(request.old_password)+ user.compare_password(request.old_password.to_owned()).change_context(UserErrors::InvalidOldPassword)?;- let new_password_hash = utils::user::password::generate_password_hash(request.new_password)?;+ if request.old_password == request.new_password {+ return Err(UserErrors::ChangePasswordError.into());+ }+ let new_password = domain::UserPassword::new(request.new_password)?;++ let new_password_hash =+ utils::user::password::generate_password_hash(new_password.get_secret())?;let _ = UserInterface::update_user_by_user_id(&*state.store,diff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rsindex 543e3cd2aa..9f95e2d078 100644--- a/crates/router/src/utils/user/sample_data.rs+++ b/crates/router/src/utils/user/sample_data.rs@@ -34,7 +34,7 @@ pub async fn generate_sample_data(&state.store.get_master_key().to_vec().into(),).await- .change_context(SampleDataError::DatabaseError)?;+ .change_context(SampleDataError::InternalServerError)?;let merchant_from_db = state.store