Skip to content

Commit

Permalink
Merge branch 'develop' into 919_Integrate_webserver
Browse files Browse the repository at this point in the history
  • Loading branch information
kuznetsss authored Nov 20, 2024
2 parents 98371a2 + fc3ba07 commit a9b55f6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
19 changes: 12 additions & 7 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 @@ -301,15 +301,20 @@ CustomValidator CustomValidators::AuthorizeCredentialValidator =
for (auto const& credObj : value.as_array()) {
auto const& obj = credObj.as_object();

if (!obj.contains("issuer"))
return Error{Status{ClioError::rpcMALFORMED_REQUEST, "Field 'Issuer' is required but missing."}};
if (!obj.contains("issuer")) {
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 a9b55f6

Please sign in to comment.