Skip to content

Commit

Permalink
fix: authorized_credential elements in array not objects bug (#1744)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterChen13579 authored Nov 21, 2024
1 parent c77154a commit 9dc322f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/rpc/common/Validators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ CustomValidator CustomValidators::AuthorizeCredentialValidator =
if (authCred.empty()) {
return Error{Status{
ClioError::rpcMALFORMED_AUTHORIZED_CREDENTIALS,
fmt::format("Requires at least one element in authorized_credentials array")
fmt::format("Requires at least one element in authorized_credentials array.")
}};
}

Expand All @@ -299,13 +299,19 @@ CustomValidator CustomValidators::AuthorizeCredentialValidator =
}

for (auto const& credObj : value.as_array()) {
if (!credObj.is_object()) {
return Error{Status{
ClioError::rpcMALFORMED_AUTHORIZED_CREDENTIALS,
"authorized_credentials elements in array are not objects."
}};
}
auto const& obj = credObj.as_object();

if (!obj.contains("issuer")) {
return Error{
Status{ClioError::rpcMALFORMED_AUTHORIZED_CREDENTIALS, "Field 'Issuer' is required but missing."}
};
}
}

// don't want to change issuer error message to be about credentials
if (!IssuerValidator.verify(credObj, "issuer"))
Expand Down
17 changes: 16 additions & 1 deletion tests/unit/rpc/handlers/LedgerEntryTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,21 @@ generateTestValuesForParametersTest()
"authorized_credentials not array"
},

ParamTestCaseBundle{
"InvalidDepositPreauthJsonAuthorizeCredentialsMalformedString",
fmt::format(
R"({{
"deposit_preauth": {{
"owner": "{}",
"authorized_credentials": ["C2F2A19C8D0D893D18F18FDCFE13A3ECB41767E48422DF07F2455CDA08FDF09B"]
}}
}})",
ACCOUNT
),
"malformedAuthorizedCredentials",
"authorized_credentials elements in array are not objects."
},

ParamTestCaseBundle{
"DepositPreauthBothAuthAndAuthCredentialsDoesNotExists",
fmt::format(
Expand Down Expand Up @@ -273,7 +288,7 @@ generateTestValuesForParametersTest()
ACCOUNT
),
"malformedAuthorizedCredentials",
"Requires at least one element in authorized_credentials array"
"Requires at least one element in authorized_credentials array."
},

ParamTestCaseBundle{
Expand Down

0 comments on commit 9dc322f

Please sign in to comment.