mirror of
https://github.com/typesense/typesense.git
synced 2025-05-22 06:40:30 +08:00
Validate API key description during creation.
This commit is contained in:
parent
e6340dd645
commit
89409bb6d6
@ -330,6 +330,10 @@ Option<uint32_t> api_key_t::validate(const nlohmann::json &key_obj) {
|
||||
return Option<uint32_t>(400, std::string("Key value must be a string."));
|
||||
}
|
||||
|
||||
if(key_obj.count("description") != 0 && !key_obj["description"].is_string()) {
|
||||
return Option<uint32_t>(400, std::string("Key description must be a string."));
|
||||
}
|
||||
|
||||
if(!key_obj["actions"].is_array() || key_obj["actions"].empty()) {
|
||||
return Option<uint32_t>(400,"Wrong format for `actions`. It should be an array of string.");
|
||||
}
|
||||
|
@ -424,4 +424,15 @@ TEST_F(AuthManagerTest, ValidateBadKeyProperties) {
|
||||
validate_op = api_key_t::validate(key_obj3);
|
||||
ASSERT_FALSE(validate_op.ok());
|
||||
ASSERT_STREQ("Key value must be a string.", validate_op.error().c_str());
|
||||
|
||||
// check for valid description
|
||||
nlohmann::json key_obj4;
|
||||
key_obj4["description"] = 42;
|
||||
key_obj4["actions"] = {"*"};
|
||||
key_obj4["collections"] = {"foobar"};
|
||||
key_obj4["value"] = "abcd";
|
||||
|
||||
validate_op = api_key_t::validate(key_obj4);
|
||||
ASSERT_FALSE(validate_op.ok());
|
||||
ASSERT_STREQ("Key description must be a string.", validate_op.error().c_str());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user