From 592af70f03dbff8f85f764b307490dc791b8e6b3 Mon Sep 17 00:00:00 2001 From: Peter Chen <34582813+PeterChen13579@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:08:20 -0500 Subject: [PATCH] fix: Credential error message (#1738) fixes #1737 --- src/rpc/common/Validators.cpp | 16 +++++++----- tests/unit/rpc/handlers/LedgerEntryTests.cpp | 27 +++++++++++++++++--- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/rpc/common/Validators.cpp b/src/rpc/common/Validators.cpp index 47ea3e413..2597ea61a 100644 --- a/src/rpc/common/Validators.cpp +++ b/src/rpc/common/Validators.cpp @@ -258,7 +258,7 @@ CustomValidator CustomValidators::CurrencyIssueValidator = CustomValidator CustomValidators::CredentialTypeValidator = CustomValidator{[](boost::json::value const& value, std::string_view key) -> MaybeError { if (not value.is_string()) - return Error{Status{RippledError::rpcINVALID_PARAMS, std::string(key) + " NotString"}}; + return Error{Status{ClioError::rpcMALFORMED_AUTHORIZED_CREDENTIALS, std::string(key) + " NotString"}}; auto const& credTypeHex = ripple::strViewUnHex(value.as_string()); if (!credTypeHex.has_value()) @@ -302,14 +302,18 @@ CustomValidator CustomValidators::AuthorizeCredentialValidator = auto const& obj = credObj.as_object(); if (!obj.contains("issuer")) - return Error{Status{ClioError::rpcMALFORMED_REQUEST, "Field 'Issuer' is required but missing."}}; + return Error{ + Status{ClioError::rpcMALFORMED_AUTHORIZED_CREDENTIALS, "Field 'Issuer' is required but missing."} + }; - if (auto const err = IssuerValidator.verify(credObj, "issuer"); !err) - return err; + // don't want to change issuer error message to be about credentials + if (!IssuerValidator.verify(credObj, "issuer")) + return Error{Status{ClioError::rpcMALFORMED_AUTHORIZED_CREDENTIALS, "issuer NotString"}}; if (!obj.contains("credential_type")) { - return Error{Status{ClioError::rpcMALFORMED_REQUEST, "Field 'CredentialType' is required but missing."} - }; + return Error{Status{ + ClioError::rpcMALFORMED_AUTHORIZED_CREDENTIALS, "Field 'CredentialType' is required but missing." + }}; } if (auto const err = CredentialTypeValidator.verify(credObj, "credential_type"); !err) diff --git a/tests/unit/rpc/handlers/LedgerEntryTests.cpp b/tests/unit/rpc/handlers/LedgerEntryTests.cpp index f8528cef9..82d1396e7 100644 --- a/tests/unit/rpc/handlers/LedgerEntryTests.cpp +++ b/tests/unit/rpc/handlers/LedgerEntryTests.cpp @@ -292,7 +292,7 @@ generateTestValuesForParametersTest() ACCOUNT, ACCOUNT2 ), - "malformedRequest", + "malformedAuthorizedCredentials", "Field 'CredentialType' is required but missing." }, @@ -312,10 +312,31 @@ generateTestValuesForParametersTest() ACCOUNT, CREDENTIALTYPE ), - "malformedRequest", + "malformedAuthorizedCredentials", "Field 'Issuer' is required but missing." }, + ParamTestCaseBundle{ + "DepositPreauthAuthorizeCredentialsIncorrectIssuerType", + fmt::format( + R"({{ + "deposit_preauth": {{ + "owner": "{}", + "authorized_credentials": [ + {{ + "issuer": 123, + "credential_type": "{}" + }} + ] + }} + }})", + ACCOUNT, + CREDENTIALTYPE + ), + "malformedAuthorizedCredentials", + "issuer NotString" + }, + ParamTestCaseBundle{ "DepositPreauthAuthorizeCredentialsIncorrectCredentialType", fmt::format( @@ -333,7 +354,7 @@ generateTestValuesForParametersTest() ACCOUNT, ACCOUNT2 ), - "invalidParams", + "malformedAuthorizedCredentials", "credential_type NotString" },