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
Support regexp of collection names in API key.
kishorencec9da2ccf38e
diff --git a/src/auth_manager.cpp b/src/auth_manager.cppindex 14a3f407..7a17fd1f 100644--- a/src/auth_manager.cpp+++ b/src/auth_manager.cpp@@ -1,5 +1,6 @@#include "auth_manager.h"#include <openssl/evp.h>+#include <regex>constexpr const char* AuthManager::DOCUMENTS_SEARCH_ACTION;@@ -85,7 +86,7 @@ Option<api_key_t> AuthManager::get_key(uint32_t id, bool truncate_value) {}Option<api_key_t> AuthManager::create_key(api_key_t& api_key) {- LOG(INFO) << "AuthManager::create_key()";+ //LOG(INFO) << "AuthManager::create_key()";if(api_keys.count(api_key.value) != 0) {return Option<api_key_t>(409, "API key generation conflict.");@@ -195,7 +196,8 @@ bool AuthManager::authenticate(const std::string& req_api_key, const std::string// check if action is allowed against a specific collectionfor(const std::string& allowed_collection: api_key.collections) {- if(allowed_collection == "*" || (collection != "*" && allowed_collection == collection) || collection.empty()) {+ if(allowed_collection == "*" || (collection != "*" && allowed_collection == collection) ||+ std::regex_match (collection, std::regex(allowed_collection)) || collection.empty()) {return true;}}diff --git a/test/auth_manager_test.cpp b/test/auth_manager_test.cppindex 76316289..ab464965 100644--- a/test/auth_manager_test.cpp+++ b/test/auth_manager_test.cpp@@ -160,6 +160,19 @@ TEST_F(AuthManagerTest, VerifyAuthentication) {ASSERT_FALSE(auth_manager.authenticate(mul_acoll_key.value, "documents:search", "collection2", sparams));ASSERT_FALSE(auth_manager.authenticate(mul_acoll_key.value, "documents:get", "collection5", sparams));ASSERT_FALSE(auth_manager.authenticate(mul_acoll_key.value, "*", "*", sparams));++ // regexp match++ api_key_t regexp_colls_key1 = api_key_t("abcd6", "regexp coll key", {"*"}, {"coll.*"});+ auth_manager.create_key(regexp_colls_key1);+ ASSERT_TRUE(auth_manager.authenticate(regexp_colls_key1.value, "collections:list", "collection2", sparams));+ ASSERT_TRUE(auth_manager.authenticate(regexp_colls_key1.value, "documents:get", "collection5", sparams));++ api_key_t regexp_colls_key2 = api_key_t("abcd7", "regexp coll key", {"*"}, {".*meta.*"});+ auth_manager.create_key(regexp_colls_key2);+ ASSERT_TRUE(auth_manager.authenticate(regexp_colls_key2.value, "collections:list", "metacollection", sparams));+ ASSERT_TRUE(auth_manager.authenticate(regexp_colls_key2.value, "collections:list", "ametacollection", sparams));+}TEST_F(AuthManagerTest, GenerationOfAPIAction) {