Skip to content

Commit 6f54b92

Browse files
author
mtirum011
committed
RDKEMW-12168 Port the getAccountID Script functionality to RFC Module
1 parent 8fcb108 commit 6f54b92

5 files changed

Lines changed: 83 additions & 18 deletions

File tree

rfcMgr/rfc_common.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,14 @@ int executeCommandAndGetOutput(SYSCMD eSysCmd, const char *pArgs, std::string&
256256
}
257257

258258
bool CheckSpecialCharacters(const std::string& str) {
259+
260+
if (str.length() >= ACCOUNT_ID_MAX_LEN) {
261+
return true; // invalid: length limit exceeded
262+
}
263+
259264
for (char c : str)
260265
{
261-
if(!std::isalnum(c))
266+
if(!std::isalnum(c) && c != '_' && c != '-')
262267
{
263268
return true; // Return true if a non-alphanumeric character is found
264269
}

rfcMgr/rfc_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#define SECURE_RFC_PATH "/opt/secure/RFC"
6363

6464
#define DEFAULT_DL_ALLOC 1024
65+
#define ACCOUNT_ID_MAX_LEN 32
6566

6667
typedef enum {
6768
eRdkSsaCli,

rfcMgr/rfc_xconf_handler.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -823,21 +823,31 @@ void RuntimeFeatureControlProcessor::GetAccountID()
823823
}
824824
else
825825
{
826-
i = strnlen(tempbuf, szBufSize);
827-
RDK_LOG(RDK_LOG_INFO, LOG_RFCMGR, "GetAccountID: AccountID = %s\n", tempbuf);
828-
_accountId = tempbuf;
829-
#ifdef RDKB_SUPPORT
830-
if (access("/tmp/RFC/.timeValue", F_OK) != 0)
826+
if (CheckSpecialCharacters(tempbuf))
831827
{
832-
// Time file doesn't exist, set AccountID to Unknown
828+
RDK_LOG(RDK_LOG_ERROR, LOG_RFCMGR, "[%s][%d] Invalid characters in newly received accountId: %s\n", __FUNCTION__, __LINE__, tempbuf);
833829
_accountId = "Unknown";
834-
RDK_LOG(RDK_LOG_INFO, LOG_RFCMGR, "GetAccountID: /tmp/RFC/.timeValue file not found, setting AccountID to Unknown\n");
835830
}
836-
saveAccountIdToFile(_accountId, RFC_ACCOUNT_ID_KEY_STR, "string");
837-
#endif
838-
if((_accountId.empty()) || (_last_firmware.compare( _firmware_version) != 0))
831+
else
839832
{
840-
_accountId="Unknown";
833+
i = strnlen(tempbuf, szBufSize);
834+
RDK_LOG(RDK_LOG_INFO, LOG_RFCMGR, "GetAccountID: AccountID = %s\n", tempbuf);
835+
_accountId = tempbuf;
836+
#ifdef RDKB_SUPPORT
837+
if (access("/tmp/RFC/.timeValue", F_OK) != 0)
838+
{
839+
// Time file doesn't exist, set AccountID to Unknown
840+
_accountId = "Unknown";
841+
RDK_LOG(RDK_LOG_INFO, LOG_RFCMGR, "GetAccountID: /tmp/RFC/.timeValue file not found, setting AccountID to Unknown\n");
842+
}
843+
844+
saveAccountIdToFile(_accountId, RFC_ACCOUNT_ID_KEY_STR, "string");
845+
#endif
846+
847+
if((_accountId.empty()) || (_last_firmware.compare( _firmware_version) != 0))
848+
{
849+
_accountId = "Unknown";
850+
}
841851
}
842852
}
843853

run_l2.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_xc
5252

5353
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_valid_accountid.json test/functional-tests/tests/test_rfc_valid_accountid.py
5454

55-
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_trigger_reboot_unknown_accountid.json test/functional-tests/tests/test_rfc_trigger_reboot.py
56-
57-
cat /opt/logs/rfcscript.txt.1
58-
59-
cat /opt/logs/rfcscript.txt.0
60-
6155
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_feature_enable.json test/functional-tests/tests/test_rfc_feature_enable.py
6256

6357
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_configsethash_time.json test/functional-tests/tests/test_rfc_xconf_configsethash_time.py
@@ -66,6 +60,11 @@ echo "ENABLE_MAINTENANCE=true" >> /etc/device.properties
6660

6761
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_xconf_reboot.json test/functional-tests/tests/test_rfc_xconf_reboot.py
6862

63+
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_invalid_accountid.json test/functional-tests/tests/test_rfc_invalid_accoountid.py
64+
cat /opt/logs/rfcscript.txt.1
65+
66+
cat /opt/logs/rfcscript.txt.0
67+
6968
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_override_rfc_prop.json test/functional-tests/tests/test_rfc_override_rfc_prop.py
7069

7170
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_rfc_webpa.json test/functional-tests/tests/test_rfc_webpa.py
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
####################################################################################
2+
# If not stated otherwise in this file or this component's Licenses file the
3+
# following copyright and licenses apply:
4+
#
5+
# Copyright 2024 RDK Management
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
####################################################################################
19+
20+
import os
21+
from rfc_test_helper import *
22+
23+
24+
def test_set_invalid_accid_value():
25+
command_to_check = "tr181 -d -s -t string -v 306045!@#06186635988 Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AccountInfo.AccountID"
26+
result = run_shell_command(command_to_check)
27+
assert "Set operation success" in result, '"Set operation success" not found in the output'
28+
29+
def test_xconf_request_response():
30+
"""
31+
Test the communication between RFC Manager and XCONF.
32+
33+
This function checks the creation of the TR181 INI file,
34+
verifies the firmware version update, and checks the key-value pair in the TR181 INI file.
35+
"""
36+
if os.path.exists(TR181_INI_FILE):
37+
os.remove(TR181_INI_FILE)
38+
39+
if os.path.exists(RFC_OLD_FW_FILE):
40+
rename_file(RFC_OLD_FW_FILE, RFC_OLD_FW_FILE + "_bak")
41+
42+
try:
43+
rfc_run_binary()
44+
INVALID_ACCID_MSG_STATUS = f"Invalid characters in newly received accountId"
45+
46+
assert grep_log_file(RFC_LOG_FILE, INVALID_ACCID_MSG_STATUS), f"Expected '{INVALID_ACCID_MSG_STATUS}' in log file."
47+
except Exception as e:
48+
print(f"Exception during Validate the XConf request and response: {e}")
49+
assert False, f"Exception during Validate the XConf request and response: {e}"
50+

0 commit comments

Comments
 (0)