Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 121 additions & 4 deletions Tests/L2Tests/tests/UserSettings_L2Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ TEST_F(UserSettingTest, getMigrationStatecase)
string preferredCaptionsLanguages = "en,es";
string preferredService = "CC3";
string viewingRestrictions = "ALWAYS";
string contentPin = "1234";
string contentPin = "123456";
double rate = 1;

Core::JSON::String result_string;
Expand Down Expand Up @@ -2060,7 +2060,7 @@ TEST_F(UserSettingTest, onContentPinChangedEvent)
uint32_t status = Core::ERROR_GENERAL;
uint32_t signalled = UserSettings_StateInvalid;

string contentPin = "1234";
string contentPin = "123456";

Core::JSON::String result_string;
Core::JSON::Boolean result_bool;
Expand Down Expand Up @@ -2120,6 +2120,123 @@ TEST_F(UserSettingTest, onContentPinChangedEvent)

}

/* Verify that SetContentPin rejects a 4-digit PIN (old format) and returns ERROR_INVALID_PARAMETER.
The regex was updated from ^\d{4}$ to ^\d{6}$, so 4-digit PINs must be rejected. */
TEST_F(UserSettingTest, SetContentPin_InvalidFourDigitPinReturnsError)
{
uint32_t status = Core::ERROR_GENERAL;
Core::Sink<NotificationHandler> notification;

if (CreateUserSettingInterfaceObjectUsingComRPCConnection() != Core::ERROR_NONE)
{
TEST_LOG("Invalid Client_UserSettings");
}
else
{
ASSERT_TRUE(m_controller_usersettings != nullptr);
if (m_controller_usersettings)
{
ASSERT_TRUE(m_usersettingsplugin != nullptr);
if (m_usersettingsplugin)
{
m_usersettingsplugin->Register(&notification);

TEST_LOG("Verifying that a 4-digit PIN is rejected after regex update to 6 digits");
status = m_usersettingsplugin->SetContentPin("1234");
EXPECT_EQ(status, Core::ERROR_INVALID_PARAMETER);
if (status != Core::ERROR_INVALID_PARAMETER)
{
std::string errorMsg = "COM-RPC returned error " + std::to_string(status) + " (" + std::string(Core::ErrorToString(status)) + ")";
TEST_LOG("Err: %s", errorMsg.c_str());
}

/* Verify no notification is triggered for an invalid PIN */
uint32_t signalled = notification.WaitForRequestStatus(JSON_TIMEOUT, UserSettings_onContentPinChanged);
EXPECT_FALSE(signalled & UserSettings_onContentPinChanged);

m_usersettingsplugin->Unregister(&notification);
m_usersettingsplugin->Release();
}
else
{
TEST_LOG("m_usersettingsplugin is NULL");
}
m_controller_usersettings->Release();
}
else
{
TEST_LOG("m_controller_usersettings is NULL");
}
}
}

/* Verify that SetContentPin rejects non-numeric and invalid-length PINs. */
TEST_F(UserSettingTest, SetContentPin_InvalidFormatPinReturnsError)
{
uint32_t status = Core::ERROR_GENERAL;
Core::Sink<NotificationHandler> notification;

if (CreateUserSettingInterfaceObjectUsingComRPCConnection() != Core::ERROR_NONE)
{
TEST_LOG("Invalid Client_UserSettings");
}
else
{
ASSERT_TRUE(m_controller_usersettings != nullptr);
if (m_controller_usersettings)
{
ASSERT_TRUE(m_usersettingsplugin != nullptr);
if (m_usersettingsplugin)
{
m_usersettingsplugin->Register(&notification);

TEST_LOG("Verifying that a non-numeric PIN is rejected");
status = m_usersettingsplugin->SetContentPin("abcdef");
EXPECT_EQ(status, Core::ERROR_INVALID_PARAMETER);
if (status != Core::ERROR_INVALID_PARAMETER)
{
std::string errorMsg = "COM-RPC returned error " + std::to_string(status) + " (" + std::string(Core::ErrorToString(status)) + ")";
TEST_LOG("Err: %s", errorMsg.c_str());
}

TEST_LOG("Verifying that a 5-digit PIN is rejected");
status = m_usersettingsplugin->SetContentPin("12345");
EXPECT_EQ(status, Core::ERROR_INVALID_PARAMETER);
if (status != Core::ERROR_INVALID_PARAMETER)
{
std::string errorMsg = "COM-RPC returned error " + std::to_string(status) + " (" + std::string(Core::ErrorToString(status)) + ")";
TEST_LOG("Err: %s", errorMsg.c_str());
}

TEST_LOG("Verifying that a 7-digit PIN is rejected");
status = m_usersettingsplugin->SetContentPin("1234567");
EXPECT_EQ(status, Core::ERROR_INVALID_PARAMETER);
if (status != Core::ERROR_INVALID_PARAMETER)
{
std::string errorMsg = "COM-RPC returned error " + std::to_string(status) + " (" + std::string(Core::ErrorToString(status)) + ")";
TEST_LOG("Err: %s", errorMsg.c_str());
}

/* Verify no notification is triggered for any invalid PIN */
uint32_t signalled = notification.WaitForRequestStatus(JSON_TIMEOUT, UserSettings_onContentPinChanged);
EXPECT_FALSE(signalled & UserSettings_onContentPinChanged);

m_usersettingsplugin->Unregister(&notification);
m_usersettingsplugin->Release();
}
else
{
TEST_LOG("m_usersettingsplugin is NULL");
}
m_controller_usersettings->Release();
}
else
{
TEST_LOG("m_controller_usersettings is NULL");
}
}
}

/* Activating UserSettings and Persistent store plugins and UserSettings namespace has no entries in db.
So that we can verify whether UserSettings plugin is receiving default values from PersistentStore or not*/
TEST_F(UserSettingTest, VerifyDefaultValues)
Expand Down Expand Up @@ -3087,7 +3204,7 @@ TEST_F(UserSettingTest,SetAndGetMethodsUsingComRpcConnectionSuccessCase)
}

TEST_LOG("Setting and Getting ContentPin Values");
status = m_usersettingsplugin->SetContentPin("1234");
status = m_usersettingsplugin->SetContentPin("123456");
EXPECT_EQ(status,Core::ERROR_NONE);
if (status != Core::ERROR_NONE)
{
Expand All @@ -3098,7 +3215,7 @@ TEST_F(UserSettingTest,SetAndGetMethodsUsingComRpcConnectionSuccessCase)
EXPECT_TRUE(signalled & UserSettings_onContentPinChanged);

status = m_usersettingsplugin->GetContentPin(getStringValue);
EXPECT_EQ(getStringValue, "1234");
EXPECT_EQ(getStringValue, "123456");
EXPECT_EQ(status,Core::ERROR_NONE);
if (status != Core::ERROR_NONE)
{
Expand Down