From 2128e4ccd4ee7f5620f514a3c1462191237978de Mon Sep 17 00:00:00 2001 From: hongwei Date: Wed, 24 May 2023 16:37:56 +0800 Subject: [PATCH] refactor/tweaked the error message InvalidChallengeAnswer --- .../scala/code/api/util/ErrorMessages.scala | 4 ++-- .../src/main/scala/code/api/util/NewStyle.scala | 12 ++++++++++-- .../scala/code/api/v2_1_0/APIMethods210.scala | 5 ++++- .../scala/code/api/v4_0_0/APIMethods400.scala | 5 ++++- .../MappedChallengeProvider.scala | 17 ++++++++++++++--- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/ErrorMessages.scala b/obp-api/src/main/scala/code/api/util/ErrorMessages.scala index deb679774..202cde0a1 100644 --- a/obp-api/src/main/scala/code/api/util/ErrorMessages.scala +++ b/obp-api/src/main/scala/code/api/util/ErrorMessages.scala @@ -552,8 +552,8 @@ object ErrorMessages { val AllowedAttemptsUsedUp = "OBP-40014: Sorry, you've used up your allowed attempts. " val InvalidChallengeType = "OBP-40015: Invalid Challenge Type. Please specify a valid value for CHALLENGE_TYPE, when you create the transaction request." val InvalidChallengeAnswer = s"OBP-40016: Invalid Challenge Answer. Please specify a valid value for answer in Json body. " + - s"The challenge answer may be expired(${transactionRequestChallengeTtl} seconds)." + - s"Or you've used up your allowed attempts (${allowedAnswerTransactionRequestChallengeAttempts})." + + s"The challenge answer may be expired." + + s"Or you've used up your allowed attempts." + "Or if connector = mapped and transactionRequestType_OTP_INSTRUCTION_TRANSPORT = DUMMY and suggested_default_sca_method=DUMMY, the answer must be `123`. " + "Or if connector = others, the challenge answer can be got by phone message or other security ways." val InvalidPhoneNumber = "OBP-40017: Invalid Phone Number. Please specify a valid value for PHONE_NUMBER. Eg:+9722398746 " diff --git a/obp-api/src/main/scala/code/api/util/NewStyle.scala b/obp-api/src/main/scala/code/api/util/NewStyle.scala index 83228f41a..43161b096 100644 --- a/obp-api/src/main/scala/code/api/util/NewStyle.scala +++ b/obp-api/src/main/scala/code/api/util/NewStyle.scala @@ -1356,7 +1356,11 @@ object NewStyle extends MdcLoggable{ def validateChallengeAnswer(challengeId: String, hashOfSuppliedAnswer: String, callContext: Option[CallContext]): OBPReturnType[Boolean] = Connector.connector.vend.validateChallengeAnswer(challengeId: String, hashOfSuppliedAnswer: String, callContext: Option[CallContext]) map { i => - (unboxFullOrFail(i._1, callContext, s"$InvalidChallengeAnswer "), i._2) + (unboxFullOrFail(i._1, callContext, s"${ + InvalidChallengeAnswer + .replace("answer may be expired.", s"answer may be expired (${transactionRequestChallengeTtl} seconds).") + .replace("up your allowed attempts.", s"up your allowed attempts (${allowedAnswerTransactionRequestChallengeAttempts} times).") + }"), i._2) } def allChallengesSuccessfullyAnswered( @@ -1399,7 +1403,11 @@ object NewStyle extends MdcLoggable{ hashOfSuppliedAnswer: String, callContext: Option[CallContext] ) map { i => - (unboxFullOrFail(i._1, callContext, s"$InvalidChallengeAnswer "), i._2) + (unboxFullOrFail(i._1, callContext, s"${ + InvalidChallengeAnswer + .replace("answer may be expired.", s"answer may be expired (${transactionRequestChallengeTtl} seconds).") + .replace("up your allowed attempts.", s"up your allowed attempts (${allowedAnswerTransactionRequestChallengeAttempts} times).") + }"), i._2) } } } diff --git a/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala b/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala index ef8457cae..5caa19dce 100644 --- a/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala +++ b/obp-api/src/main/scala/code/api/v2_1_0/APIMethods210.scala @@ -644,7 +644,10 @@ trait APIMethods210 { (isChallengeAnswerValidated, callContext) <- NewStyle.function.validateChallengeAnswer(challengeAnswerJson.id, challengeAnswerJson.answer, callContext) - _ <- Helper.booleanToFuture(s"${InvalidChallengeAnswer} ", cc=callContext) { + _ <- Helper.booleanToFuture(s"${InvalidChallengeAnswer + .replace("answer may be expired.", s"answer may be expired (${transactionRequestChallengeTtl} seconds).") + .replace("up your allowed attempts.", s"up your allowed attempts (${allowedAnswerTransactionRequestChallengeAttempts} times).") + } ", cc = callContext) { (isChallengeAnswerValidated == true) } diff --git a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala index 8b9c99d2a..6c709c01e 100644 --- a/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala +++ b/obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala @@ -1630,7 +1630,10 @@ trait APIMethods400 { (challengeAnswerIsValidated, callContext) <- NewStyle.function.validateChallengeAnswer(challengeAnswerJson.id, challengeAnswerJson.answer, callContext) - _ <- Helper.booleanToFuture(s"${InvalidChallengeAnswer.replace("answer may be expired.",s"answer may be expired, current expiration time is ${transactionRequestChallengeTtl} seconds .")} ", cc=callContext) { + _ <- Helper.booleanToFuture(s"${InvalidChallengeAnswer + .replace("answer may be expired.",s"answer may be expired (${transactionRequestChallengeTtl} seconds).") + .replace("up your allowed attempts.",s"up your allowed attempts (${allowedAnswerTransactionRequestChallengeAttempts} times).") + }", cc=callContext) { challengeAnswerIsValidated } diff --git a/obp-api/src/main/scala/code/transactionChallenge/MappedChallengeProvider.scala b/obp-api/src/main/scala/code/transactionChallenge/MappedChallengeProvider.scala index 629cdb3a2..0006d6f5e 100644 --- a/obp-api/src/main/scala/code/transactionChallenge/MappedChallengeProvider.scala +++ b/obp-api/src/main/scala/code/transactionChallenge/MappedChallengeProvider.scala @@ -1,6 +1,7 @@ package code.transactionChallenge -import code.api.util.APIUtil.transactionRequestChallengeTtl +import code.api.util.APIUtil.{allowedAnswerTransactionRequestChallengeAttempts, transactionRequestChallengeTtl} +import code.api.util.ErrorMessages.InvalidChallengeAnswer import code.api.util.{APIUtil, ErrorMessages} import com.openbankproject.commons.model.{ChallengeTrait, ErrorMessage} import com.openbankproject.commons.model.enums.StrongCustomerAuthentication.SCA @@ -77,13 +78,23 @@ object MappedChallengeProvider extends ChallengeProvider { if(currentHashedAnswer==expectedHashedAnswer) { tryo{challenge.mSuccessful(true).mScaStatus(StrongCustomerAuthenticationStatus.finalised.toString).saveMe()} } else { - Failure(s"${ErrorMessages.InvalidChallengeAnswer}") + Failure(s"${ + s"${ + InvalidChallengeAnswer + .replace("answer may be expired.", s"answer may be expired (${transactionRequestChallengeTtl} seconds).") + .replace("up your allowed attempts.", s"up your allowed attempts (${allowedAnswerTransactionRequestChallengeAttempts} times).") + }"}") } case Some(id) => if(currentHashedAnswer==expectedHashedAnswer && id==challenge.expectedUserId) { tryo{challenge.mSuccessful(true).mScaStatus(StrongCustomerAuthenticationStatus.finalised.toString).saveMe()} } else { - Failure(s"${ErrorMessages.InvalidChallengeAnswer}") + Failure(s"${ + s"${ + InvalidChallengeAnswer + .replace("answer may be expired.", s"answer may be expired (${transactionRequestChallengeTtl} seconds).") + .replace("up your allowed attempts.", s"up your allowed attempts (${allowedAnswerTransactionRequestChallengeAttempts} times).") + }"}") } } }else{