Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Allow API key to be passed via multi_search body.
Kishore Nallanc5f8e59b96a7
diff --git a/src/auth_manager.cpp b/src/auth_manager.cppindex f4e5c431..fe658f41 100644--- a/src/auth_manager.cpp+++ b/src/auth_manager.cpp@@ -153,6 +153,14 @@ bool AuthManager::authenticate(const std::string& action,size_t num_keys_matched = 0;for(size_t i = 0; i < collection_keys.size(); i++) {const auto& coll_key = collection_keys[i];+ if(coll_key.api_key.empty()) {+ return false;+ }++ if(coll_key.api_key == bootstrap_auth_key) {+ return true;+ }+const auto& key_it = api_keys.find(coll_key.api_key);nlohmann::json embedded_params;diff --git a/src/collection_manager.cpp b/src/collection_manager.cppindex 8d5da6a9..11f49e26 100644--- a/src/collection_manager.cpp+++ b/src/collection_manager.cpp@@ -306,10 +306,6 @@ bool CollectionManager::auth_key_matches(const string& req_auth_key, const strinstd::vector<nlohmann::json>& embedded_params_vec) const {std::shared_lock lock(mutex);- if(req_auth_key.empty()) {- return false;- }-// check with bootstrap auth keyif(bootstrap_auth_key == req_auth_key) {return true;diff --git a/test/collection_manager_test.cpp b/test/collection_manager_test.cppindex c0643ed2..e61eaac6 100644--- a/test/collection_manager_test.cpp+++ b/test/collection_manager_test.cpp@@ -768,6 +768,39 @@ TEST_F(CollectionManagerTest, DropCollectionCleanly) {delete it;}+TEST_F(CollectionManagerTest, AuthWithMultiSearchKeys) {+ api_key_t key1("api_key", "some key", {"documents:create"}, {"foo"}, 64723363199);+ collectionManager.getAuthManager().create_key(key1);++ std::vector<collection_key_t> collection_keys = {+ collection_key_t("foo", "api_key")+ };++ std::vector<nlohmann::json> embedded_params_vec = { nlohmann::json::object() };+ std::map<std::string, std::string> params;++ // empty req auth key (present in header / GET param)+ ASSERT_TRUE(collectionManager.auth_key_matches("", "documents:create", collection_keys, params,+ embedded_params_vec));++ // should work with bootstrap key+ collection_keys = {+ collection_key_t("foo", "auth_key")+ };++ ASSERT_TRUE(collectionManager.auth_key_matches("", "documents:create", collection_keys, params,+ embedded_params_vec));++ // bad key++ collection_keys = {+ collection_key_t("foo", "")+ };++ ASSERT_FALSE(collectionManager.auth_key_matches("", "documents:create", collection_keys, params,+ embedded_params_vec));+}+TEST_F(CollectionManagerTest, Symlinking) {CollectionManager & cmanager = CollectionManager::get_instance();std::string state_dir_path = "/tmp/typesense_test/cmanager_test_db";