mirror of
https://github.com/typesense/typesense.git
synced 2025-05-19 13:12:22 +08:00
Fix collection creation action auth.
This commit is contained in:
parent
e3bf9f02d6
commit
071750c663
@ -68,6 +68,16 @@ void get_collections_for_auth(std::map<std::string, std::string> &req_params, co
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(rpath.handler == post_create_collection) {
|
||||
nlohmann::json obj = nlohmann::json::parse(body, nullptr, false);
|
||||
|
||||
if(obj == nlohmann::json::value_t::discarded) {
|
||||
LOG(ERROR) << "Create collection request body is malformed.";
|
||||
}
|
||||
|
||||
if(obj != nlohmann::json::value_t::discarded && obj.count("name") != 0 && obj["name"].is_string()) {
|
||||
collections.emplace_back(obj["name"].get<std::string>());
|
||||
}
|
||||
}
|
||||
|
||||
if(collections.empty()) {
|
||||
|
@ -223,6 +223,13 @@ TEST_F(AuthManagerTest, VerifyAuthentication) {
|
||||
ASSERT_TRUE(auth_manager.authenticate(wildcard_action_coll_key.value, "collections:create", {"collection1"}, sparams));
|
||||
ASSERT_TRUE(auth_manager.authenticate(wildcard_action_coll_key.value, "collections:delete", {"collection1", "collection2"}, sparams));
|
||||
ASSERT_FALSE(auth_manager.authenticate(wildcard_action_coll_key.value, "documents:create", {"collection1"}, sparams));
|
||||
|
||||
// create action on a specific collection
|
||||
api_key_t create_action_coll_key = api_key_t("abcd11", "create action+coll key", {"collections:create"}, {"collection1"}, FUTURE_TS);
|
||||
auth_manager.create_key(create_action_coll_key);
|
||||
|
||||
ASSERT_TRUE(auth_manager.authenticate(create_action_coll_key.value, "collections:create", {"collection1"}, sparams));
|
||||
ASSERT_FALSE(auth_manager.authenticate(create_action_coll_key.value, "collections:create", {"collection2"}, sparams));
|
||||
}
|
||||
|
||||
TEST_F(AuthManagerTest, HandleAuthentication) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user