Skip to content

Commit 7d6f80f

Browse files
fix(rest): validate storage credentials in LoadTableResult::Validate
1 parent de69d97 commit 7d6f80f

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎src/iceberg/catalog/rest/types.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,18 @@ struct ICEBERG_REST_EXPORT StorageCredential {
187187
std::string prefix;
188188
std::unordered_map<std::string, std::string> config;
189189

190+
/// \brief Validates the StorageCredential. The REST spec requires both a
191+
/// prefix and config; non-empty matches Java `Credential.validate()`.
192+
Status Validate() const {
193+
if (prefix.empty()) {
194+
return ValidationFailed("Invalid storage credential: prefix must be non-empty");
195+
}
196+
if (config.empty()) {
197+
return ValidationFailed("Invalid storage credential: config must be non-empty");
198+
}
199+
return {};
200+
}
201+
190202
bool operator==(const StorageCredential& other) const = default;
191203
};
192204

@@ -203,6 +215,9 @@ struct ICEBERG_REST_EXPORT LoadTableResult {
203215
if (!metadata) {
204216
return ValidationFailed("Invalid metadata: null");
205217
}
218+
for (const auto& credential : storage_credentials) {
219+
ICEBERG_RETURN_UNEXPECTED(credential.Validate());
220+
}
206221
return {};
207222
}
208223

‎src/iceberg/test/rest_json_serde_test.cc‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,4 +2612,18 @@ TEST(FetchPlanningResultResponseRoundtripTest, FailedWithError) {
26122612
EXPECT_EQ(*result, *result2);
26132613
}
26142614

2615+
TEST(StorageCredentialValidateTest, RequiresPrefixAndConfig) {
2616+
EXPECT_THAT(
2617+
(StorageCredential{.prefix = "s3", .config = {{"s3.region", "us"}}}.Validate()),
2618+
IsOk());
2619+
2620+
auto empty_prefix = StorageCredential{.prefix = "", .config = {{"s3.region", "us"}}};
2621+
EXPECT_THAT(empty_prefix.Validate(), IsError(ErrorKind::kValidationFailed));
2622+
EXPECT_THAT(empty_prefix.Validate(), HasErrorMessage("prefix must be non-empty"));
2623+
2624+
auto empty_config = StorageCredential{.prefix = "s3", .config = {}};
2625+
EXPECT_THAT(empty_config.Validate(), IsError(ErrorKind::kValidationFailed));
2626+
EXPECT_THAT(empty_config.Validate(), HasErrorMessage("config must be non-empty"));
2627+
}
2628+
26152629
} // namespace iceberg::rest

0 commit comments

Comments
 (0)