diff --git a/services/netfirewallmanager/src/netfirewall_preference_helper.cpp b/services/netfirewallmanager/src/netfirewall_preference_helper.cpp index 6af38e6778aee2a251e367535c249f9a2d51c071..cff391d126352911d67509a42260edddbed64253 100755 --- a/services/netfirewallmanager/src/netfirewall_preference_helper.cpp +++ b/services/netfirewallmanager/src/netfirewall_preference_helper.cpp @@ -33,9 +33,6 @@ shared_ptr NetFirewallPreferenceHelper::GetInstance bool NetFirewallPreferenceHelper::GetPreference() { - if (ptr_ != nullptr) { - return true; - } int32_t errCode = -1; ptr_ = NativePreferences::PreferencesHelper::GetPreferences(filePath_, errCode); if (ptr_ == nullptr) { @@ -47,9 +44,6 @@ bool NetFirewallPreferenceHelper::GetPreference() bool NetFirewallPreferenceHelper::GetPreference(const std::string &filePath) { - if (ptr_ != nullptr) { - return true; - } filePath_ = filePath; int32_t errCode = -1; ptr_ = NativePreferences::PreferencesHelper::GetPreferences(filePath_, errCode); diff --git a/services/netfirewallmanager/src/netfirewall_service.cpp b/services/netfirewallmanager/src/netfirewall_service.cpp index a92e91e10b1d5601172ba4eae19d01dd1ae78916..af338b08bac38ba972a2ea00628101f5a41fef34 100755 --- a/services/netfirewallmanager/src/netfirewall_service.cpp +++ b/services/netfirewallmanager/src/netfirewall_service.cpp @@ -91,10 +91,14 @@ int32_t NetFirewallService::GetCurrentAccountId() */ int32_t NetFirewallService::SetNetFirewallPolicy(const int32_t userId, const sptr &policy) { - NETMGR_EXT_LOG_I("SetNetFirewallPolicy isOpen= %{public}d, inAction=%{public}d", policy->isOpen, policy->inAction); - + NETMGR_EXT_LOG_I("SetNetFirewallPolicy userId=%{public}d isOpen= %{public}d, inAction=%{public}d", userId, + policy->isOpen, policy->inAction); + int32_t ret = CheckUserExist(userId); + if (ret != FIREWALL_SUCCESS) { + return ret; + } std::shared_ptr policyManager = NetFirewallPolicyManager::GetInstance(); - int32_t ret = policyManager->SetNetFirewallPolicy(userId, policy); + ret = policyManager->SetNetFirewallPolicy(userId, policy); if (ret != FIREWALL_SUCCESS) { return ret; } @@ -124,6 +128,10 @@ int32_t NetFirewallService::SetNetFirewallPolicy(const int32_t userId, const spt int32_t NetFirewallService::GetNetFirewallPolicy(const int32_t userId, sptr &policy) { NETMGR_EXT_LOG_I("GetNetFirewallPolicy"); + int32_t ret = CheckUserExist(userId); + if (ret != FIREWALL_SUCCESS) { + return ret; + } NetFirewallPolicyManager::GetInstance()->GetNetFirewallPolicy(userId, policy); return FIREWALL_SUCCESS; } diff --git a/test/netfirewallmanager/unittest/netfirewallmanager_test/netfirewall_client_test.cpp b/test/netfirewallmanager/unittest/netfirewallmanager_test/netfirewall_client_test.cpp index 0051741169c9e3c6d6d4299f5a54eec20a13f332..f230045c2193d80c49a21fb28a7bcd2e3263b27a 100755 --- a/test/netfirewallmanager/unittest/netfirewallmanager_test/netfirewall_client_test.cpp +++ b/test/netfirewallmanager/unittest/netfirewallmanager_test/netfirewall_client_test.cpp @@ -51,6 +51,7 @@ constexpr int32_t MAX_TEST_CNT = 1; constexpr int32_t MAX_USER_RULE = 1; constexpr uint32_t APPID_TEST01 = 2034; constexpr int32_t USER_ID1 = 100; +constexpr int32_t USER_ID2 = 101; const uint16_t LOCAL_START_PORT = 10020; const uint16_t LOCAL_END_PORT = 1003; const uint16_t REMOTE_START_PORT = 1002; @@ -265,6 +266,9 @@ HWTEST_F(NetFirewallClientTest, AddNetFirewallRule001, TestSize.Level1) sptr rule = GetNetFirewallRuleSptr(); g_startTimeTest = GetCurrentMilliseconds(); for (int32_t i = 0; i < MAX_USER_RULE; i++) { + if (i >= FIREWALL_USER_MAX_RULE) { + rule->userId = USER_ID2; + } uint64_t stime = GetCurrentMilliseconds(); ret = netfirewallClient_.AddNetFirewallRule(rule, ruleId); std::cout << "AddNetFirewallRule IP " << i + 1 << " ruleId " << ruleId << ", use time : " <<