From 976e96f2394b92f96ddf64b6667bf011e90ef694 Mon Sep 17 00:00:00 2001 From: Anand Kandasamy <37086488+anand-ky@users.noreply.github.com> Date: Wed, 20 Mar 2024 11:11:26 -0400 Subject: [PATCH 1/3] Merge pull request #5040 from rdkcentral/RDK-47994-unsupported RDK-47994 : Return ERROR_GENERAL if call with wrong scope --- PersistentStore/grpc/Store2.h | 14 +++++++++++++- PersistentStore/sqlite/Store2.h | 12 ++++++++++++ PersistentStore/sqlite/StoreInspector.h | 9 +++++++++ PersistentStore/sqlite/StoreLimit.h | 6 ++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/PersistentStore/grpc/Store2.h b/PersistentStore/grpc/Store2.h index 9caf1684e6..c7ef3912af 100644 --- a/PersistentStore/grpc/Store2.h +++ b/PersistentStore/grpc/Store2.h @@ -145,6 +145,9 @@ namespace Plugin { uint32_t SetValue(const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) override { ASSERT(scope == ScopeType::ACCOUNT); + if (scope != ScopeType::ACCOUNT) { + return Core::ERROR_GENERAL; + } uint32_t result; @@ -186,6 +189,9 @@ namespace Plugin { uint32_t GetValue(const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) override { ASSERT(scope == ScopeType::ACCOUNT); + if (scope != ScopeType::ACCOUNT) { + return Core::ERROR_GENERAL; + } uint32_t result; @@ -239,6 +245,9 @@ namespace Plugin { uint32_t DeleteKey(const ScopeType scope, const string& ns, const string& key) override { ASSERT(scope == ScopeType::ACCOUNT); + if (scope != ScopeType::ACCOUNT) { + return Core::ERROR_GENERAL; + } uint32_t result; @@ -271,6 +280,9 @@ namespace Plugin { uint32_t DeleteNamespace(const ScopeType scope, const string& ns) override { ASSERT(scope == ScopeType::ACCOUNT); + if (scope != ScopeType::ACCOUNT) { + return Core::ERROR_GENERAL; + } uint32_t result; @@ -307,7 +319,7 @@ namespace Plugin { index(_clients.begin()); while (index != _clients.end()) { - (*index)->ValueChanged(ScopeType::DEVICE, ns, key, value); + (*index)->ValueChanged(ScopeType::ACCOUNT, ns, key, value); index++; } } diff --git a/PersistentStore/sqlite/Store2.h b/PersistentStore/sqlite/Store2.h index c106b088b8..d5412da91d 100644 --- a/PersistentStore/sqlite/Store2.h +++ b/PersistentStore/sqlite/Store2.h @@ -145,6 +145,9 @@ namespace Plugin { uint32_t SetValue(const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) override { ASSERT(scope == ScopeType::DEVICE); + if (scope != ScopeType::DEVICE) { + return Core::ERROR_GENERAL; + } uint32_t result; @@ -195,6 +198,9 @@ namespace Plugin { uint32_t GetValue(const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) override { ASSERT(scope == ScopeType::DEVICE); + if (scope != ScopeType::DEVICE) { + return Core::ERROR_GENERAL; + } uint32_t result; @@ -253,6 +259,9 @@ namespace Plugin { uint32_t DeleteKey(const ScopeType scope, const string& ns, const string& key) override { ASSERT(scope == ScopeType::DEVICE); + if (scope != ScopeType::DEVICE) { + return Core::ERROR_GENERAL; + } uint32_t result; @@ -279,6 +288,9 @@ namespace Plugin { uint32_t DeleteNamespace(const ScopeType scope, const string& ns) override { ASSERT(scope == ScopeType::DEVICE); + if (scope != ScopeType::DEVICE) { + return Core::ERROR_GENERAL; + } uint32_t result; diff --git a/PersistentStore/sqlite/StoreInspector.h b/PersistentStore/sqlite/StoreInspector.h index e1c03a99a8..94cf92a043 100644 --- a/PersistentStore/sqlite/StoreInspector.h +++ b/PersistentStore/sqlite/StoreInspector.h @@ -84,6 +84,9 @@ namespace Plugin { uint32_t GetKeys(const ScopeType scope, const string& ns, RPC::IStringIterator*& keys) override { ASSERT(scope == ScopeType::DEVICE); + if (scope != ScopeType::DEVICE) { + return Core::ERROR_GENERAL; + } uint32_t result; @@ -114,6 +117,9 @@ namespace Plugin { uint32_t GetNamespaces(const ScopeType scope, RPC::IStringIterator*& namespaces) override { ASSERT(scope == ScopeType::DEVICE); + if (scope != ScopeType::DEVICE) { + return Core::ERROR_GENERAL; + } uint32_t result; @@ -139,6 +145,9 @@ namespace Plugin { uint32_t GetStorageSizes(const ScopeType scope, INamespaceSizeIterator*& storageList) override { ASSERT(scope == ScopeType::DEVICE); + if (scope != ScopeType::DEVICE) { + return Core::ERROR_GENERAL; + } uint32_t result; diff --git a/PersistentStore/sqlite/StoreLimit.h b/PersistentStore/sqlite/StoreLimit.h index 86f9300a7f..145b71d174 100644 --- a/PersistentStore/sqlite/StoreLimit.h +++ b/PersistentStore/sqlite/StoreLimit.h @@ -91,6 +91,9 @@ namespace Plugin { uint32_t SetNamespaceStorageLimit(const ScopeType scope, const string& ns, const uint32_t size) override { ASSERT(scope == ScopeType::DEVICE); + if (scope != ScopeType::DEVICE) { + return Core::ERROR_GENERAL; + } uint32_t result; @@ -129,6 +132,9 @@ namespace Plugin { uint32_t GetNamespaceStorageLimit(const ScopeType scope, const string& ns, uint32_t& size) override { ASSERT(scope == ScopeType::DEVICE); + if (scope != ScopeType::DEVICE) { + return Core::ERROR_GENERAL; + } uint32_t result; From 1cd31b5b2b7264b1df8cd521684fbce527adf987 Mon Sep 17 00:00:00 2001 From: Nikita Poltorapavlo Date: Thu, 21 Mar 2024 15:34:17 +0200 Subject: [PATCH 2/3] RDK-48344 : Get token from auth service, get ids Reason for change: Get token from auth service plugin. Auth service doesn't have c++ interface, can be inactive or token is not set. Also get ids from file system and supply in the calls. Update proto with new parameters. Unite sqlite implementations in one class, use QueryInterface instead of Root. Return ERROR_NOT_SUPPORTED if unsupported. Test Procedure: None Risks: None Signed-off-by: Nikita Poltorapavlo --- PersistentStore/CMakeLists.txt | 3 - PersistentStore/Module.h | 1 - PersistentStore/PersistentStore.conf.in | 1 - PersistentStore/PersistentStore.config | 1 - PersistentStore/PersistentStore.cpp | 65 ++-- PersistentStore/PersistentStore.h | 293 +++++++++++------- PersistentStore/PersistentStoreJsonRpc.cpp | 26 +- PersistentStore/grpc/Store2.h | 78 ++--- PersistentStore/grpc/l0test/Store2Test.cpp | 3 +- .../grpc/secure_storage/secure_storage.proto | 131 ++++++-- .../l0test/PersistentStoreTest.cpp | 187 +++++++---- PersistentStore/l0test/Store2Mock.h | 23 +- PersistentStore/l0test/StoreCacheMock.h | 13 - PersistentStore/l0test/StoreInspectorMock.h | 15 - PersistentStore/l0test/StoreLimitMock.h | 14 - PersistentStore/sqlite/Store2.h | 220 +++++++++++-- PersistentStore/sqlite/StoreCache.cpp | 8 - PersistentStore/sqlite/StoreCache.h | 114 ------- PersistentStore/sqlite/StoreInspector.cpp | 8 - PersistentStore/sqlite/StoreInspector.h | 199 ------------ PersistentStore/sqlite/StoreLimit.cpp | 8 - PersistentStore/sqlite/StoreLimit.h | 189 ----------- PersistentStore/sqlite/l1test/CMakeLists.txt | 3 - PersistentStore/sqlite/l1test/Store2Test.cpp | 207 ++++++++++--- .../sqlite/l1test/StoreCacheTest.cpp | 29 -- .../sqlite/l1test/StoreInspectorTest.cpp | 96 ------ .../sqlite/l1test/StoreLimitTest.cpp | 112 ------- 27 files changed, 881 insertions(+), 1166 deletions(-) delete mode 100644 PersistentStore/l0test/StoreCacheMock.h delete mode 100644 PersistentStore/l0test/StoreInspectorMock.h delete mode 100644 PersistentStore/l0test/StoreLimitMock.h delete mode 100644 PersistentStore/sqlite/StoreCache.cpp delete mode 100644 PersistentStore/sqlite/StoreCache.h delete mode 100644 PersistentStore/sqlite/StoreInspector.cpp delete mode 100644 PersistentStore/sqlite/StoreInspector.h delete mode 100644 PersistentStore/sqlite/StoreLimit.cpp delete mode 100644 PersistentStore/sqlite/StoreLimit.h delete mode 100644 PersistentStore/sqlite/l1test/StoreCacheTest.cpp delete mode 100644 PersistentStore/sqlite/l1test/StoreInspectorTest.cpp delete mode 100644 PersistentStore/sqlite/l1test/StoreLimitTest.cpp diff --git a/PersistentStore/CMakeLists.txt b/PersistentStore/CMakeLists.txt index 8df164f077..fdefac6b4f 100644 --- a/PersistentStore/CMakeLists.txt +++ b/PersistentStore/CMakeLists.txt @@ -61,9 +61,6 @@ install(TARGETS ${MODULE_NAME} set(PLUGIN_IMPLEMENTATION ${MODULE_NAME}Implementation) add_library(${PLUGIN_IMPLEMENTATION} SHARED sqlite/Store2.cpp - sqlite/StoreCache.cpp - sqlite/StoreInspector.cpp - sqlite/StoreLimit.cpp grpc/Store2.cpp Module.cpp ) diff --git a/PersistentStore/Module.h b/PersistentStore/Module.h index fa393a364b..bce1d970a4 100644 --- a/PersistentStore/Module.h +++ b/PersistentStore/Module.h @@ -34,7 +34,6 @@ #define MAXSIZE_ENV "PERSISTENTSTORE_MAXSIZE" #define MAXVALUE_ENV "PERSISTENTSTORE_MAXVALUE" #define LIMIT_ENV "PERSISTENTSTORE_LIMIT" -#define TOKEN_COMMAND_ENV "PERSISTENTSTORE_TOKEN_COMMAND" #define IARM_INIT_NAME "Thunder_Plugins" #define URI_RFC "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.PersistentStore.Uri" diff --git a/PersistentStore/PersistentStore.conf.in b/PersistentStore/PersistentStore.conf.in index 244967ed15..d5b5965460 100644 --- a/PersistentStore/PersistentStore.conf.in +++ b/PersistentStore/PersistentStore.conf.in @@ -16,4 +16,3 @@ configuration.add("key", "@PLUGIN_PERSISTENTSTORE_KEY@") configuration.add("maxsize", "@PLUGIN_PERSISTENTSTORE_MAXSIZE@") configuration.add("maxvalue", "@PLUGIN_PERSISTENTSTORE_MAXVALUE@") configuration.add("limit", "@PLUGIN_PERSISTENTSTORE_LIMIT@") -configuration.add("tokencommand", "@PLUGIN_PERSISTENTSTORE_TOKEN_COMMAND@") diff --git a/PersistentStore/PersistentStore.config b/PersistentStore/PersistentStore.config index 5d6d4c59cd..3b6fde49f1 100644 --- a/PersistentStore/PersistentStore.config +++ b/PersistentStore/PersistentStore.config @@ -19,6 +19,5 @@ map() kv(maxsize ${PLUGIN_PERSISTENTSTORE_MAXSIZE}) kv(maxvalue ${PLUGIN_PERSISTENTSTORE_MAXVALUE}) kv(limit ${PLUGIN_PERSISTENTSTORE_LIMIT}) - kv(tokencommand ${PLUGIN_PERSISTENTSTORE_TOKEN_COMMAND}) end() ans(configuration) diff --git a/PersistentStore/PersistentStore.cpp b/PersistentStore/PersistentStore.cpp index 9ea464f11e..17396dcdd3 100644 --- a/PersistentStore/PersistentStore.cpp +++ b/PersistentStore/PersistentStore.cpp @@ -90,57 +90,50 @@ namespace Plugin { Core::SystemInfo::SetEnvironment(MAXSIZE_ENV, std::to_string(_config.MaxSize.Value())); Core::SystemInfo::SetEnvironment(MAXVALUE_ENV, std::to_string(_config.MaxValue.Value())); Core::SystemInfo::SetEnvironment(LIMIT_ENV, std::to_string(_config.Limit.Value())); - Core::SystemInfo::SetEnvironment(TOKEN_COMMAND_ENV, _config.TokenCommand.Value()); uint32_t connectionId; - Store2::ScopeMapType initList1; - auto deviceStore2 = service->Root(connectionId, 2000, _T("SqliteStore2")); - if (deviceStore2 != nullptr) { - initList1.emplace(Exchange::IStore2::ScopeType::DEVICE, deviceStore2); + _deviceStore2 = service->Root(connectionId, 2000, _T("SqliteStore2")); + if (_deviceStore2 != nullptr) { + _deviceStore2->Register(&_store2Sink); + _deviceStore2->Register(_store); + _deviceStoreCache = _deviceStore2->QueryInterface(); + _deviceStoreInspector = _deviceStore2->QueryInterface(); + _deviceStoreLimit = _deviceStore2->QueryInterface(); } - auto accountStore2 = service->Root(connectionId, 2000, _T("GrpcStore2")); - if (accountStore2 != nullptr) { - initList1.emplace(Exchange::IStore2::ScopeType::ACCOUNT, accountStore2); - } - _store2 = Core::Service::Create(initList1); - if (deviceStore2 != nullptr) { - deviceStore2->Release(); - } - if (accountStore2 != nullptr) { - accountStore2->Release(); + + _accountStore2 = service->Root(connectionId, 2000, _T("GrpcStore2")); + if (_accountStore2 != nullptr) { + _accountStore2->Register(&_store2Sink); } - _store2->Register(&_store2Sink); - _store = Core::Service::Create(_store2); - _storeCache = service->Root(connectionId, 2000, _T("SqliteStoreCache")); - _storeInspector = service->Root(connectionId, 2000, _T("SqliteStoreInspector")); - _storeLimit = service->Root(connectionId, 2000, _T("SqliteStoreLimit")); return result; } void PersistentStore::Deinitialize(PluginHost::IShell* /* service */) { - if (_store != nullptr) { - _store->Release(); - _store = nullptr; + if (_deviceStore2 != nullptr) { + _deviceStore2->Unregister(&_store2Sink); + _deviceStore2->Unregister(_store); + _deviceStore2->Release(); + _deviceStore2 = nullptr; } - if (_store2 != nullptr) { - _store2->Unregister(&_store2Sink); - _store2->Release(); - _store2 = nullptr; + if (_deviceStoreCache != nullptr) { + _deviceStoreCache->Release(); + _deviceStoreCache = nullptr; } - if (_storeCache != nullptr) { - _storeCache->Release(); - _storeCache = nullptr; + if (_deviceStoreInspector != nullptr) { + _deviceStoreInspector->Release(); + _deviceStoreInspector = nullptr; } - if (_storeInspector != nullptr) { - _storeInspector->Release(); - _storeInspector = nullptr; + if (_deviceStoreLimit != nullptr) { + _deviceStoreLimit->Release(); + _deviceStoreLimit = nullptr; } - if (_storeLimit != nullptr) { - _storeLimit->Release(); - _storeLimit = nullptr; + if (_accountStore2 != nullptr) { + _accountStore2->Unregister(&_store2Sink); + _accountStore2->Release(); + _accountStore2 = nullptr; } } diff --git a/PersistentStore/PersistentStore.h b/PersistentStore/PersistentStore.h index 3d97f0b322..c0886b645c 100644 --- a/PersistentStore/PersistentStore.h +++ b/PersistentStore/PersistentStore.h @@ -20,7 +20,6 @@ #pragma once #include "Module.h" - #include #include #include @@ -50,7 +49,6 @@ namespace Plugin { Add(_T("maxsize"), &MaxSize); Add(_T("maxvalue"), &MaxValue); Add(_T("limit"), &Limit); - Add(_T("tokencommand"), &TokenCommand); } public: @@ -61,7 +59,6 @@ namespace Plugin { Core::JSON::DecUInt64 MaxSize; Core::JSON::DecUInt64 MaxValue; Core::JSON::DecUInt64 Limit; - Core::JSON::String TokenCommand; }; class Store2Notification : public Exchange::IStore2::INotification { @@ -70,15 +67,13 @@ namespace Plugin { Store2Notification& operator=(const Store2Notification&) = delete; public: - explicit Store2Notification(PersistentStore* parent) - : _parent(*parent) + explicit Store2Notification(PersistentStore& parent) + : _parent(parent) { } ~Store2Notification() override = default; public: - // IStore2::INotification methods - void ValueChanged(const Exchange::IStore2::ScopeType scope, const string& ns, const string& key, const string& value) override { JsonData::PersistentStore::SetValueParamsData params; @@ -99,66 +94,20 @@ namespace Plugin { }; // Deprecated - class Store : public Exchange::IStore { + class Store : public Exchange::IStore, + public Exchange::IStore2::INotification { private: Store(const Store&) = delete; Store& operator=(const Store&) = delete; - private: - class Store2Notification : public Exchange::IStore2::INotification { - private: - Store2Notification(const Store2Notification&) = delete; - Store2Notification& operator=(const Store2Notification&) = delete; - - public: - explicit Store2Notification(Store* parent) - : _parent(*parent) - { - } - ~Store2Notification() override = default; - - public: - // IStore2::INotification methods - - void ValueChanged(const Exchange::IStore2::ScopeType, const string& ns, const string& key, const string& value) override - { - Core::SafeSyncType lock(_parent._clientLock); - - std::list::iterator - index(_parent._clients.begin()); - - while (index != _parent._clients.end()) { - (*index)->ValueChanged(ns, key, value); - index++; - } - } - - BEGIN_INTERFACE_MAP(Store2Notification) - INTERFACE_ENTRY(Exchange::IStore2::INotification) - END_INTERFACE_MAP - - private: - Store& _parent; - }; - public: - Store(Exchange::IStore2* store2) - : _store2(store2) - , _store2Sink(this) + Store(PersistentStore& parent) + : _parent(parent) { - ASSERT(_store2 != nullptr); - _store2->AddRef(); - _store2->Register(&_store2Sink); - } - ~Store() override - { - _store2->Unregister(&_store2Sink); - _store2->Release(); } + ~Store() override = default; public: - // IStore methods - uint32_t Register(Exchange::IStore::INotification* notification) override { Core::SafeSyncType lock(_clientLock); @@ -188,95 +137,201 @@ namespace Plugin { } uint32_t SetValue(const string& ns, const string& key, const string& value) override { - return _store2->SetValue(Exchange::IStore2::ScopeType::DEVICE, ns, key, value, 0); + if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->SetValue(Exchange::IStore2::ScopeType::DEVICE, ns, key, value, 0); + } + return Core::ERROR_NOT_SUPPORTED; } uint32_t GetValue(const string& ns, const string& key, string& value) override { - uint32_t ttl; - return _store2->GetValue(Exchange::IStore2::ScopeType::DEVICE, ns, key, value, ttl); + if (_parent._deviceStore2 != nullptr) { + uint32_t ttl; + return _parent._deviceStore2->GetValue(Exchange::IStore2::ScopeType::DEVICE, ns, key, value, ttl); + } + return Core::ERROR_NOT_SUPPORTED; } uint32_t DeleteKey(const string& ns, const string& key) override { - return _store2->DeleteKey(Exchange::IStore2::ScopeType::DEVICE, ns, key); + if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->DeleteKey(Exchange::IStore2::ScopeType::DEVICE, ns, key); + } + return Core::ERROR_NOT_SUPPORTED; } uint32_t DeleteNamespace(const string& ns) override { - return _store2->DeleteNamespace(Exchange::IStore2::ScopeType::DEVICE, ns); + if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->DeleteNamespace(Exchange::IStore2::ScopeType::DEVICE, ns); + } + return Core::ERROR_NOT_SUPPORTED; + } + void ValueChanged(const Exchange::IStore2::ScopeType scope, const string& ns, const string& key, const string& value) override + { + ASSERT(scope == Exchange::IStore2::ScopeType::DEVICE); + + Core::SafeSyncType lock(_clientLock); + + std::list::iterator + index(_clients.begin()); + + while (index != _clients.end()) { + (*index)->ValueChanged(ns, key, value); + index++; + } } BEGIN_INTERFACE_MAP(Store) INTERFACE_ENTRY(Exchange::IStore) + INTERFACE_ENTRY(Exchange::IStore2::INotification) END_INTERFACE_MAP private: - Exchange::IStore2* _store2; + PersistentStore& _parent; std::list _clients; Core::CriticalSection _clientLock; - Core::Sink _store2Sink; }; - class Store2 : public Exchange::IStore2 { + class Store2 : public Exchange::IStore2, + public Exchange::IStoreCache, + public Exchange::IStoreInspector, + public Exchange::IStoreLimit { private: Store2(const Store2&) = delete; Store2& operator=(const Store2&) = delete; public: - typedef std::map ScopeMapType; + Store2(PersistentStore& parent) + : _parent(parent) + { + } + ~Store2() override = default; - Store2(const ScopeMapType& map) - : _scopeMap(map) + public: + uint32_t Register(INotification* notification) override { - for (auto const& x : _scopeMap) { - x.second->AddRef(); + if (_parent._deviceStore2 != nullptr) { + _parent._deviceStore2->Register(notification); + } + if (_parent._accountStore2 != nullptr) { + _parent._accountStore2->Register(notification); } + return Core::ERROR_NONE; } - ~Store2() override + uint32_t Unregister(INotification* notification) override { - for (auto const& x : _scopeMap) { - x.second->Release(); + if (_parent._deviceStore2 != nullptr) { + _parent._deviceStore2->Unregister(notification); + } + if (_parent._accountStore2 != nullptr) { + _parent._accountStore2->Unregister(notification); } + return Core::ERROR_NONE; } - - public: - // IStore2 methods - - uint32_t Register(Exchange::IStore2::INotification* notification) override + uint32_t SetValue(const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) override { - for (auto const& x : _scopeMap) { - x.second->Register(notification); + if (scope == IStore2::ScopeType::ACCOUNT) { + if (_parent._accountStore2 != nullptr) { + return _parent._accountStore2->SetValue(scope, ns, key, value, ttl); + } + } else if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->SetValue(scope, ns, key, value, ttl); } - return Core::ERROR_NONE; + return Core::ERROR_NOT_SUPPORTED; } - uint32_t Unregister(Exchange::IStore2::INotification* notification) override + uint32_t GetValue(const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) override { - for (auto const& x : _scopeMap) { - x.second->Unregister(notification); + if (scope == IStore2::ScopeType::ACCOUNT) { + if (_parent._accountStore2 != nullptr) { + return _parent._accountStore2->GetValue(scope, ns, key, value, ttl); + } + } else if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->GetValue(scope, ns, key, value, ttl); } - return Core::ERROR_NONE; + return Core::ERROR_NOT_SUPPORTED; } - uint32_t SetValue(const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) override + uint32_t DeleteKey(const IStore2::ScopeType scope, const string& ns, const string& key) override { - return _scopeMap.at(scope)->SetValue(scope, ns, key, value, ttl); + if (scope == IStore2::ScopeType::ACCOUNT) { + if (_parent._accountStore2 != nullptr) { + return _parent._accountStore2->DeleteKey(scope, ns, key); + } + } else if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->DeleteKey(scope, ns, key); + } + return Core::ERROR_NOT_SUPPORTED; } - uint32_t GetValue(const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) override + uint32_t DeleteNamespace(const IStore2::ScopeType scope, const string& ns) override { - return _scopeMap.at(scope)->GetValue(scope, ns, key, value, ttl); + if (scope == IStore2::ScopeType::ACCOUNT) { + if (_parent._accountStore2 != nullptr) { + return _parent._accountStore2->DeleteNamespace(scope, ns); + } + } else if (_parent._deviceStore2 != nullptr) { + return _parent._deviceStore2->DeleteNamespace(scope, ns); + } + return Core::ERROR_NOT_SUPPORTED; } - uint32_t DeleteKey(const ScopeType scope, const string& ns, const string& key) override + uint32_t FlushCache() override { - return _scopeMap.at(scope)->DeleteKey(scope, ns, key); + if (_parent._deviceStoreCache != nullptr) { + return _parent._deviceStoreCache->FlushCache(); + } + return Core::ERROR_NOT_SUPPORTED; } - uint32_t DeleteNamespace(const ScopeType scope, const string& ns) override + uint32_t GetKeys(const IStoreInspector::ScopeType scope, const string& ns, RPC::IStringIterator*& keys) override { - return _scopeMap.at(scope)->DeleteNamespace(scope, ns); + if (scope == IStoreInspector::ScopeType::DEVICE) { + if (_parent._deviceStoreInspector != nullptr) { + return _parent._deviceStoreInspector->GetKeys(scope, ns, keys); + } + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t GetNamespaces(const IStoreInspector::ScopeType scope, RPC::IStringIterator*& namespaces) override + { + if (scope == IStoreInspector::ScopeType::DEVICE) { + if (_parent._deviceStoreInspector != nullptr) { + return _parent._deviceStoreInspector->GetNamespaces(scope, namespaces); + } + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t GetStorageSizes(const IStoreInspector::ScopeType scope, INamespaceSizeIterator*& storageList) override + { + if (scope == IStoreInspector::ScopeType::DEVICE) { + if (_parent._deviceStoreInspector != nullptr) { + return _parent._deviceStoreInspector->GetStorageSizes(scope, storageList); + } + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t SetNamespaceStorageLimit(const IStoreLimit::ScopeType scope, const string& ns, const uint32_t size) override + { + if (scope == IStoreLimit::ScopeType::DEVICE) { + if (_parent._deviceStoreLimit != nullptr) { + return _parent._deviceStoreLimit->SetNamespaceStorageLimit(scope, ns, size); + } + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t GetNamespaceStorageLimit(const IStoreLimit::ScopeType scope, const string& ns, uint32_t& size) override + { + if (scope == IStoreLimit::ScopeType::DEVICE) { + if (_parent._deviceStoreLimit != nullptr) { + return _parent._deviceStoreLimit->GetNamespaceStorageLimit(scope, ns, size); + } + } + return Core::ERROR_NOT_SUPPORTED; } BEGIN_INTERFACE_MAP(Store2) - INTERFACE_ENTRY(Exchange::IStore2) + INTERFACE_ENTRY(IStore2) + INTERFACE_ENTRY(IStoreCache) + INTERFACE_ENTRY(IStoreInspector) + INTERFACE_ENTRY(IStoreLimit) END_INTERFACE_MAP private: - ScopeMapType _scopeMap; + PersistentStore& _parent; }; private: @@ -286,41 +341,47 @@ namespace Plugin { public: PersistentStore() : PluginHost::JSONRPC() - , _store(nullptr) - , _store2(nullptr) - , _storeCache(nullptr) - , _storeInspector(nullptr) - , _storeLimit(nullptr) - , _store2Sink(this) + , _deviceStore2(nullptr) + , _deviceStoreCache(nullptr) + , _deviceStoreInspector(nullptr) + , _deviceStoreLimit(nullptr) + , _accountStore2(nullptr) + , _store(Core::Service::Create(*this)) + , _store2(Core::Service::Create(*this)) + , _store2Sink(*this) { RegisterAll(); } ~PersistentStore() override { UnregisterAll(); + + if (_store != nullptr) { + _store->Release(); + _store = nullptr; + } + if (_store2 != nullptr) { + _store2->Release(); + _store2 = nullptr; + } } - // Build QueryInterface implementation, specifying all possible interfaces to be returned. BEGIN_INTERFACE_MAP(PersistentStore) INTERFACE_ENTRY(PluginHost::IPlugin) INTERFACE_ENTRY(PluginHost::IDispatcher) INTERFACE_AGGREGATE(Exchange::IStore, _store) INTERFACE_AGGREGATE(Exchange::IStore2, _store2) - INTERFACE_AGGREGATE(Exchange::IStoreCache, _storeCache) - INTERFACE_AGGREGATE(Exchange::IStoreInspector, _storeInspector) - INTERFACE_AGGREGATE(Exchange::IStoreLimit, _storeLimit) + INTERFACE_AGGREGATE(Exchange::IStoreCache, _store2) + INTERFACE_AGGREGATE(Exchange::IStoreInspector, _store2) + INTERFACE_AGGREGATE(Exchange::IStoreLimit, _store2) END_INTERFACE_MAP public: - // IPlugin methods - // ------------------------------------------------------------------------------------------------------- const string Initialize(PluginHost::IShell* service) override; void Deinitialize(PluginHost::IShell* service) override; string Information() const override; private: - // JSON RPC - void RegisterAll(); void UnregisterAll(); @@ -343,11 +404,13 @@ namespace Plugin { private: Config _config; - Exchange::IStore* _store; // Deprecated - Exchange::IStore2* _store2; - Exchange::IStoreCache* _storeCache; - Exchange::IStoreInspector* _storeInspector; - Exchange::IStoreLimit* _storeLimit; + Exchange::IStore2* _deviceStore2; + Exchange::IStoreCache* _deviceStoreCache; + Exchange::IStoreInspector* _deviceStoreInspector; + Exchange::IStoreLimit* _deviceStoreLimit; + Exchange::IStore2* _accountStore2; + Store* _store; // Deprecated + Store2* _store2; Core::Sink _store2Sink; }; diff --git a/PersistentStore/PersistentStoreJsonRpc.cpp b/PersistentStore/PersistentStoreJsonRpc.cpp index faa89dd147..f8c4c6a700 100644 --- a/PersistentStore/PersistentStoreJsonRpc.cpp +++ b/PersistentStore/PersistentStoreJsonRpc.cpp @@ -118,8 +118,8 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getKeys(const DeleteNamespaceParamsInfo& params, GetKeysResultData& response) { RPC::IStringIterator* it; - auto result = _storeInspector->GetKeys( - Exchange::IStore2::ScopeType(params.Scope.Value()), + auto result = _store2->GetKeys( + Exchange::IStoreInspector::ScopeType(params.Scope.Value()), params.Namespace.Value(), it); if (result == Core::ERROR_NONE) { @@ -137,8 +137,8 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getNamespaces(const GetNamespacesParamsInfo& params, GetNamespacesResultData& response) { RPC::IStringIterator* it; - auto result = _storeInspector->GetNamespaces( - Exchange::IStore2::ScopeType(params.Scope.Value()), + auto result = _store2->GetNamespaces( + Exchange::IStoreInspector::ScopeType(params.Scope.Value()), it); if (result == Core::ERROR_NONE) { string element; @@ -156,8 +156,8 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getStorageSize(const GetNamespacesParamsInfo& params, JsonObject& response) { Exchange::IStoreInspector::INamespaceSizeIterator* it; - auto result = _storeInspector->GetStorageSizes( - Exchange::IStore2::ScopeType(params.Scope.Value()), + auto result = _store2->GetStorageSizes( + Exchange::IStoreInspector::ScopeType(params.Scope.Value()), it); if (result == Core::ERROR_NONE) { JsonObject jsonObject; @@ -176,8 +176,8 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getStorageSizes(const GetNamespacesParamsInfo& params, GetStorageSizesResultData& response) { Exchange::IStoreInspector::INamespaceSizeIterator* it; - auto result = _storeInspector->GetStorageSizes( - Exchange::IStore2::ScopeType(params.Scope.Value()), + auto result = _store2->GetStorageSizes( + Exchange::IStoreInspector::ScopeType(params.Scope.Value()), it); if (result == Core::ERROR_NONE) { Exchange::IStoreInspector::NamespaceSize element; @@ -194,7 +194,7 @@ namespace Plugin { uint32_t PersistentStore::endpoint_flushCache(DeleteKeyResultInfo& response) { - auto result = _storeCache->FlushCache(); + auto result = _store2->FlushCache(); if (result == Core::ERROR_NONE) { response.Success = true; } @@ -205,8 +205,8 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getNamespaceStorageLimit(const DeleteNamespaceParamsInfo& params, GetNamespaceStorageLimitResultData& response) { uint32_t size; - auto result = _storeLimit->GetNamespaceStorageLimit( - Exchange::IStore2::ScopeType(params.Scope.Value()), + auto result = _store2->GetNamespaceStorageLimit( + Exchange::IStoreLimit::ScopeType(params.Scope.Value()), params.Namespace.Value(), size); if (result == Core::ERROR_NONE) { @@ -218,8 +218,8 @@ namespace Plugin { uint32_t PersistentStore::endpoint_setNamespaceStorageLimit(const SetNamespaceStorageLimitParamsData& params) { - return _storeLimit->SetNamespaceStorageLimit( - Exchange::IStore2::ScopeType(params.Scope.Value()), + return _store2->SetNamespaceStorageLimit( + Exchange::IStoreLimit::ScopeType(params.Scope.Value()), params.Namespace.Value(), params.StorageLimit.Value()); } diff --git a/PersistentStore/grpc/Store2.h b/PersistentStore/grpc/Store2.h index c7ef3912af..67de1e4889 100644 --- a/PersistentStore/grpc/Store2.h +++ b/PersistentStore/grpc/Store2.h @@ -39,15 +39,12 @@ namespace Plugin { public: Store2() - : Store2( - getenv(URI_ENV), - getenv(TOKEN_COMMAND_ENV)) + : Store2(getenv(URI_ENV)) { } - Store2(const string& uri, const string& tokenCommand) + Store2(const string& uri) : IStore2() , _uri(uri) - , _tokenCommand(tokenCommand) { Open(); } @@ -93,24 +90,34 @@ namespace Plugin { } string GetToken() const { - class Authorization : public Core::JSON::Container { - public: - Authorization() - : Core::JSON::Container() - , Expires(0) - , Received(0) - { - Add(_T("token"), &Token); - Add(_T("expires"), &Expires); - Add(_T("received"), &Received); - } - Core::JSON::String Token; - Core::JSON::DecUInt64 Expires; - Core::JSON::DecUInt64 Received; - }; - Authorization auth; - auth.FromString(ExecuteCmd(_tokenCommand.c_str())); - return auth.Token.Value(); + // TODO remove this + JsonObject jsonObject; + jsonObject.FromString(ExecuteCmd("curl -d '{\"jsonrpc\":\"2.0\",\"id\":0,\"method\":\"org.rdk.AuthService.getServiceAccessToken\"}' http://127.0.0.1:9998/jsonrpc")); + return jsonObject["result"].Object()["token"].String(); + } + static string ReadFromFile(const char* filename) + { + string result; + Core::File file(filename); + if (file.Open(true)) { + uint8_t buffer[1024]; + auto size = file.Read(buffer, 1024); + result.assign(reinterpret_cast(buffer), size); + result.erase(result.find_last_not_of(" \n\r\t") + 1); + } + return result; + } + string GetPartnerId() const + { + return ReadFromFile("/opt/www/authService/partnerId3.dat"); + } + string GetAccountId() const + { + return ReadFromFile("/opt/www/authService/said.dat"); + } + string GetDeviceId() const + { + return ReadFromFile("/opt/www/authService/xdeviceid.dat"); } public: @@ -145,9 +152,6 @@ namespace Plugin { uint32_t SetValue(const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) override { ASSERT(scope == ScopeType::ACCOUNT); - if (scope != ScopeType::ACCOUNT) { - return Core::ERROR_GENERAL; - } uint32_t result; @@ -156,6 +160,9 @@ namespace Plugin { context.AddMetadata("authorization", "Bearer " + GetToken()); } ::distp::gateway::secure_storage::v1::UpdateValueRequest request; + request.set_partner_id(GetPartnerId()); + request.set_account_id(GetAccountId()); + request.set_device_id(GetDeviceId()); auto v = new ::distp::gateway::secure_storage::v1::Value(); v->set_value(value); if (ttl != 0) { @@ -189,9 +196,6 @@ namespace Plugin { uint32_t GetValue(const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) override { ASSERT(scope == ScopeType::ACCOUNT); - if (scope != ScopeType::ACCOUNT) { - return Core::ERROR_GENERAL; - } uint32_t result; @@ -200,6 +204,9 @@ namespace Plugin { context.AddMetadata("authorization", "Bearer " + GetToken()); } ::distp::gateway::secure_storage::v1::GetValueRequest request; + request.set_partner_id(GetPartnerId()); + request.set_account_id(GetAccountId()); + request.set_device_id(GetDeviceId()); auto k = new ::distp::gateway::secure_storage::v1::Key(); k->set_app_id(ns); k->set_key(key); @@ -245,9 +252,6 @@ namespace Plugin { uint32_t DeleteKey(const ScopeType scope, const string& ns, const string& key) override { ASSERT(scope == ScopeType::ACCOUNT); - if (scope != ScopeType::ACCOUNT) { - return Core::ERROR_GENERAL; - } uint32_t result; @@ -256,6 +260,9 @@ namespace Plugin { context.AddMetadata("authorization", "Bearer " + GetToken()); } ::distp::gateway::secure_storage::v1::DeleteValueRequest request; + request.set_partner_id(GetPartnerId()); + request.set_account_id(GetAccountId()); + request.set_device_id(GetDeviceId()); auto k = new ::distp::gateway::secure_storage::v1::Key(); k->set_app_id(ns); k->set_key(key); @@ -280,9 +287,6 @@ namespace Plugin { uint32_t DeleteNamespace(const ScopeType scope, const string& ns) override { ASSERT(scope == ScopeType::ACCOUNT); - if (scope != ScopeType::ACCOUNT) { - return Core::ERROR_GENERAL; - } uint32_t result; @@ -291,6 +295,9 @@ namespace Plugin { context.AddMetadata("authorization", "Bearer " + GetToken()); } ::distp::gateway::secure_storage::v1::DeleteAllValuesRequest request; + request.set_partner_id(GetPartnerId()); + request.set_account_id(GetAccountId()); + request.set_device_id(GetDeviceId()); request.set_app_id(ns); request.set_scope(::distp::gateway::secure_storage::v1::Scope::SCOPE_ACCOUNT); ::distp::gateway::secure_storage::v1::DeleteAllValuesResponse response; @@ -330,7 +337,6 @@ namespace Plugin { private: const string _uri; - const string _tokenCommand; std::unique_ptr<::distp::gateway::secure_storage::v1::SecureStorageService::Stub> _stub; std::list _clients; Core::CriticalSection _clientLock; diff --git a/PersistentStore/grpc/l0test/Store2Test.cpp b/PersistentStore/grpc/l0test/Store2Test.cpp index a354e79691..d915570af3 100644 --- a/PersistentStore/grpc/l0test/Store2Test.cpp +++ b/PersistentStore/grpc/l0test/Store2Test.cpp @@ -30,7 +30,6 @@ using ::WPEFramework::Exchange::IStore2; using ::WPEFramework::Plugin::Grpc::Store2; const auto kUri = "0.0.0.0:50051"; -const auto kTokenCommand = ""; const auto kValue = "value_1"; const auto kKey = "key_1"; const auto kAppId = "app_id_1"; @@ -44,7 +43,7 @@ class AStore2 : public Test { WPEFramework::Core::ProxyType store2; AStore2() : server(kUri, &service) - , store2(WPEFramework::Core::ProxyType::Create(kUri, kTokenCommand)) + , store2(WPEFramework::Core::ProxyType::Create(kUri)) { } }; diff --git a/PersistentStore/grpc/secure_storage/secure_storage.proto b/PersistentStore/grpc/secure_storage/secure_storage.proto index 526eefb8eb..dc66cad38d 100644 --- a/PersistentStore/grpc/secure_storage/secure_storage.proto +++ b/PersistentStore/grpc/secure_storage/secure_storage.proto @@ -5,44 +5,65 @@ package distp.gateway.secure_storage.v1; import "google/protobuf/duration.proto"; import "google/protobuf/timestamp.proto"; -// SecureStorageService handles the storage and deletion of data (represented as string values) from applications given a particular key and scope. +// SecureStorageService handles the storage and deletion of data (represented +// as string values) from applications given a particular key and scope. service SecureStorageService { - // GetValue retrieves the value string stored in SecureStorage based on the scope and key provided for the current application. + // GetValue retrieves the value string stored in SecureStorage based on the + // scope and key provided for the current application. rpc GetValue(GetValueRequest) returns (GetValueResponse); - // UpdateValue stores the string value provided in SecureStorage against the scope and key provided for the current application. + + // UpdateValue stores the string value provided in SecureStorage against the + // scope and key provided for the current application. rpc UpdateValue(UpdateValueRequest) returns (UpdateValueResponse); - // DeleteValue removes the string value stored in SecureStorage, if present, defined by the scope and key provided for the current application/device. + + // DeleteValue removes the string value stored in SecureStorage, if present, + // defined by the scope and key provided for the current application/device. rpc DeleteValue(DeleteValueRequest) returns (DeleteValueResponse); - // DeleteAllValues removes all values stored against the provided application for the given account. This includes all key/value pairs - // stored against the device scope for other devices within the account. Please note that this method does not take a key as input. - // Also, DeleteAllValues is a separate method given that access to delete all values may be controlled by explicit capabilities. + + // DeleteAllValues removes all values stored against the provided application + // for the given account. This includes all key/value pairs stored against + // the device scope for other devices within the account. Please note that + // this method does not take a key as input. Also, DeleteAllValues is a + // separate method given that access to delete all values may be controlled + // by explicit capabilities. rpc DeleteAllValues(DeleteAllValuesRequest) returns (DeleteAllValuesResponse); - // SeedValue stores the string value provided in SecureStorage against the scope and key provided for the current application. - // This is a management API so the stored value will not cause the distributor's storage limits to be exceeded. + + // SeedValue stores the string value provided in SecureStorage against the + // scope and key provided for the current application. This is a management + // API so the stored value will not cause the distributor's storage limits to + // be exceeded. rpc SeedValue(SeedValueRequest) returns (SeedValueResponse); } -// Key is a group of fields that contribute to building the composite key that will be used to store the data in SecureStorage. +// Key is a group of fields that contribute to building the composite key that +// will be used to store the data in SecureStorage. message Key { // key of the key,value pair to be retrieved from SecureStorage. string key = 1; - // Scope describes the extent of the key,value pair. Scope is determined by the distributor. + + // Scope describes the extent of the key,value pair. Scope is determined by + // the distributor. Scope scope = 2; // app_id is the unique identifier of an app or family of apps. string app_id = 3; } -// Value contains the value of the requested data as well as some other relevant fields like scope and expiry useful for the client. +// Value contains the value of the requested data as well as some other +// relevant fields like scope and expiry useful for the client. message Value { // key of the key,value pair that was retrieved from SecureStorage. Key key = 1; - // value is the value associated with the key,value pair retrieved from SecureStorage. + + // value is the value associated with the key,value pair retrieved from + // SecureStorage. string value = 2; - // expiration returns the expire time of the retrieved value. Conforms to AIP-214. + + // expiration returns the expire time of the retrieved value. Conforms to + // AIP-214. oneof expiration { - // Timestamp in UTC of when this resource is considered expired. - // This is *always* provided on output, regardless of what was sent on input. + // Timestamp in UTC of when this resource is considered expired. This is + // *always* provided on output, regardless of what was sent on input. google.protobuf.Timestamp expire_time = 3; // Input only. The TTL for this resource. @@ -52,48 +73,104 @@ message Value { // GetValueRequest is the request to retrieve the SecureStorage data. message GetValueRequest { - // key is the group of fields that contribute to building the composite key that will be used to store the data in SecureStorage. + // XBO ID for the partner making the request + string partner_id = 3; + + // XBO ID for the account making the request + string account_id = 4; + + // XBO ID for the device making the request + string device_id = 2; + + // key is the group of fields that contribute to building the composite key + // that will be used to store the data in SecureStorage. Key key = 1; } -// GetValueResponse is the response containing the value of the requested key within the specified scope. +// GetValueResponse is the response containing the value of the requested key +// within the specified scope. message GetValueResponse { - // value contains the data associated with the key,value pair that was stored in SecureStorage. + // value contains the data associated with the key,value pair that was stored + // in SecureStorage. Value value = 1; } // UpdateValueRequest is the request to store data in SecureStorage. message UpdateValueRequest { - // key is the group of fields that contribute to building the composite key that will be used to store the data in SecureStorage. + // XBO ID for the partner making the request + string partner_id = 3; + + // XBO ID for the account making the request + string account_id = 4; + + // XBO ID for the device making the request + string device_id = 2; + + // The key-value pair that will be upserted into the secure storage database. Value value = 1; } // UpdateValueResponse is the response from the GetValue method. message UpdateValueResponse {} -// DeleteValueRequest is the request to remove a stored value given the key and scope. +// DeleteValueRequest is the request to remove a stored value given the key and +// scope. message DeleteValueRequest { - // key is the group of fields that contribute to building the composite key that will be used to store the data in SecureStorage. + // XBO ID for the partner making the request + string partner_id = 3; + + // XBO ID for the account making the request + string account_id = 4; + + // XBO ID for the device making the request + string device_id = 2; + + // Key is the group of fields that contribute to building the composite key + // that will be used to store the data in SecureStorage. Key key = 1; } // DeleteValueResponse is the response from the DeleteValue method. message DeleteValueResponse {} -// DeleteAllValuesRequest is the request to delete all of the keys associated with an app under the given account. +// DeleteAllValuesRequest is the request to delete all of the keys associated +// with an app under the given account. message DeleteAllValuesRequest { + // XBO ID for the partner making the request + string partner_id = 3; + + // XBO ID for the account making the request + string account_id = 4; + + // XBO ID for the device making the request + string device_id = 5; + // app_id is the unique identifier of an app or family of apps. string app_id = 1; - // Scope describes the extent of the key,value pair. Scope is determined by the distributor. + + // Scope describes the extent of the key,value pair. Scope is determined by + // the distributor. Scope scope = 2; } // DeleteAllValuesResponse is the response from the DeleteAllValues method. message DeleteAllValuesResponse {} -// SeedValueRequest is the request to store data in SecureStorage. Stored data will not cause the distributor's storage limits to be exceeded. +// SeedValueRequest is the request to store data in SecureStorage. Stored data +// will not cause the distributor's storage limits to be exceeded. message SeedValueRequest { - // value contains the data associated with the key,value pair that will be stored in SecureStorage. + // ID of the partner this change applies to. This field is optional IFF + // exactly one partner is provided in the request SAT. + string partner_id = 4; + + // XBO ID for the account making the request + string account_id = 2; + + // XBO ID for the device making the request + string device_id = 3; + + // value contains the data associated with the key,value pair that will be + // stored in SecureStorage. Value value = 1; } @@ -104,8 +181,10 @@ message SeedValueResponse {} enum Scope { // Represents an unset or invalid scope. SCOPE_UNSPECIFIED = 0; + // Account scope. SCOPE_ACCOUNT = 1; + // Device scope. SCOPE_DEVICE = 2; } diff --git a/PersistentStore/l0test/PersistentStoreTest.cpp b/PersistentStore/l0test/PersistentStoreTest.cpp index dfd7d8c980..6d65f5ffe3 100644 --- a/PersistentStore/l0test/PersistentStoreTest.cpp +++ b/PersistentStore/l0test/PersistentStoreTest.cpp @@ -4,9 +4,6 @@ #include "../PersistentStore.h" #include "ServiceMock.h" #include "Store2Mock.h" -#include "StoreCacheMock.h" -#include "StoreInspectorMock.h" -#include "StoreLimitMock.h" using ::testing::_; using ::testing::Eq; @@ -23,6 +20,7 @@ using ::WPEFramework::Exchange::IStoreInspector; using ::WPEFramework::JsonData::PersistentStore::DeleteKeyParamsInfo; using ::WPEFramework::JsonData::PersistentStore::DeleteNamespaceParamsInfo; using ::WPEFramework::JsonData::PersistentStore::GetKeysResultData; +using ::WPEFramework::JsonData::PersistentStore::GetNamespacesParamsInfo; using ::WPEFramework::JsonData::PersistentStore::GetNamespacesResultData; using ::WPEFramework::JsonData::PersistentStore::GetNamespaceStorageLimitResultData; using ::WPEFramework::JsonData::PersistentStore::GetStorageSizesResultData; @@ -69,8 +67,8 @@ TEST_F(APersistentStore, GetsValueInDeviceScopeViaJsonRpc) { EXPECT_CALL(*this, GetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); value = kValue; @@ -106,8 +104,8 @@ TEST_F(APersistentStore, GetsValueInAccountScopeViaJsonRpc) { EXPECT_CALL(*this, GetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) { - EXPECT_THAT(scope, Eq(ScopeType::ACCOUNT)); + [](const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::ACCOUNT)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); value = kValue; @@ -144,8 +142,8 @@ TEST_F(APersistentStore, SetsValueInDeviceScopeViaJsonRpc) { EXPECT_CALL(*this, SetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); EXPECT_THAT(value, Eq(kValue)); @@ -179,8 +177,8 @@ TEST_F(APersistentStore, SetsValueInAccountScopeViaJsonRpc) { EXPECT_CALL(*this, SetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) { - EXPECT_THAT(scope, Eq(ScopeType::ACCOUNT)); + [](const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::ACCOUNT)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); EXPECT_THAT(value, Eq(kValue)); @@ -215,8 +213,8 @@ TEST_F(APersistentStore, DeletesKeyInDeviceScopeViaJsonRpc) { EXPECT_CALL(*this, DeleteKey(_, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns, const string& key) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); return WPEFramework::Core::ERROR_NONE; @@ -246,8 +244,8 @@ TEST_F(APersistentStore, DeletesKeyInAccountScopeViaJsonRpc) { EXPECT_CALL(*this, DeleteKey(_, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key) { - EXPECT_THAT(scope, Eq(ScopeType::ACCOUNT)); + [](const IStore2::ScopeType scope, const string& ns, const string& key) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::ACCOUNT)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); return WPEFramework::Core::ERROR_NONE; @@ -278,8 +276,8 @@ TEST_F(APersistentStore, DeletesNamespaceInDeviceScopeViaJsonRpc) { EXPECT_CALL(*this, DeleteNamespace(_, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); return WPEFramework::Core::ERROR_NONE; })); @@ -307,8 +305,8 @@ TEST_F(APersistentStore, DeletesNamespaceInAccountScopeViaJsonRpc) { EXPECT_CALL(*this, DeleteNamespace(_, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns) { - EXPECT_THAT(scope, Eq(ScopeType::ACCOUNT)); + [](const IStore2::ScopeType scope, const string& ns) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::ACCOUNT)); EXPECT_THAT(ns, Eq(kAppId)); return WPEFramework::Core::ERROR_NONE; })); @@ -331,15 +329,15 @@ TEST_F(APersistentStore, DeletesNamespaceInAccountScopeViaJsonRpc) TEST_F(APersistentStore, FlushesCacheViaJsonRpc) { - class SqliteStoreCache : public NiceMock { + class SqliteStore2 : public NiceMock { public: - SqliteStoreCache() + SqliteStore2() { EXPECT_CALL(*this, FlushCache()) .WillRepeatedly(Return(WPEFramework::Core::ERROR_NONE)); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -351,21 +349,21 @@ TEST_F(APersistentStore, FlushesCacheViaJsonRpc) TEST_F(APersistentStore, GetsKeysInDeviceScopeViaJsonRpc) { - class SqliteStoreInspector : public NiceMock { + class SqliteStore2 : public NiceMock { public: - SqliteStoreInspector() + SqliteStore2() { EXPECT_CALL(*this, GetKeys(_, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, IStringIterator*& keys) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStoreInspector::ScopeType scope, const string& ns, IStringIterator*& keys) { + EXPECT_THAT(scope, Eq(IStoreInspector::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); keys = (WPEFramework::Core::Service::Create(kKeys)); return WPEFramework::Core::ERROR_NONE; })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -387,22 +385,38 @@ TEST_F(APersistentStore, GetsKeysInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } +TEST_F(APersistentStore, DoesNotGetKeysInAccountScopeViaJsonRpc) +{ + ASSERT_THAT(plugin->Initialize(service), Eq("")); + auto jsonRpc = plugin->QueryInterface(); + ASSERT_THAT(jsonRpc, NotNull()); + DeleteNamespaceParamsInfo params; + params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; + params.Namespace = kAppId; + string paramsJsonStr; + params.ToString(paramsJsonStr); + string resultJsonStr; + EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "getKeys", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); + jsonRpc->Release(); + plugin->Deinitialize(service); +} + TEST_F(APersistentStore, GetsNamespacesInDeviceScopeViaJsonRpc) { - class SqliteStoreInspector : public NiceMock { + class SqliteStore2 : public NiceMock { public: - SqliteStoreInspector() + SqliteStore2() { EXPECT_CALL(*this, GetNamespaces(_, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, IStringIterator*& namespaces) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStoreInspector::ScopeType scope, IStringIterator*& namespaces) { + EXPECT_THAT(scope, Eq(IStoreInspector::ScopeType::DEVICE)); namespaces = (WPEFramework::Core::Service::Create(kAppIds)); return WPEFramework::Core::ERROR_NONE; })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -420,22 +434,37 @@ TEST_F(APersistentStore, GetsNamespacesInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } +TEST_F(APersistentStore, DoesNotGetNamespacesInAccountScopeViaJsonRpc) +{ + ASSERT_THAT(plugin->Initialize(service), Eq("")); + auto jsonRpc = plugin->QueryInterface(); + ASSERT_THAT(jsonRpc, NotNull()); + GetNamespacesParamsInfo params; + params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; + string paramsJsonStr; + params.ToString(paramsJsonStr); + string resultJsonStr; + EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "getNamespaces", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); + jsonRpc->Release(); + plugin->Deinitialize(service); +} + TEST_F(APersistentStore, GetsStorageSizesInDeviceScopeViaJsonRpc) { - class SqliteStoreInspector : public NiceMock { + class SqliteStore2 : public NiceMock { public: - SqliteStoreInspector() + SqliteStore2() { EXPECT_CALL(*this, GetStorageSizes(_, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, INamespaceSizeIterator*& storageList) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStoreInspector::ScopeType scope, INamespaceSizeIterator*& storageList) { + EXPECT_THAT(scope, Eq(IStoreInspector::ScopeType::DEVICE)); storageList = (WPEFramework::Core::Service>::Create(kSizes)); return WPEFramework::Core::ERROR_NONE; })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -455,23 +484,38 @@ TEST_F(APersistentStore, GetsStorageSizesInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } +TEST_F(APersistentStore, DoesNotGetStorageSizesInAccountScopeViaJsonRpc) +{ + ASSERT_THAT(plugin->Initialize(service), Eq("")); + auto jsonRpc = plugin->QueryInterface(); + ASSERT_THAT(jsonRpc, NotNull()); + GetNamespacesParamsInfo params; + params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; + string paramsJsonStr; + params.ToString(paramsJsonStr); + string resultJsonStr; + EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "getStorageSizes", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); + jsonRpc->Release(); + plugin->Deinitialize(service); +} + TEST_F(APersistentStore, GetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) { - class SqliteStoreLimit : public NiceMock { + class SqliteStore2 : public NiceMock { public: - SqliteStoreLimit() + SqliteStore2() { EXPECT_CALL(*this, GetNamespaceStorageLimit(_, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, uint32_t& size) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStoreLimit::ScopeType scope, const string& ns, uint32_t& size) { + EXPECT_THAT(scope, Eq(IStoreLimit::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); size = kSize; return WPEFramework::Core::ERROR_NONE; })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -488,23 +532,39 @@ TEST_F(APersistentStore, GetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } +TEST_F(APersistentStore, DoesNotGetNamespaceStorageLimitInAccountScopeViaJsonRpc) +{ + ASSERT_THAT(plugin->Initialize(service), Eq("")); + auto jsonRpc = plugin->QueryInterface(); + ASSERT_THAT(jsonRpc, NotNull()); + DeleteNamespaceParamsInfo params; + params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; + params.Namespace = kAppId; + string paramsJsonStr; + params.ToString(paramsJsonStr); + string resultJsonStr; + EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "getNamespaceStorageLimit", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); + jsonRpc->Release(); + plugin->Deinitialize(service); +} + TEST_F(APersistentStore, SetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) { - class SqliteStoreLimit : public NiceMock { + class SqliteStore2 : public NiceMock { public: - SqliteStoreLimit() + SqliteStore2() { EXPECT_CALL(*this, SetNamespaceStorageLimit(_, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const uint32_t size) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStoreLimit::ScopeType scope, const string& ns, const uint32_t size) { + EXPECT_THAT(scope, Eq(IStoreLimit::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(size, Eq(kSize)); return WPEFramework::Core::ERROR_NONE; })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -519,6 +579,23 @@ TEST_F(APersistentStore, SetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } +TEST_F(APersistentStore, DoesNotSetNamespaceStorageLimitInAccountScopeViaJsonRpc) +{ + ASSERT_THAT(plugin->Initialize(service), Eq("")); + auto jsonRpc = plugin->QueryInterface(); + ASSERT_THAT(jsonRpc, NotNull()); + SetNamespaceStorageLimitParamsData params; + params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; + params.Namespace = kAppId; + params.StorageLimit = kSize; + string paramsJsonStr; + params.ToString(paramsJsonStr); + string resultJsonStr; + EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "setNamespaceStorageLimit", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); + jsonRpc->Release(); + plugin->Deinitialize(service); +} + TEST_F(APersistentStore, GetsValueInDeviceScopeViaIStore) { class SqliteStore2 : public NiceMock { @@ -527,8 +604,8 @@ TEST_F(APersistentStore, GetsValueInDeviceScopeViaIStore) { EXPECT_CALL(*this, GetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); value = kValue; @@ -555,8 +632,8 @@ TEST_F(APersistentStore, SetsValueInDeviceScopeViaIStore) { EXPECT_CALL(*this, SetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); EXPECT_THAT(value, Eq(kValue)); @@ -582,8 +659,8 @@ TEST_F(APersistentStore, DeletesKeyInDeviceScopeViaIStore) { EXPECT_CALL(*this, DeleteKey(_, _, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns, const string& key) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns, const string& key) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); return WPEFramework::Core::ERROR_NONE; @@ -607,8 +684,8 @@ TEST_F(APersistentStore, DeletesNamespaceInDeviceScopeViaIStore) { EXPECT_CALL(*this, DeleteNamespace(_, _)) .WillRepeatedly(Invoke( - [](const ScopeType scope, const string& ns) { - EXPECT_THAT(scope, Eq(ScopeType::DEVICE)); + [](const IStore2::ScopeType scope, const string& ns) { + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); return WPEFramework::Core::ERROR_NONE; })); diff --git a/PersistentStore/l0test/Store2Mock.h b/PersistentStore/l0test/Store2Mock.h index 35ac62674f..a049bcbfc5 100644 --- a/PersistentStore/l0test/Store2Mock.h +++ b/PersistentStore/l0test/Store2Mock.h @@ -2,17 +2,30 @@ #include #include +#include -class Store2Mock : public WPEFramework::Exchange::IStore2 { +class Store2Mock : public WPEFramework::Exchange::IStore2, + public WPEFramework::Exchange::IStoreCache, + public WPEFramework::Exchange::IStoreInspector, + public WPEFramework::Exchange::IStoreLimit { public: ~Store2Mock() override = default; MOCK_METHOD(uint32_t, Register, (INotification*), (override)); MOCK_METHOD(uint32_t, Unregister, (INotification*), (override)); - MOCK_METHOD(uint32_t, SetValue, (const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl), (override)); - MOCK_METHOD(uint32_t, GetValue, (const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl), (override)); - MOCK_METHOD(uint32_t, DeleteKey, (const ScopeType scope, const string& ns, const string& key), (override)); - MOCK_METHOD(uint32_t, DeleteNamespace, (const ScopeType scope, const string& ns), (override)); + MOCK_METHOD(uint32_t, SetValue, (const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl), (override)); + MOCK_METHOD(uint32_t, GetValue, (const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl), (override)); + MOCK_METHOD(uint32_t, DeleteKey, (const IStore2::ScopeType scope, const string& ns, const string& key), (override)); + MOCK_METHOD(uint32_t, DeleteNamespace, (const IStore2::ScopeType scope, const string& ns), (override)); + MOCK_METHOD(uint32_t, FlushCache, (), (override)); + MOCK_METHOD(uint32_t, GetKeys, (const IStoreInspector::ScopeType scope, const string& ns, IStringIterator*& keys), (override)); + MOCK_METHOD(uint32_t, GetNamespaces, (const IStoreInspector::ScopeType scope, IStringIterator*& namespaces), (override)); + MOCK_METHOD(uint32_t, GetStorageSizes, (const IStoreInspector::ScopeType scope, INamespaceSizeIterator*& storageList), (override)); + MOCK_METHOD(uint32_t, GetNamespaceStorageLimit, (const IStoreLimit::ScopeType scope, const string& ns, uint32_t& size), (override)); + MOCK_METHOD(uint32_t, SetNamespaceStorageLimit, (const IStoreLimit::ScopeType scope, const string& ns, const uint32_t size), (override)); BEGIN_INTERFACE_MAP(Store2Mock) INTERFACE_ENTRY(IStore2) + INTERFACE_ENTRY(IStoreCache) + INTERFACE_ENTRY(IStoreInspector) + INTERFACE_ENTRY(IStoreLimit) END_INTERFACE_MAP }; diff --git a/PersistentStore/l0test/StoreCacheMock.h b/PersistentStore/l0test/StoreCacheMock.h deleted file mode 100644 index ed7715a013..0000000000 --- a/PersistentStore/l0test/StoreCacheMock.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include -#include - -class StoreCacheMock : public WPEFramework::Exchange::IStoreCache { -public: - ~StoreCacheMock() override = default; - MOCK_METHOD(uint32_t, FlushCache, (), (override)); - BEGIN_INTERFACE_MAP(StoreCacheMock) - INTERFACE_ENTRY(IStoreCache) - END_INTERFACE_MAP -}; diff --git a/PersistentStore/l0test/StoreInspectorMock.h b/PersistentStore/l0test/StoreInspectorMock.h deleted file mode 100644 index 7765f744a7..0000000000 --- a/PersistentStore/l0test/StoreInspectorMock.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include -#include - -class StoreInspectorMock : public WPEFramework::Exchange::IStoreInspector { -public: - ~StoreInspectorMock() override = default; - MOCK_METHOD(uint32_t, GetKeys, (const ScopeType scope, const string& ns, IStringIterator*& keys), (override)); - MOCK_METHOD(uint32_t, GetNamespaces, (const ScopeType scope, IStringIterator*& namespaces), (override)); - MOCK_METHOD(uint32_t, GetStorageSizes, (const ScopeType scope, INamespaceSizeIterator*& storageList), (override)); - BEGIN_INTERFACE_MAP(StoreInspectorMock) - INTERFACE_ENTRY(IStoreInspector) - END_INTERFACE_MAP -}; diff --git a/PersistentStore/l0test/StoreLimitMock.h b/PersistentStore/l0test/StoreLimitMock.h deleted file mode 100644 index 2b818984e9..0000000000 --- a/PersistentStore/l0test/StoreLimitMock.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include - -class StoreLimitMock : public WPEFramework::Exchange::IStoreLimit { -public: - ~StoreLimitMock() override = default; - MOCK_METHOD(uint32_t, GetNamespaceStorageLimit, (const ScopeType scope, const string& ns, uint32_t& size), (override)); - MOCK_METHOD(uint32_t, SetNamespaceStorageLimit, (const ScopeType scope, const string& ns, const uint32_t size), (override)); - BEGIN_INTERFACE_MAP(StoreLimitMock) - INTERFACE_ENTRY(IStoreLimit) - END_INTERFACE_MAP -}; diff --git a/PersistentStore/sqlite/Store2.h b/PersistentStore/sqlite/Store2.h index d5412da91d..1b9b9bbb13 100644 --- a/PersistentStore/sqlite/Store2.h +++ b/PersistentStore/sqlite/Store2.h @@ -21,6 +21,7 @@ #include "../Module.h" #include +#include #include #ifdef WITH_SYSMGR #include @@ -31,7 +32,10 @@ namespace WPEFramework { namespace Plugin { namespace Sqlite { - class Store2 : public Exchange::IStore2 { + class Store2 : public Exchange::IStore2, + public Exchange::IStoreCache, + public Exchange::IStoreInspector, + public Exchange::IStoreLimit { private: Store2(const Store2&) = delete; Store2& operator=(const Store2&) = delete; @@ -47,6 +51,9 @@ namespace Plugin { } Store2(const string& path, const uint64_t maxSize, const uint64_t maxValue, const uint64_t limit) : IStore2() + , IStoreCache() + , IStoreInspector() + , IStoreLimit() , _path(path) , _maxSize(maxSize) , _maxValue(maxValue) @@ -141,13 +148,9 @@ namespace Plugin { return Core::ERROR_NONE; } - - uint32_t SetValue(const ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) override + uint32_t SetValue(const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) override { - ASSERT(scope == ScopeType::DEVICE); - if (scope != ScopeType::DEVICE) { - return Core::ERROR_GENERAL; - } + ASSERT(scope == IStore2::ScopeType::DEVICE); uint32_t result; @@ -195,12 +198,9 @@ namespace Plugin { return result; } - uint32_t GetValue(const ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) override + uint32_t GetValue(const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) override { - ASSERT(scope == ScopeType::DEVICE); - if (scope != ScopeType::DEVICE) { - return Core::ERROR_GENERAL; - } + ASSERT(scope == IStore2::ScopeType::DEVICE); uint32_t result; @@ -256,12 +256,9 @@ namespace Plugin { return result; } - uint32_t DeleteKey(const ScopeType scope, const string& ns, const string& key) override + uint32_t DeleteKey(const IStore2::ScopeType scope, const string& ns, const string& key) override { - ASSERT(scope == ScopeType::DEVICE); - if (scope != ScopeType::DEVICE) { - return Core::ERROR_GENERAL; - } + ASSERT(scope == IStore2::ScopeType::DEVICE); uint32_t result; @@ -285,12 +282,9 @@ namespace Plugin { return result; } - uint32_t DeleteNamespace(const ScopeType scope, const string& ns) override + uint32_t DeleteNamespace(const IStore2::ScopeType scope, const string& ns) override { - ASSERT(scope == ScopeType::DEVICE); - if (scope != ScopeType::DEVICE) { - return Core::ERROR_GENERAL; - } + ASSERT(scope == IStore2::ScopeType::DEVICE); uint32_t result; @@ -309,9 +303,189 @@ namespace Plugin { return result; } + uint32_t FlushCache() override + { + uint32_t result; + + auto rc = sqlite3_db_cacheflush(_data); + + if (rc == SQLITE_OK) { + result = Core::ERROR_NONE; + } else { + OnError(__FUNCTION__, rc); + result = Core::ERROR_GENERAL; + } + + sync(); + + return result; + } + uint32_t GetKeys(const IStoreInspector::ScopeType scope, const string& ns, RPC::IStringIterator*& keys) override + { + ASSERT(scope == IStoreInspector::ScopeType::DEVICE); + + uint32_t result; + + sqlite3_stmt* stmt; + sqlite3_prepare_v2(_data, "select key" + " from item" + " where ns in (select id from namespace where name = ?)" + ";", + -1, &stmt, nullptr); + sqlite3_bind_text(stmt, 1, ns.c_str(), -1, SQLITE_TRANSIENT); + std::list list; + int rc; + while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { + list.emplace_back((const char*)sqlite3_column_text(stmt, 0)); + } + sqlite3_finalize(stmt); + + if (rc == SQLITE_DONE) { + keys = (Core::Service::Create(list)); + result = Core::ERROR_NONE; + } else { + OnError(__FUNCTION__, rc); + result = Core::ERROR_GENERAL; + } + + return result; + } + uint32_t GetNamespaces(const IStoreInspector::ScopeType scope, RPC::IStringIterator*& namespaces) override + { + ASSERT(scope == IStoreInspector::ScopeType::DEVICE); + + uint32_t result; + + sqlite3_stmt* stmt; + sqlite3_prepare_v2(_data, "select name from namespace;", -1, &stmt, nullptr); + std::list list; + int rc; + while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { + list.emplace_back((const char*)sqlite3_column_text(stmt, 0)); + } + sqlite3_finalize(stmt); + + if (rc == SQLITE_DONE) { + namespaces = (Core::Service::Create(list)); + result = Core::ERROR_NONE; + } else { + OnError(__FUNCTION__, rc); + result = Core::ERROR_GENERAL; + } + + return result; + } + uint32_t GetStorageSizes(const IStoreInspector::ScopeType scope, INamespaceSizeIterator*& storageList) override + { + ASSERT(scope == IStoreInspector::ScopeType::DEVICE); + + uint32_t result; + + sqlite3_stmt* stmt; + sqlite3_prepare_v2(_data, "select name, sum(length(key)+length(value))" + " from item" + " inner join namespace on namespace.id = item.ns" + " group by name" + ";", + -1, &stmt, nullptr); + std::list list; + int rc; + while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { + NamespaceSize namespaceSize; + namespaceSize.ns = (const char*)sqlite3_column_text(stmt, 0); + namespaceSize.size = sqlite3_column_int(stmt, 1); + list.emplace_back(namespaceSize); + } + sqlite3_finalize(stmt); + + if (rc == SQLITE_DONE) { + storageList = (Core::Service>::Create(list)); + result = Core::ERROR_NONE; + } else { + OnError(__FUNCTION__, rc); + result = Core::ERROR_GENERAL; + } + + return result; + } + uint32_t SetNamespaceStorageLimit(const IStoreLimit::ScopeType scope, const string& ns, const uint32_t size) override + { + ASSERT(scope == IStoreLimit::ScopeType::DEVICE); + + uint32_t result; + + sqlite3_stmt* stmt; + sqlite3_prepare_v2(_data, "insert or ignore into namespace (name) values (?);", + -1, &stmt, nullptr); + sqlite3_bind_text(stmt, 1, ns.c_str(), -1, SQLITE_TRANSIENT); + auto rc = sqlite3_step(stmt); + sqlite3_finalize(stmt); + if (rc == SQLITE_DONE) { + sqlite3_prepare_v2(_data, "insert into limits (n,size)" + " select id, ?" + " from namespace" + " where name = ?" + ";", + -1, &stmt, nullptr); + sqlite3_bind_int(stmt, 1, size); + sqlite3_bind_text(stmt, 2, ns.c_str(), -1, SQLITE_TRANSIENT); + rc = sqlite3_step(stmt); + sqlite3_finalize(stmt); + } + + if (rc == SQLITE_DONE) { + result = Core::ERROR_NONE; + } else { + OnError(__FUNCTION__, rc); + if (rc == SQLITE_CONSTRAINT) { + result = Core::ERROR_INVALID_INPUT_LENGTH; + } else { + result = Core::ERROR_GENERAL; + } + } + + return result; + } + uint32_t GetNamespaceStorageLimit(const IStoreLimit::ScopeType scope, const string& ns, uint32_t& size) override + { + ASSERT(scope == IStoreLimit::ScopeType::DEVICE); + + uint32_t result; + + uint32_t s; + sqlite3_stmt* stmt; + sqlite3_prepare_v2(_data, "select size" + " from limits" + " inner join namespace on namespace.id = limits.n" + " where name = ?" + ";", + -1, &stmt, nullptr); + sqlite3_bind_text(stmt, 1, ns.c_str(), -1, SQLITE_TRANSIENT); + auto rc = sqlite3_step(stmt); + if (rc == SQLITE_ROW) { + s = (uint32_t)sqlite3_column_int(stmt, 0); + result = Core::ERROR_NONE; + } + sqlite3_finalize(stmt); + + if (rc == SQLITE_ROW) { + size = s; + result = Core::ERROR_NONE; + } else if (rc == SQLITE_DONE) { + result = Core::ERROR_NOT_EXIST; + } else { + OnError(__FUNCTION__, rc); + result = Core::ERROR_GENERAL; + } + + return result; + } BEGIN_INTERFACE_MAP(Store2) INTERFACE_ENTRY(IStore2) + INTERFACE_ENTRY(IStoreCache) + INTERFACE_ENTRY(IStoreInspector) + INTERFACE_ENTRY(IStoreLimit) END_INTERFACE_MAP private: @@ -323,7 +497,7 @@ namespace Plugin { index(_clients.begin()); while (index != _clients.end()) { - (*index)->ValueChanged(ScopeType::DEVICE, ns, key, value); + (*index)->ValueChanged(IStore2::ScopeType::DEVICE, ns, key, value); index++; } } diff --git a/PersistentStore/sqlite/StoreCache.cpp b/PersistentStore/sqlite/StoreCache.cpp deleted file mode 100644 index ec05da258b..0000000000 --- a/PersistentStore/sqlite/StoreCache.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "StoreCache.h" - -namespace WPEFramework { -namespace Plugin { - class SqliteStoreCache : public Sqlite::StoreCache {}; - SERVICE_REGISTRATION(SqliteStoreCache, 1, 0); -} // namespace Plugin -} // namespace WPEFramework diff --git a/PersistentStore/sqlite/StoreCache.h b/PersistentStore/sqlite/StoreCache.h deleted file mode 100644 index d6811766af..0000000000 --- a/PersistentStore/sqlite/StoreCache.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2022 RDK Management - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "../Module.h" -#include -#include - -namespace WPEFramework { -namespace Plugin { - namespace Sqlite { - - class StoreCache : public Exchange::IStoreCache { - private: - StoreCache(const StoreCache&) = delete; - StoreCache& operator=(const StoreCache&) = delete; - - public: - StoreCache() - : StoreCache(getenv(PATH_ENV)) - { - } - StoreCache(const string& path) - : IStoreCache() - , _path(path) - { - Open(); - } - ~StoreCache() override - { - Close(); - } - - private: - void Open() - { - Core::File file(_path); - Core::Directory(file.PathName().c_str()).CreatePath(); - auto rc = sqlite3_open(_path.c_str(), &_data); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - const std::vector statements = { - "pragma busy_timeout = 1000000;" - }; - for (auto& sql : statements) { - auto rc = sqlite3_exec(_data, sql.c_str(), nullptr, nullptr, nullptr); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - } - } - void Close() - { - auto rc = sqlite3_close_v2(_data); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - } - - public: - uint32_t FlushCache() override - { - uint32_t result; - - auto rc = sqlite3_db_cacheflush(_data); - - if (rc == SQLITE_OK) { - result = Core::ERROR_NONE; - } else { - OnError(__FUNCTION__, rc); - result = Core::ERROR_GENERAL; - } - - sync(); - - return result; - } - - BEGIN_INTERFACE_MAP(StoreCache) - INTERFACE_ENTRY(IStoreCache) - END_INTERFACE_MAP - - private: - void OnError(const char* fn, const int status) const - { - TRACE(Trace::Error, (_T("%s sqlite error %d"), fn, status)); - } - - private: - const string _path; - sqlite3* _data; - }; - - } // namespace Sqlite -} // namespace Plugin -} // namespace WPEFramework diff --git a/PersistentStore/sqlite/StoreInspector.cpp b/PersistentStore/sqlite/StoreInspector.cpp deleted file mode 100644 index 543faab05a..0000000000 --- a/PersistentStore/sqlite/StoreInspector.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "StoreInspector.h" - -namespace WPEFramework { -namespace Plugin { - class SqliteStoreInspector : public Sqlite::StoreInspector {}; - SERVICE_REGISTRATION(SqliteStoreInspector, 1, 0); -} // namespace Plugin -} // namespace WPEFramework diff --git a/PersistentStore/sqlite/StoreInspector.h b/PersistentStore/sqlite/StoreInspector.h deleted file mode 100644 index 94cf92a043..0000000000 --- a/PersistentStore/sqlite/StoreInspector.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2022 RDK Management - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "../Module.h" -#include -#include - -namespace WPEFramework { -namespace Plugin { - namespace Sqlite { - - class StoreInspector : public Exchange::IStoreInspector { - private: - StoreInspector(const StoreInspector&) = delete; - StoreInspector& operator=(const StoreInspector&) = delete; - - typedef RPC::IteratorType NamespaceSizeIterator; - - public: - StoreInspector() - : StoreInspector(getenv(PATH_ENV)) - { - } - StoreInspector(const string& path) - : IStoreInspector() - , _path(path) - { - Open(); - } - ~StoreInspector() override - { - Close(); - } - - private: - void Open() - { - Core::File file(_path); - Core::Directory(file.PathName().c_str()).CreatePath(); - auto rc = sqlite3_open(_path.c_str(), &_data); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - const std::vector statements = { - "pragma foreign_keys = on;", - "pragma busy_timeout = 1000000;", - "create table if not exists namespace (id integer primary key,name text unique);", - "create table if not exists item (ns integer,key text,value text,foreign key(ns) references namespace(id) on delete cascade on update no action,unique(ns,key) on conflict replace);" - }; - for (auto& sql : statements) { - auto rc = sqlite3_exec(_data, sql.c_str(), nullptr, nullptr, nullptr); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - } - } - void Close() - { - auto rc = sqlite3_close_v2(_data); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - } - - public: - uint32_t GetKeys(const ScopeType scope, const string& ns, RPC::IStringIterator*& keys) override - { - ASSERT(scope == ScopeType::DEVICE); - if (scope != ScopeType::DEVICE) { - return Core::ERROR_GENERAL; - } - - uint32_t result; - - sqlite3_stmt* stmt; - sqlite3_prepare_v2(_data, "select key" - " from item" - " where ns in (select id from namespace where name = ?)" - ";", - -1, &stmt, nullptr); - sqlite3_bind_text(stmt, 1, ns.c_str(), -1, SQLITE_TRANSIENT); - std::list list; - int rc; - while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { - list.emplace_back((const char*)sqlite3_column_text(stmt, 0)); - } - sqlite3_finalize(stmt); - - if (rc == SQLITE_DONE) { - keys = (Core::Service::Create(list)); - result = Core::ERROR_NONE; - } else { - OnError(__FUNCTION__, rc); - result = Core::ERROR_GENERAL; - } - - return result; - } - uint32_t GetNamespaces(const ScopeType scope, RPC::IStringIterator*& namespaces) override - { - ASSERT(scope == ScopeType::DEVICE); - if (scope != ScopeType::DEVICE) { - return Core::ERROR_GENERAL; - } - - uint32_t result; - - sqlite3_stmt* stmt; - sqlite3_prepare_v2(_data, "select name from namespace;", -1, &stmt, nullptr); - std::list list; - int rc; - while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { - list.emplace_back((const char*)sqlite3_column_text(stmt, 0)); - } - sqlite3_finalize(stmt); - - if (rc == SQLITE_DONE) { - namespaces = (Core::Service::Create(list)); - result = Core::ERROR_NONE; - } else { - OnError(__FUNCTION__, rc); - result = Core::ERROR_GENERAL; - } - - return result; - } - uint32_t GetStorageSizes(const ScopeType scope, INamespaceSizeIterator*& storageList) override - { - ASSERT(scope == ScopeType::DEVICE); - if (scope != ScopeType::DEVICE) { - return Core::ERROR_GENERAL; - } - - uint32_t result; - - sqlite3_stmt* stmt; - sqlite3_prepare_v2(_data, "select name, sum(length(key)+length(value))" - " from item" - " inner join namespace on namespace.id = item.ns" - " group by name" - ";", - -1, &stmt, nullptr); - std::list list; - int rc; - while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) { - NamespaceSize namespaceSize; - namespaceSize.ns = (const char*)sqlite3_column_text(stmt, 0); - namespaceSize.size = sqlite3_column_int(stmt, 1); - list.emplace_back(namespaceSize); - } - sqlite3_finalize(stmt); - - if (rc == SQLITE_DONE) { - storageList = (Core::Service::Create(list)); - result = Core::ERROR_NONE; - } else { - OnError(__FUNCTION__, rc); - result = Core::ERROR_GENERAL; - } - - return result; - } - - BEGIN_INTERFACE_MAP(StoreInspector) - INTERFACE_ENTRY(IStoreInspector) - END_INTERFACE_MAP - - private: - void OnError(const char* fn, const int status) const - { - TRACE(Trace::Error, (_T("%s sqlite error %d"), fn, status)); - } - - private: - const string _path; - sqlite3* _data; - }; - - } // namespace Sqlite -} // namespace Plugin -} // namespace WPEFramework diff --git a/PersistentStore/sqlite/StoreLimit.cpp b/PersistentStore/sqlite/StoreLimit.cpp deleted file mode 100644 index c37cd1507a..0000000000 --- a/PersistentStore/sqlite/StoreLimit.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "StoreLimit.h" - -namespace WPEFramework { -namespace Plugin { - class SqliteStoreLimit : public Sqlite::StoreLimit {}; - SERVICE_REGISTRATION(SqliteStoreLimit, 1, 0); -} // namespace Plugin -} // namespace WPEFramework diff --git a/PersistentStore/sqlite/StoreLimit.h b/PersistentStore/sqlite/StoreLimit.h deleted file mode 100644 index 145b71d174..0000000000 --- a/PersistentStore/sqlite/StoreLimit.h +++ /dev/null @@ -1,189 +0,0 @@ -/* - * If not stated otherwise in this file or this component's LICENSE file the - * following copyright and licenses apply: - * - * Copyright 2022 RDK Management - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "../Module.h" -#include -#include - -namespace WPEFramework { -namespace Plugin { - namespace Sqlite { - - class StoreLimit : public Exchange::IStoreLimit { - private: - StoreLimit(const StoreLimit&) = delete; - StoreLimit& operator=(const StoreLimit&) = delete; - - public: - StoreLimit() - : StoreLimit( - getenv(PATH_ENV), - std::stoul(getenv(MAXSIZE_ENV)), - std::stoul(getenv(MAXVALUE_ENV))) - { - } - StoreLimit(const string& path, const uint64_t maxSize, const uint64_t maxValue) - : IStoreLimit() - , _path(path) - , _maxSize(maxSize) - , _maxValue(maxValue) - { - Open(); - } - ~StoreLimit() override - { - Close(); - } - - private: - void Open() - { - Core::File file(_path); - Core::Directory(file.PathName().c_str()).CreatePath(); - auto rc = sqlite3_open(_path.c_str(), &_data); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - const std::vector statements = { - "pragma foreign_keys = on;", - "pragma busy_timeout = 1000000;", - "create table if not exists namespace (id integer primary key,name text unique);", - "create table if not exists item (ns integer,key text,value text,foreign key(ns) references namespace(id) on delete cascade on update no action,unique(ns,key) on conflict replace);", - "create table if not exists limits (n integer,size integer,foreign key(n) references namespace(id) on delete cascade on update no action,unique(n) on conflict replace);", - "create temporary trigger if not exists ns_empty insert on namespace begin select case when length(new.name) = 0 then raise (fail, 'empty') end; end;", - "create temporary trigger if not exists ns_maxvalue insert on namespace begin select case when length(new.name) > " + std::to_string(_maxValue) + " then raise (fail, 'max value') end; end;", - "create temporary trigger if not exists ns_maxsize insert on namespace begin select case when (select sum(s) from (select sum(length(key)+length(value)) s from item union all select sum(length(name)) s from namespace union all select length(new.name) s)) > " + std::to_string(_maxSize) + " then raise (fail, 'max size') end; end;" - }; - for (auto& sql : statements) { - auto rc = sqlite3_exec(_data, sql.c_str(), nullptr, nullptr, nullptr); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - } - } - void Close() - { - auto rc = sqlite3_close_v2(_data); - if (rc != SQLITE_OK) { - OnError(__FUNCTION__, rc); - } - } - - public: - uint32_t SetNamespaceStorageLimit(const ScopeType scope, const string& ns, const uint32_t size) override - { - ASSERT(scope == ScopeType::DEVICE); - if (scope != ScopeType::DEVICE) { - return Core::ERROR_GENERAL; - } - - uint32_t result; - - sqlite3_stmt* stmt; - sqlite3_prepare_v2(_data, "insert or ignore into namespace (name) values (?);", - -1, &stmt, nullptr); - sqlite3_bind_text(stmt, 1, ns.c_str(), -1, SQLITE_TRANSIENT); - auto rc = sqlite3_step(stmt); - sqlite3_finalize(stmt); - if (rc == SQLITE_DONE) { - sqlite3_prepare_v2(_data, "insert into limits (n,size)" - " select id, ?" - " from namespace" - " where name = ?" - ";", - -1, &stmt, nullptr); - sqlite3_bind_int(stmt, 1, size); - sqlite3_bind_text(stmt, 2, ns.c_str(), -1, SQLITE_TRANSIENT); - rc = sqlite3_step(stmt); - sqlite3_finalize(stmt); - } - - if (rc == SQLITE_DONE) { - result = Core::ERROR_NONE; - } else { - OnError(__FUNCTION__, rc); - if (rc == SQLITE_CONSTRAINT) { - result = Core::ERROR_INVALID_INPUT_LENGTH; - } else { - result = Core::ERROR_GENERAL; - } - } - - return result; - } - uint32_t GetNamespaceStorageLimit(const ScopeType scope, const string& ns, uint32_t& size) override - { - ASSERT(scope == ScopeType::DEVICE); - if (scope != ScopeType::DEVICE) { - return Core::ERROR_GENERAL; - } - - uint32_t result; - - uint32_t s; - sqlite3_stmt* stmt; - sqlite3_prepare_v2(_data, "select size" - " from limits" - " inner join namespace on namespace.id = limits.n" - " where name = ?" - ";", - -1, &stmt, nullptr); - sqlite3_bind_text(stmt, 1, ns.c_str(), -1, SQLITE_TRANSIENT); - auto rc = sqlite3_step(stmt); - if (rc == SQLITE_ROW) { - s = (uint32_t)sqlite3_column_int(stmt, 0); - result = Core::ERROR_NONE; - } - sqlite3_finalize(stmt); - - if (rc == SQLITE_ROW) { - size = s; - result = Core::ERROR_NONE; - } else if (rc == SQLITE_DONE) { - result = Core::ERROR_NOT_EXIST; - } else { - OnError(__FUNCTION__, rc); - result = Core::ERROR_GENERAL; - } - - return result; - } - - BEGIN_INTERFACE_MAP(StoreLimit) - INTERFACE_ENTRY(IStoreLimit) - END_INTERFACE_MAP - - private: - void OnError(const char* fn, const int status) const - { - TRACE(Trace::Error, (_T("%s sqlite error %d"), fn, status)); - } - - private: - const string _path; - const uint64_t _maxSize; - const uint64_t _maxValue; - sqlite3* _data; - }; - - } // namespace Sqlite -} // namespace Plugin -} // namespace WPEFramework diff --git a/PersistentStore/sqlite/l1test/CMakeLists.txt b/PersistentStore/sqlite/l1test/CMakeLists.txt index 168d5ee7bc..698833ebf3 100644 --- a/PersistentStore/sqlite/l1test/CMakeLists.txt +++ b/PersistentStore/sqlite/l1test/CMakeLists.txt @@ -34,9 +34,6 @@ find_package(${NAMESPACE}Plugins REQUIRED) add_executable(${PROJECT_NAME} ../../Module.cpp Store2Test.cpp - StoreCacheTest.cpp - StoreInspectorTest.cpp - StoreLimitTest.cpp ) target_link_libraries(${PROJECT_NAME} PRIVATE diff --git a/PersistentStore/sqlite/l1test/Store2Test.cpp b/PersistentStore/sqlite/l1test/Store2Test.cpp index 9d30c9471d..2ee78da6a4 100644 --- a/PersistentStore/sqlite/l1test/Store2Test.cpp +++ b/PersistentStore/sqlite/l1test/Store2Test.cpp @@ -8,11 +8,18 @@ using ::testing::_; using ::testing::Eq; using ::testing::Gt; using ::testing::Invoke; +using ::testing::IsFalse; +using ::testing::IsTrue; using ::testing::Le; using ::testing::NiceMock; +using ::testing::NotNull; using ::testing::Test; using ::WPEFramework::Exchange::IStore2; +using ::WPEFramework::Exchange::IStoreCache; +using ::WPEFramework::Exchange::IStoreInspector; +using ::WPEFramework::Exchange::IStoreLimit; using ::WPEFramework::Plugin::Sqlite::Store2; +using ::WPEFramework::RPC::IStringIterator; const auto kPath = "/tmp/persistentstore/sqlite/l1test/store2test"; const auto kMaxSize = 100; @@ -23,82 +30,80 @@ const auto kKey = "key_1"; const auto kAppId = "app_id_1"; const auto kTtl = 2; const auto kNoTtl = 0; -const auto kScope = IStore2::ScopeType::DEVICE; const auto kEmpty = ""; const auto kOversize = "this is too large"; const auto kUnknown = "unknown"; +const auto kLimit20 = 20; +const auto kLimit30 = 30; +const auto kLimit40 = 40; class AStore2 : public Test { protected: - IStore2* store2; + WPEFramework::Core::ProxyType store2; AStore2() - : store2(WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit)) + : store2(WPEFramework::Core::ProxyType::Create(kPath, kMaxSize, kMaxValue, kLimit)) { } - ~AStore2() override - { - store2->Release(); - } }; TEST_F(AStore2, DoesNotSetValueWhenNamespaceEmpty) { - EXPECT_THAT(store2->SetValue(kScope, kEmpty, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kEmpty, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); } TEST_F(AStore2, DoesNotSetValueWhenKeyEmpty) { - EXPECT_THAT(store2->SetValue(kScope, kAppId, kEmpty, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kEmpty, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); } TEST_F(AStore2, DoesNotSetValueWhenNamespaceOversize) { - EXPECT_THAT(store2->SetValue(kScope, kOversize, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kOversize, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); } TEST_F(AStore2, DoesNotSetValueWhenKeyOversize) { - EXPECT_THAT(store2->SetValue(kScope, kAppId, kOversize, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kOversize, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); } TEST_F(AStore2, DoesNotSetValueWhenValueOversize) { - EXPECT_THAT(store2->SetValue(kScope, kAppId, kKey, kOversize, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kOversize, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); } TEST_F(AStore2, DoesNotGetValueWhenNamespaceUnknown) { string value; uint32_t ttl; - EXPECT_THAT(store2->GetValue(kScope, kUnknown, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NOT_EXIST)); + EXPECT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kUnknown, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NOT_EXIST)); } TEST_F(AStore2, DeletesKeyWhenNamespaceUnknown) { - EXPECT_THAT(store2->DeleteKey(kScope, kUnknown, kKey), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteKey(IStore2::ScopeType::DEVICE, kUnknown, kKey), Eq(WPEFramework::Core::ERROR_NONE)); } TEST_F(AStore2, DeletesNamespaceWhenNamespaceUnknown) { - EXPECT_THAT(store2->DeleteNamespace(kScope, kUnknown), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, kUnknown), Eq(WPEFramework::Core::ERROR_NONE)); } TEST_F(AStore2, SetsValueWhenValueEmpty) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kEmpty, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kEmpty, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); string value; uint32_t ttl; - ASSERT_THAT(store2->GetValue(kScope, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NONE)); EXPECT_THAT(value, Eq(kEmpty)); EXPECT_THAT(ttl, Eq(kNoTtl)); } TEST_F(AStore2, GetsValueWhenTtlNotExpired) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kTtl), Eq(WPEFramework::Core::ERROR_NONE)); string value; uint32_t ttl; - ASSERT_THAT(store2->GetValue(kScope, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NONE)); EXPECT_THAT(value, Eq(kValue)); EXPECT_THAT(ttl, Le(kTtl)); EXPECT_THAT(ttl, Gt(kNoTtl)); @@ -106,12 +111,12 @@ TEST_F(AStore2, GetsValueWhenTtlNotExpired) TEST_F(AStore2, DoesNotGetValueWhenTtlExpired) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kTtl), Eq(WPEFramework::Core::ERROR_NONE)); WPEFramework::Core::Event lock(false, true); lock.Lock(kTtl * WPEFramework::Core::Time::MilliSecondsPerSecond); string value; uint32_t ttl; - EXPECT_THAT(store2->GetValue(kScope, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); + EXPECT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); } TEST_F(AStore2, ValueChangedWhenSetValue) @@ -123,7 +128,7 @@ TEST_F(AStore2, ValueChangedWhenSetValue) EXPECT_CALL(*this, ValueChanged(_, _, _, _)) .WillRepeatedly(Invoke( [](const IStore2::ScopeType scope, const string& ns, const string& key, const string& value) { - EXPECT_THAT(scope, Eq(kScope)); + EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); EXPECT_THAT(value, Eq(kValue)); @@ -133,50 +138,170 @@ TEST_F(AStore2, ValueChangedWhenSetValue) }; WPEFramework::Core::Sink sink; store2->Register(&sink); - EXPECT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); store2->Unregister(&sink); } TEST_F(AStore2, DoesNotGetValueWhenKeyUnknown) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); string value; uint32_t ttl; - EXPECT_THAT(store2->GetValue(kScope, kAppId, kUnknown, value, ttl), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); + EXPECT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kAppId, kUnknown, value, ttl), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); } TEST_F(AStore2, DeletesKeyWhenKeyUnknown) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->DeleteKey(kScope, kAppId, kUnknown), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteKey(IStore2::ScopeType::DEVICE, kAppId, kUnknown), Eq(WPEFramework::Core::ERROR_NONE)); } TEST_F(AStore2, DeletesKey) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->DeleteKey(kScope, kAppId, kKey), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->DeleteKey(IStore2::ScopeType::DEVICE, kAppId, kKey), Eq(WPEFramework::Core::ERROR_NONE)); string value; uint32_t ttl; - EXPECT_THAT(store2->GetValue(kScope, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); + EXPECT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); } TEST_F(AStore2, DeletesNamespace) { - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->DeleteNamespace(kScope, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); string value; uint32_t ttl; - EXPECT_THAT(store2->GetValue(kScope, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NOT_EXIST)); + EXPECT_THAT(store2->GetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, value, ttl), Eq(WPEFramework::Core::ERROR_NOT_EXIST)); } TEST_F(AStore2, DoesNotSetValueWhenReachedMaxSize) { - ASSERT_THAT(store2->DeleteNamespace(kScope, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "8InMXXU4hM", "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "XhrICnuerw", "jPKODBDk5K", "d3BarkA5xF", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "WNeBknDDI2", "GC96ZN6Fuq", "IBF2E1MLQh", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "8InMXXU4hM"), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "XhrICnuerw"), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "WNeBknDDI2"), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "8InMXXU4hM", "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "XhrICnuerw", "jPKODBDk5K", "d3BarkA5xF", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "WNeBknDDI2", "GC96ZN6Fuq", "IBF2E1MLQh", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "8InMXXU4hM"), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "XhrICnuerw"), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "WNeBknDDI2"), Eq(WPEFramework::Core::ERROR_NONE)); +} + +TEST_F(AStore2, FlushesCache) +{ + EXPECT_THAT(store2->FlushCache(), Eq(WPEFramework::Core::ERROR_NONE)); +} + +TEST_F(AStore2, GetsKeysWhenNamespaceUnknown) +{ + IStringIterator* it; + ASSERT_THAT(store2->GetKeys(IStoreInspector::ScopeType::DEVICE, kUnknown, it), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(it, NotNull()); + string element; + EXPECT_THAT(it->Next(element), IsFalse()); + it->Release(); +} + +TEST_F(AStore2, GetsKeys) +{ + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + IStringIterator* it; + ASSERT_THAT(store2->GetKeys(IStoreInspector::ScopeType::DEVICE, kAppId, it), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(it, NotNull()); + string element; + ASSERT_THAT(it->Next(element), IsTrue()); + EXPECT_THAT(element, Eq(kKey)); + EXPECT_THAT(it->Next(element), IsFalse()); + it->Release(); +} + +TEST_F(AStore2, GetsNamespaces) +{ + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + IStringIterator* it; + ASSERT_THAT(store2->GetNamespaces(IStoreInspector::ScopeType::DEVICE, it), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(it, NotNull()); + string element; + ASSERT_THAT(it->Next(element), IsTrue()); + EXPECT_THAT(element, Eq(kAppId)); + EXPECT_THAT(it->Next(element), IsFalse()); + it->Release(); +} + +TEST_F(AStore2, GetsStorageSizes) +{ + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + IStoreInspector::INamespaceSizeIterator* it; + ASSERT_THAT(store2->GetStorageSizes(IStoreInspector::ScopeType::DEVICE, it), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(it, NotNull()); + IStoreInspector::NamespaceSize element; + ASSERT_THAT(it->Next(element), IsTrue()); + EXPECT_THAT(element.ns, Eq(kAppId)); + EXPECT_THAT(element.size, Eq(strlen(kKey) + strlen(kValue))); + EXPECT_THAT(it->Next(element), IsFalse()); + it->Release(); +} + +TEST_F(AStore2, DoesNotGetNamespaceStorageLimitWhenNamespaceUnknown) +{ + uint32_t value; + EXPECT_THAT(store2->GetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kUnknown, value), Eq(WPEFramework::Core::ERROR_NOT_EXIST)); +} + +TEST_F(AStore2, DoesNotSetNamespaceStorageLimitWhenNamespaceEmpty) +{ + EXPECT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kEmpty, kLimit20), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); +} + +TEST_F(AStore2, DoesNotSetNamespaceStorageLimitWhenNamespaceOversize) +{ + EXPECT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kOversize, kLimit20), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); +} + +TEST_F(AStore2, SetsNamespaceStorageLimit) +{ + ASSERT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, kLimit20), Eq(WPEFramework::Core::ERROR_NONE)); + uint32_t value; + ASSERT_THAT(store2->GetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, value), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(value, Eq(kLimit20)); +} + +TEST_F(AStore2, SetsNamespaceStorageLimitWhenAlreadySet) +{ + ASSERT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, kLimit30), Eq(WPEFramework::Core::ERROR_NONE)); + uint32_t value; + ASSERT_THAT(store2->GetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, value), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(value, Eq(kLimit30)); + ASSERT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, kLimit40), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->GetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, value), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(value, Eq(kLimit40)); +} + +TEST_F(AStore2, DoesNotSetNamespaceStorageLimitWhenReachedMaxSize) +{ + ASSERT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "8InMXXU4hM", "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "XhrICnuerw", "jPKODBDk5K", "d3BarkA5xF", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "WNeBknDDI2", "GC96ZN6Fuq", "IBF2E1MLQh", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, "V92", "R1R", "rHk", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, kLimit), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "8InMXXU4hM"), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "XhrICnuerw"), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "WNeBknDDI2"), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, "V92"), Eq(WPEFramework::Core::ERROR_NONE)); +} + +TEST_F(AStore2, EnforcesSetValueToFailWhenReachedDefaultLimit) +{ + ASSERT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, "jPKODBDk5K", "d3BarkA5xF", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); +} + +TEST_F(AStore2, EnforcesSetValueToFailWhenReachedLimit) +{ + ASSERT_THAT(store2->DeleteNamespace(IStore2::ScopeType::DEVICE, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); + EXPECT_THAT(store2->SetNamespaceStorageLimit(IStoreLimit::ScopeType::DEVICE, kAppId, kLimit20), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); + ASSERT_THAT(store2->SetValue(IStore2::ScopeType::DEVICE, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); } diff --git a/PersistentStore/sqlite/l1test/StoreCacheTest.cpp b/PersistentStore/sqlite/l1test/StoreCacheTest.cpp deleted file mode 100644 index 5d2af5fd1d..0000000000 --- a/PersistentStore/sqlite/l1test/StoreCacheTest.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -#include "../StoreCache.h" - -using ::testing::Eq; -using ::testing::Test; -using ::WPEFramework::Exchange::IStoreCache; -using ::WPEFramework::Plugin::Sqlite::StoreCache; - -const auto kPath = "/tmp/persistentstore/sqlite/l1test/storecachetest"; - -class AStoreCache : public Test { -protected: - IStoreCache* cache; - AStoreCache() - : cache(WPEFramework::Core::Service::Create(kPath)) - { - } - ~AStoreCache() override - { - cache->Release(); - } -}; - -TEST_F(AStoreCache, FlushesCache) -{ - EXPECT_THAT(cache->FlushCache(), Eq(WPEFramework::Core::ERROR_NONE)); -} diff --git a/PersistentStore/sqlite/l1test/StoreInspectorTest.cpp b/PersistentStore/sqlite/l1test/StoreInspectorTest.cpp deleted file mode 100644 index ec3dd3866f..0000000000 --- a/PersistentStore/sqlite/l1test/StoreInspectorTest.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include - -#include "../Store2.h" -#include "../StoreInspector.h" - -using ::testing::Eq; -using ::testing::IsFalse; -using ::testing::IsTrue; -using ::testing::NotNull; -using ::testing::Test; -using ::WPEFramework::Exchange::IStore2; -using ::WPEFramework::Exchange::IStoreInspector; -using ::WPEFramework::Plugin::Sqlite::Store2; -using ::WPEFramework::Plugin::Sqlite::StoreInspector; -using ::WPEFramework::RPC::IStringIterator; - -const auto kPath = "/tmp/persistentstore/sqlite/l1test/storeinspectortest"; -const auto kMaxSize = 100; -const auto kMaxValue = 10; -const auto kLimit = 50; -const auto kValue = "value_1"; -const auto kKey = "key_1"; -const auto kAppId = "app_id_1"; -const auto kNoTtl = 0; -const auto kScope = IStoreInspector::ScopeType::DEVICE; -const auto kUnknown = "unknown"; - -class AStoreInspector : public Test { -protected: - IStoreInspector* inspector; - AStoreInspector() - : inspector(WPEFramework::Core::Service::Create(kPath)) - { - } - ~AStoreInspector() override - { - inspector->Release(); - } -}; - -TEST_F(AStoreInspector, GetsKeysWhenNamespaceUnknown) -{ - IStringIterator* it; - ASSERT_THAT(inspector->GetKeys(kScope, kUnknown, it), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(it, NotNull()); - string element; - EXPECT_THAT(it->Next(element), IsFalse()); - it->Release(); -} - -TEST_F(AStoreInspector, GetsKeys) -{ - auto store2 = WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit); - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - store2->Release(); - IStringIterator* it; - ASSERT_THAT(inspector->GetKeys(kScope, kAppId, it), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(it, NotNull()); - string element; - ASSERT_THAT(it->Next(element), IsTrue()); - EXPECT_THAT(element, Eq(kKey)); - EXPECT_THAT(it->Next(element), IsFalse()); - it->Release(); -} - -TEST_F(AStoreInspector, GetsNamespaces) -{ - auto store2 = WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit); - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - store2->Release(); - IStringIterator* it; - ASSERT_THAT(inspector->GetNamespaces(kScope, it), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(it, NotNull()); - string element; - ASSERT_THAT(it->Next(element), IsTrue()); - EXPECT_THAT(element, Eq(kAppId)); - EXPECT_THAT(it->Next(element), IsFalse()); - it->Release(); -} - -TEST_F(AStoreInspector, GetsStorageSizes) -{ - auto store2 = WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit); - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - store2->Release(); - IStoreInspector::INamespaceSizeIterator* it; - ASSERT_THAT(inspector->GetStorageSizes(kScope, it), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(it, NotNull()); - IStoreInspector::NamespaceSize element; - ASSERT_THAT(it->Next(element), IsTrue()); - EXPECT_THAT(element.ns, Eq(kAppId)); - EXPECT_THAT(element.size, Eq(strlen(kKey) + strlen(kValue))); - EXPECT_THAT(it->Next(element), IsFalse()); - it->Release(); -} diff --git a/PersistentStore/sqlite/l1test/StoreLimitTest.cpp b/PersistentStore/sqlite/l1test/StoreLimitTest.cpp deleted file mode 100644 index 49409e91d3..0000000000 --- a/PersistentStore/sqlite/l1test/StoreLimitTest.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include -#include - -#include "../Store2.h" -#include "../StoreLimit.h" - -using ::testing::Eq; -using ::testing::Test; -using ::WPEFramework::Exchange::IStore2; -using ::WPEFramework::Exchange::IStoreLimit; -using ::WPEFramework::Plugin::Sqlite::Store2; -using ::WPEFramework::Plugin::Sqlite::StoreLimit; - -const auto kPath = "/tmp/persistentstore/sqlite/l1test/storelimittest"; -const auto kMaxSize = 100; -const auto kMaxValue = 10; -const auto kLimit = 50; -const auto kValue = "value_1"; -const auto kKey = "key_1"; -const auto kAppId = "app_id_1"; -const auto kNoTtl = 0; -const auto kScope = IStoreLimit::ScopeType::DEVICE; -const auto kEmpty = ""; -const auto kOversize = "this is too large"; -const auto kUnknown = "unknown"; -const auto kLimit20 = 20; -const auto kLimit30 = 30; -const auto kLimit40 = 40; - -class AStoreLimit : public Test { -protected: - IStoreLimit* limit; - AStoreLimit() - : limit(WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue)) - { - } - ~AStoreLimit() override - { - limit->Release(); - } -}; - -TEST_F(AStoreLimit, DoesNotGetNamespaceStorageLimitWhenNamespaceUnknown) -{ - uint32_t value; - EXPECT_THAT(limit->GetNamespaceStorageLimit(kScope, kUnknown, value), Eq(WPEFramework::Core::ERROR_NOT_EXIST)); -} - -TEST_F(AStoreLimit, DoesNotSetNamespaceStorageLimitWhenNamespaceEmpty) -{ - EXPECT_THAT(limit->SetNamespaceStorageLimit(kScope, kEmpty, kLimit20), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); -} - -TEST_F(AStoreLimit, DoesNotSetNamespaceStorageLimitWhenNamespaceOversize) -{ - EXPECT_THAT(limit->SetNamespaceStorageLimit(kScope, kOversize, kLimit20), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); -} - -TEST_F(AStoreLimit, SetsNamespaceStorageLimit) -{ - ASSERT_THAT(limit->SetNamespaceStorageLimit(kScope, kAppId, kLimit20), Eq(WPEFramework::Core::ERROR_NONE)); - uint32_t value; - ASSERT_THAT(limit->GetNamespaceStorageLimit(kScope, kAppId, value), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(value, Eq(kLimit20)); -} - -TEST_F(AStoreLimit, SetsNamespaceStorageLimitWhenAlreadySet) -{ - ASSERT_THAT(limit->SetNamespaceStorageLimit(kScope, kAppId, kLimit30), Eq(WPEFramework::Core::ERROR_NONE)); - uint32_t value; - ASSERT_THAT(limit->GetNamespaceStorageLimit(kScope, kAppId, value), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(value, Eq(kLimit30)); - ASSERT_THAT(limit->SetNamespaceStorageLimit(kScope, kAppId, kLimit40), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(limit->GetNamespaceStorageLimit(kScope, kAppId, value), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(value, Eq(kLimit40)); -} - -TEST_F(AStoreLimit, DoesNotSetNamespaceStorageLimitWhenReachedMaxSize) -{ - auto store2 = WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit); - ASSERT_THAT(store2->DeleteNamespace(kScope, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "8InMXXU4hM", "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "XhrICnuerw", "jPKODBDk5K", "d3BarkA5xF", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "WNeBknDDI2", "GC96ZN6Fuq", "IBF2E1MLQh", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, "V92", "R1R", "rHk", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(limit->SetNamespaceStorageLimit(kScope, kAppId, kLimit), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "8InMXXU4hM"), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "XhrICnuerw"), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "WNeBknDDI2"), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(store2->DeleteNamespace(kScope, "V92"), Eq(WPEFramework::Core::ERROR_NONE)); - store2->Release(); -} - -TEST_F(AStoreLimit, EnforcesSetValueToFailWhenReachedDefaultLimit) -{ - auto store2 = WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit); - ASSERT_THAT(store2->DeleteNamespace(kScope, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, kAppId, "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, kAppId, "jPKODBDk5K", "d3BarkA5xF", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); - store2->Release(); -} - -TEST_F(AStoreLimit, EnforcesSetValueToFailWhenReachedLimit) -{ - auto store2 = WPEFramework::Core::Service::Create(kPath, kMaxSize, kMaxValue, kLimit); - ASSERT_THAT(store2->DeleteNamespace(kScope, kAppId), Eq(WPEFramework::Core::ERROR_NONE)); - EXPECT_THAT(limit->SetNamespaceStorageLimit(kScope, kAppId, kLimit20), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, kAppId, "YWKN74ODMf", "N0ed2C2h4n", kNoTtl), Eq(WPEFramework::Core::ERROR_NONE)); - ASSERT_THAT(store2->SetValue(kScope, kAppId, kKey, kValue, kNoTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); - store2->Release(); -} From 2962a9b056146a158e66ce12b96f59b1bd530fb6 Mon Sep 17 00:00:00 2001 From: Nikita Poltorapavlo Date: Mon, 1 Apr 2024 13:56:04 +0300 Subject: [PATCH 3/3] update changelog and api version --- PersistentStore/CHANGELOG.md | 5 +++++ PersistentStore/PersistentStore.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/PersistentStore/CHANGELOG.md b/PersistentStore/CHANGELOG.md index d31d919f4d..593a204ccc 100644 --- a/PersistentStore/CHANGELOG.md +++ b/PersistentStore/CHANGELOG.md @@ -16,6 +16,11 @@ All notable changes to this RDK Service will be documented in this file. * For more details, refer to [versioning](https://github.com/rdkcentral/rdkservices#versioning) section under Main README. +## [1.0.9] - 2024-04-01 +### Added +- Get token from auth service, supply ids in the cloud calls +- Return ERROR_NOT_SUPPORTED if unsupported + ## [1.0.8] - 2024-03-21 ### Added - Account scope implementation diff --git a/PersistentStore/PersistentStore.cpp b/PersistentStore/PersistentStore.cpp index 17396dcdd3..caf8a730ed 100644 --- a/PersistentStore/PersistentStore.cpp +++ b/PersistentStore/PersistentStore.cpp @@ -25,7 +25,7 @@ #define API_VERSION_NUMBER_MAJOR 1 #define API_VERSION_NUMBER_MINOR 0 -#define API_VERSION_NUMBER_PATCH 8 +#define API_VERSION_NUMBER_PATCH 9 namespace WPEFramework {