Skip to content

Commit

Permalink
Merge pull request #5364 from npoltorapavlo/DELIA-65244_main
Browse files Browse the repository at this point in the history
Delia 65244 main
  • Loading branch information
anand-ky authored May 31, 2024
2 parents 76f4738 + 85cb5d6 commit 5cb3264
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 3 deletions.
4 changes: 4 additions & 0 deletions PersistentStore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion PersistentStore/PersistentStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 2 additions & 0 deletions PersistentStore/grpc/Store2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
47 changes: 47 additions & 0 deletions PersistentStore/grpc/l0test/Store2Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
108 changes: 106 additions & 2 deletions PersistentStore/grpc/l2test/StubTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -44,6 +46,17 @@ class AStub : public Test {
}
};

class ADevStub : public Test {
protected:
std::unique_ptr<SecureStorageService::Stub> stub;
ADevStub()
: stub(SecureStorageService::NewStub(grpc::CreateChannel(
kDevUri,
grpc::SslCredentials(grpc::SslCredentialsOptions()))))
{
}
};

TEST_F(AStub, DoesNotUpdateValueWhenAppIdEmpty)
{
grpc::ClientContext context;
Expand Down Expand Up @@ -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)
{
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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));
Expand All @@ -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"));
}
}

0 comments on commit 5cb3264

Please sign in to comment.