Skip to content

Commit

Permalink
fix: Credential error message (#1738)
Browse files Browse the repository at this point in the history
fixes #1737
  • Loading branch information
PeterChen13579 authored and godexsoft committed Nov 18, 2024
1 parent 33cf336 commit 592af70
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/rpc/common/Validators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 24 additions & 3 deletions tests/unit/rpc/handlers/LedgerEntryTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ generateTestValuesForParametersTest()
ACCOUNT,
ACCOUNT2
),
"malformedRequest",
"malformedAuthorizedCredentials",
"Field 'CredentialType' is required but missing."
},

Expand All @@ -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(
Expand All @@ -333,7 +354,7 @@ generateTestValuesForParametersTest()
ACCOUNT,
ACCOUNT2
),
"invalidParams",
"malformedAuthorizedCredentials",
"credential_type NotString"
},

Expand Down

0 comments on commit 592af70

Please sign in to comment.