diff --git a/PersistentStore/CHANGELOG.md b/PersistentStore/CHANGELOG.md index b14253c295..c7d722d153 100644 --- a/PersistentStore/CHANGELOG.md +++ b/PersistentStore/CHANGELOG.md @@ -16,6 +16,10 @@ 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.13] - 2024-05-31 +### Fixed +- Add support for error 5 (NOT_FOUND) returned from SecureStore endpoint + ## [1.0.12] - 2024-05-29 ### Fixed - Switch for account scope feature diff --git a/PersistentStore/PersistentStore.cpp b/PersistentStore/PersistentStore.cpp index 8d39876f7c..9956a1d02b 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 12 +#define API_VERSION_NUMBER_PATCH 13 namespace WPEFramework { diff --git a/PersistentStore/grpc/Store2.h b/PersistentStore/grpc/Store2.h index 9724620e85..bf8d862e23 100644 --- a/PersistentStore/grpc/Store2.h +++ b/PersistentStore/grpc/Store2.h @@ -241,6 +241,8 @@ namespace Plugin { OnError(__FUNCTION__, status); if (status.error_code() == grpc::StatusCode::INVALID_ARGUMENT) { result = Core::ERROR_INVALID_INPUT_LENGTH; + } else if (status.error_code() == grpc::StatusCode::NOT_FOUND) { + result = Core::ERROR_UNKNOWN_KEY; } else { result = Core::ERROR_GENERAL; } diff --git a/PersistentStore/grpc/l0test/Store2Test.cpp b/PersistentStore/grpc/l0test/Store2Test.cpp index d915570af3..7e4a216807 100644 --- a/PersistentStore/grpc/l0test/Store2Test.cpp +++ b/PersistentStore/grpc/l0test/Store2Test.cpp @@ -24,6 +24,7 @@ using ::testing::IsFalse; using ::testing::IsTrue; using ::testing::Le; using ::testing::NiceMock; +using ::testing::Return; using ::testing::Test; using ::WPEFramework::Core::Time; using ::WPEFramework::Exchange::IStore2; @@ -80,6 +81,36 @@ TEST_F(AStore2, GetsValueWithTtl) EXPECT_THAT(t, Eq(kTtl)); } +TEST_F(AStore2, DoesNotGetValueWhenResponseHasNoValue) +{ + ON_CALL(service, GetValue(_, _, _)) + .WillByDefault(Return(grpc::Status(grpc::StatusCode::OK, ""))); + + string v; + uint32_t t; + EXPECT_THAT(store2->GetValue(IStore2::ScopeType::ACCOUNT, kAppId, kKey, v, t), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); +} + +TEST_F(AStore2, DoesNotGetValueWhenNOT_FOUND) +{ + ON_CALL(service, GetValue(_, _, _)) + .WillByDefault(Return(grpc::Status(grpc::StatusCode::NOT_FOUND, ""))); + + string v; + uint32_t t; + EXPECT_THAT(store2->GetValue(IStore2::ScopeType::ACCOUNT, kAppId, kKey, v, t), Eq(WPEFramework::Core::ERROR_UNKNOWN_KEY)); +} + +TEST_F(AStore2, DoesNotGetValueWhenINVALID_ARGUMENT) +{ + ON_CALL(service, GetValue(_, _, _)) + .WillByDefault(Return(grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, ""))); + + string v; + uint32_t t; + EXPECT_THAT(store2->GetValue(IStore2::ScopeType::ACCOUNT, kAppId, kKey, v, t), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); +} + TEST_F(AStore2, GetsValueWithExpireTime) { GetValueRequest req; @@ -134,6 +165,14 @@ TEST_F(AStore2, SetsValueWithTtl) EXPECT_THAT(req.value().ttl().seconds(), Eq(kTtl)); } +TEST_F(AStore2, DoesNotSetValueWhenINVALID_ARGUMENT) +{ + ON_CALL(service, UpdateValue(_, _, _)) + .WillByDefault(Return(grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, ""))); + + EXPECT_THAT(store2->SetValue(IStore2::ScopeType::ACCOUNT, kAppId, kKey, kValue, kTtl), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); +} + TEST_F(AStore2, DeletesKey) { DeleteValueRequest req; @@ -151,6 +190,14 @@ TEST_F(AStore2, DeletesKey) EXPECT_THAT(req.key().scope(), Eq(kScope)); } +TEST_F(AStore2, DoesNotDeleteKeyWhenINVALID_ARGUMENT) +{ + ON_CALL(service, DeleteValue(_, _, _)) + .WillByDefault(Return(grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, ""))); + + EXPECT_THAT(store2->DeleteKey(IStore2::ScopeType::ACCOUNT, kAppId, kKey), Eq(WPEFramework::Core::ERROR_INVALID_INPUT_LENGTH)); +} + TEST_F(AStore2, DeletesNamespace) { DeleteAllValuesRequest req; diff --git a/PersistentStore/grpc/l2test/StubTest.cpp b/PersistentStore/grpc/l2test/StubTest.cpp index e90b1aed3f..895051f72f 100644 --- a/PersistentStore/grpc/l2test/StubTest.cpp +++ b/PersistentStore/grpc/l2test/StubTest.cpp @@ -24,10 +24,12 @@ using ::testing::Le; using ::testing::Test; const auto kUri = "ss.eu.prod.developer.comcast.com:443"; +const auto kDevUri = "ss.dev.developer.comcast.com:443"; const auto kValue = "value_1"; const auto kKey = "key_1"; const auto kAppId = "app_id_1"; const auto kTtl = 2; +const auto kTtlFault = 1; const auto kScope = Scope::SCOPE_ACCOUNT; const auto kEmpty = ""; const auto kUnknown = "unknown"; @@ -44,6 +46,17 @@ class AStub : public Test { } }; +class ADevStub : public Test { +protected: + std::unique_ptr stub; + ADevStub() + : stub(SecureStorageService::NewStub(grpc::CreateChannel( + kDevUri, + grpc::SslCredentials(grpc::SslCredentialsOptions())))) + { + } +}; + TEST_F(AStub, DoesNotUpdateValueWhenAppIdEmpty) { grpc::ClientContext context; @@ -218,6 +231,23 @@ TEST_F(AStub, DoesNotGetValueWhenAppIdUnknown) EXPECT_THAT(response.has_value(), IsFalse()); } +TEST_F(ADevStub, DoesNotGetValueWhenAppIdUnknown) +{ + grpc::ClientContext context; + context.AddMetadata("authorization", std::string(kToken)); + GetValueRequest request; + auto k = new Key(); + k->set_app_id(kUnknown); + k->set_key(kKey); + k->set_scope(kScope); + request.set_allocated_key(k); + GetValueResponse response; + auto status = stub->GetValue(&context, request, &response); + ASSERT_THAT(status.ok(), IsFalse()); + EXPECT_THAT(status.error_code(), Eq(5)); + EXPECT_THAT(status.error_message(), Eq("requested key scope does not exist")); +} + TEST_F(AStub, DoesNotGetValueWhenKeyUnknown) { { @@ -252,6 +282,41 @@ TEST_F(AStub, DoesNotGetValueWhenKeyUnknown) } } +TEST_F(ADevStub, DoesNotGetValueWhenKeyUnknown) +{ + { + grpc::ClientContext context; + context.AddMetadata("authorization", std::string(kToken)); + UpdateValueRequest request; + auto v = new Value(); + v->set_value(kValue); + auto k = new Key(); + k->set_app_id(kAppId); + k->set_key(kKey); + k->set_scope(kScope); + v->set_allocated_key(k); + request.set_allocated_value(v); + UpdateValueResponse response; + auto status = stub->UpdateValue(&context, request, &response); + ASSERT_THAT(status.ok(), IsTrue()); + } + { + grpc::ClientContext context; + context.AddMetadata("authorization", std::string(kToken)); + GetValueRequest request; + auto k = new Key(); + k->set_app_id(kAppId); + k->set_key(kUnknown); + k->set_scope(kScope); + request.set_allocated_key(k); + GetValueResponse response; + auto status = stub->GetValue(&context, request, &response); + ASSERT_THAT(status.ok(), IsFalse()); + EXPECT_THAT(status.error_code(), Eq(5)); + EXPECT_THAT(status.error_message(), Eq("requested key scope does not exist")); + } +} + TEST_F(AStub, DeletesValueWhenAppIdUnknown) { grpc::ClientContext context; @@ -353,7 +418,7 @@ TEST_F(AStub, GetsValueWhenTtlDidNotExpire) now.set_seconds(time(nullptr)); now.set_nanos(0); EXPECT_THAT(response.value().expire_time().seconds(), Gt(now.seconds())); - EXPECT_THAT(response.value().expire_time().seconds(), Le(now.seconds() + kTtl)); + EXPECT_THAT(response.value().expire_time().seconds(), Le(now.seconds() + kTtl + kTtlFault)); } } @@ -378,7 +443,7 @@ TEST_F(AStub, DoesNotGetValueWhenTtlExpired) auto status = stub->UpdateValue(&context, request, &response); ASSERT_THAT(status.ok(), IsTrue()); } - sleep(kTtl); + sleep(kTtl + kTtlFault); { grpc::ClientContext context; context.AddMetadata("authorization", std::string(kToken)); @@ -394,3 +459,42 @@ TEST_F(AStub, DoesNotGetValueWhenTtlExpired) EXPECT_THAT(response.has_value(), IsFalse()); } } + +TEST_F(ADevStub, DoesNotGetValueWhenTtlExpired) +{ + { + grpc::ClientContext context; + context.AddMetadata("authorization", std::string(kToken)); + UpdateValueRequest request; + auto v = new Value(); + v->set_value(kValue); + auto t = new ::google::protobuf::Duration(); + t->set_seconds(kTtl); + v->set_allocated_ttl(t); + auto k = new Key(); + k->set_app_id(kAppId); + k->set_key(kKey); + k->set_scope(kScope); + v->set_allocated_key(k); + request.set_allocated_value(v); + UpdateValueResponse response; + auto status = stub->UpdateValue(&context, request, &response); + ASSERT_THAT(status.ok(), IsTrue()); + } + sleep(kTtl + kTtlFault); + { + grpc::ClientContext context; + context.AddMetadata("authorization", std::string(kToken)); + GetValueRequest request; + auto k = new Key(); + k->set_app_id(kAppId); + k->set_key(kKey); + k->set_scope(kScope); + request.set_allocated_key(k); + GetValueResponse response; + auto status = stub->GetValue(&context, request, &response); + ASSERT_THAT(status.ok(), IsFalse()); + EXPECT_THAT(status.error_code(), Eq(5)); + EXPECT_THAT(status.error_message(), Eq("requested key scope does not exist")); + } +}