Fix collection creation action auth.

This commit is contained in:
Kishore Nallan 2021-09-21 13:12:32 +05:30
parent e3bf9f02d6
commit 071750c663
2 changed files with 17 additions and 0 deletions

View File

@ -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()) {

View File

@ -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) {