Pārlūkot izejas kodu

HPCC-26887 WsStore should not report misses as exceptions

- Removes logic which forced an exception upon fetch miss
- Logs wsstore misses
- Adds new error code for query misses
- Updates store std lib to properly test miss
- Updates TestStore with empty string vals
Signed-off-by: Rodrigo Pastrana <rodrigo.pastrana@lexisnexisrisk.com>
Rodrigo Pastrana 3 gadi atpakaļ
vecāks
revīzija
80b8b1f87e

+ 1 - 1
ecllibrary/std/system/Store.ecl

@@ -419,7 +419,7 @@ EXPORT Store(STRING username = '',
                     TRANSFORM
                         (
                             RECORDOF(LEFT),
-                            SELF.was_found := NOT EXISTS(LEFT.exceptions.exceptions),
+                            SELF.was_found := LEFT.value != '' AND NOT EXISTS(LEFT.exceptions.exceptions),
                             SELF := LEFT
                         )
                 );

+ 16 - 0
ecllibrary/teststd/system/TestStore.ecl

@@ -15,17 +15,23 @@ EXPORT TestStore := MODULE
     SHARED KEY_1 := 'some_key';
     SHARED VALUE_1 := 'fubar';
 
+    SHARED KEY_2 := 'another_key';
+    SHARED VALUE_2 := '';
+
     SHARED kvStore := Std.System.Store(USER_NAME, USER_PW, ESP);
     SHARED namedKVStore := kvStore.WithNamespace(STORE_NAMESPACE, STORE_NAME);
 
     SHARED createStoreRes := kvStore.CreateStore(STORE_NAME);
     SHARED listStoresRes := kvStore.ListStores();
     SHARED listNamespacesRes := kvStore.ListNamespaces(STORE_NAME);
+    SHARED setKeyEmptyValueRes := namedKVStore.SetKeyValue(KEY_2, VALUE_2);
+    SHARED getKeyEmptyValueRes := namedKVStore.GetKeyValue(KEY_2);
     SHARED setKeyValueRes := namedKVStore.SetKeyValue(KEY_1, VALUE_1);
     SHARED getKeyValueRes := namedKVStore.GetKeyValue(KEY_1);
     SHARED getAllKeyValuesRes := namedKVStore.GetAllKeyValues();
     SHARED getAllKeysRes := namedKVStore.GetAllKeys();
     SHARED deleteKeyValueRes := namedKVStore.DeleteKeyValue(KEY_1);
+    SHARED deleteKeyValue2Res := namedKVStore.DeleteKeyValue(KEY_2);
     SHARED deleteNamespaceRes := namedKVStore.DeleteNamespace();
 
     // Using SEQUENTIAL to reuse the above definitions in a stateful manner
@@ -40,6 +46,9 @@ EXPORT TestStore := MODULE
             // Set a new key/value
             ASSERT(setKeyValueRes.succeeded);
 
+            // Set a new key/value (empty)
+            ASSERT(setKeyEmptyValueRes.succeeded);
+
             // Ensure our namespace exists
             ASSERT(EXISTS(listNamespacesRes.namespaces(namespace = STORE_NAMESPACE)));
 
@@ -47,6 +56,10 @@ EXPORT TestStore := MODULE
             ASSERT(getKeyValueRes.was_found = TRUE);
             ASSERT(getKeyValueRes.value = VALUE_1);
 
+            // Fetch empty string value for a key
+            ASSERT(getKeyEmptyValueRes.was_found = FALSE);
+            ASSERT(getKeyEmptyValueRes.value = VALUE_2);
+
             // Fetch all key/values in a namespace
             ASSERT(getAllKeysRes.namespace = STORE_NAMESPACE);
             ASSERT(EXISTS(getAllKeysRes.keys(key = KEY_1)));
@@ -56,6 +69,9 @@ EXPORT TestStore := MODULE
             // Delete a key/value
             ASSERT(deleteKeyValueRes.succeeded);
 
+            // Delete another key/value
+            ASSERT(deleteKeyValue2Res.succeeded);
+
             // Ensure our namespace still exists
             ASSERT(EXISTS(listNamespacesRes.namespaces(namespace = STORE_NAMESPACE)));
 

+ 1 - 1
esp/scm/ws_store.ecm

@@ -114,7 +114,7 @@ ESPrequest FetchRequest
 
 ESPresponse [exceptions_inline] FetchResponse
 {
-    string Value;
+    [nil_remove] string Value;
 };
 
 ESPrequest FetchAllRequest

+ 2 - 1
esp/services/ws_store/espstorelib/CMakeLists.txt

@@ -24,7 +24,8 @@ include_directories (
     ${HPCC_SOURCE_DIR}/system/jlib
     ${HPCC_SOURCE_DIR}/dali/base                    #SDS
     ${HPCC_SOURCE_DIR}/system/mp                    #MP, included by dali base
-    ${HPCC_SOURCE_DIR}/system/security/shared/
+    ${HPCC_SOURCE_DIR}/system/security/shared
+    ${HPCC_SOURCE_DIR}/esp/smc/SMCLib
 )
 
 ADD_DEFINITIONS ( -D_USRDLL -DDALIKVSTORE_EXPORTS )

+ 8 - 4
esp/services/ws_store/espstorelib/daliKVStore.cpp

@@ -410,14 +410,18 @@ bool CDALIKVStore::fetch(const char * storename, const char * ns, const char * k
     {
         xpath.appendf("/%s", key);
         if(!storetree->hasProp(xpath.str()))
-            throw makeStringExceptionV(MSGAUD_user, -1, "DALI Keystore fetch: invalid key '%s' detected!", key);
-
-        value.set(storetree->queryProp(xpath.str()));
+        {
+            throw makeStringExceptionV(ECLWATCH_INVALID_QUERY_KEY, "DALI Keystore fetch: invalid key '%s' detected!", key);
+        }
+        else
+        {
+            value.set(storetree->queryProp(xpath.str()));
+        }
 
         return value.str();
     }
     else
-        throw MakeStringException(-1, "DALI Keystore fetch: Namespace not provided!");
+        throw makeStringException(-1, "DALI Keystore fetch: Key not provided!");
 
     return true;
 }

+ 1 - 0
esp/services/ws_store/espstorelib/espStoreShare.hpp

@@ -21,6 +21,7 @@
 #define _ESPSTORESHARE_HPP__
 
 #include "SecureUser.hpp"
+#include "eclwatch_errorlist.hpp"
 
 interface IEspStore : extends IInterface
 {

+ 17 - 2
esp/services/ws_store/ws_storeService.cpp

@@ -312,8 +312,23 @@ bool CwsstoreEx::onFetch(IEspContext &context, IEspFetchRequest &req, IEspFetchR
             storename = m_defaultStore.get();
     }
 
-    m_storeProvider->fetch(storename, req.getNamespace(), req.getKey(), value, secuser.get(), !req.getUserSpecific());
-    resp.setValue(value.str());
+    try
+    {
+        m_storeProvider->fetch(storename, req.getNamespace(), req.getKey(), value, secuser.get(), !req.getUserSpecific());
+        resp.setValue(value.str());
+    }
+    catch(IException * e)
+    {
+        if (e->errorCode() == ECLWATCH_INVALID_QUERY_KEY)
+        {
+            StringBuffer msg;
+            LOG(MCuserInfo, "WsStore: %s", e->errorMessage(msg).str());
+            e->Release();
+            return false;
+        }
+        else
+            throw e;
+    }
 
     return true;
 }

+ 1 - 0
esp/services/ws_store/ws_storeService.hpp

@@ -23,6 +23,7 @@ limitations under the License.
 
 #include "dautils.hpp"
 #include "espStoreShare.hpp"
+#include "eclwatch_errorlist.hpp"
 
 static StringBuffer g_wsstoreBuildVersion;
 

+ 1 - 0
esp/smc/SMCLib/eclwatch_errorlist.hpp

@@ -128,6 +128,7 @@
 #define ECLWATCH_INVALID_ECLRECDEF          ECLWATCH_ERROR_START+107
 #define ECLWATCH_MISSING_FILETYPE           ECLWATCH_ERROR_START+108
 
+#define ECLWATCH_INVALID_QUERY_KEY          ECLWATCH_ERROR_START+109
 
 #endif //_ECLWATCH_ERRORLIST_HPP__
 

+ 1 - 0
system/security/plugins/jwtSecurity/CMakeLists.txt

@@ -43,6 +43,7 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/jwt-cpp/include"
                     "${HPCC_SOURCE_DIR}/dali/base"
                     "${HPCC_SOURCE_DIR}/dali/server"
                     "${HPCC_SOURCE_DIR}/esp/services/ws_store/espstorelib"
+                    "${HPCC_SOURCE_DIR}/esp/smc/SMCLib"
                     "${HPCC_SOURCE_DIR}/system/include"
                     "${HPCC_SOURCE_DIR}/system/mp"
                     "${HPCC_SOURCE_DIR}/system/security/shared"