Skip to content

Commit a3d2502

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

6 files changed

Lines changed: 136 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: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ 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
55+
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_factory_reset.json test/functional-tests/tests/test_rfc_factory_reset.py
5856

59-
cat /opt/logs/rfcscript.txt.0
57+
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
6058

6159
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_feature_enable.json test/functional-tests/tests/test_rfc_feature_enable.py
6260

@@ -65,8 +63,7 @@ pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_co
6563
echo "ENABLE_MAINTENANCE=true" >> /etc/device.properties
6664

6765
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_xconf_reboot.json test/functional-tests/tests/test_rfc_xconf_reboot.py
68-
66+
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_invalid_accountid.json test/functional-tests/tests/test_rfc_invalid_accountid.py
6967
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
7068

7169
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_rfc_webpa.json test/functional-tests/tests/test_rfc_webpa.py
72-
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
Feature: Invalid Account ID Validation
21+
As a system administrator
22+
I want to ensure that invalid account IDs are properly rejected
23+
So that the system maintains data integrity and security
24+
25+
Background:
26+
Given the RFC system is initialized
27+
And the telemetry system is running
28+
29+
Scenario: Set invalid account ID with special characters
30+
Given I have an account ID with invalid characters "306045!@#06186635988"
31+
When I set the account ID using TR181 parameter "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AccountInfo.AccountID"
32+
Then the set operation should succeed
33+
And the invalid characters should be logged
34+
35+
Scenario: XCONF request validates invalid account ID
36+
Given the TR181 INI file does not exist
37+
And the RFC old firmware file is backed up
38+
When the RFC binary is executed
39+
Then the TR181 INI file should be created
40+
And the RFC log file should contain "Invalid characters in newly received accountId"
41+
42+
Scenario Outline: Validate various invalid account ID formats
43+
Given I have an account ID "<account_id>"
44+
When I attempt to set it via TR181
45+
Then the system should log "Invalid characters in newly received accountId"
46+
And the operation should be handled appropriately
47+
48+
Examples:
49+
| account_id |
50+
| 306045!@#06186635988 |
51+
| test@#$%account |
52+
| 123<>456 |
53+
| acc&*()id |
54+
| id;DROP TABLE; |
55+
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_accountid_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 = "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)