diff --git a/frameworks/inner_api/security_component/include/i_sec_comp_service.h b/frameworks/inner_api/security_component/include/i_sec_comp_service.h index 2a28352e722ec174703a5485d027e18b1d7f150a..3047943d76590eb2cf82c9d3a79e7b3016f930c4 100644 --- a/frameworks/inner_api/security_component/include/i_sec_comp_service.h +++ b/frameworks/inner_api/security_component/include/i_sec_comp_service.h @@ -32,7 +32,7 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.security.ISecCompService"); virtual int32_t RegisterSecurityComponent(SecCompType type, - const std::string& componentInfo, int32_t& scId) = 0; + const std::string& componentInfo, int32_t& scId, std::string& message) = 0; virtual int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) = 0; virtual int32_t UnregisterSecurityComponent(int32_t scId) = 0; virtual int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, diff --git a/frameworks/inner_api/security_component/include/sec_comp_client.h b/frameworks/inner_api/security_component/include/sec_comp_client.h index e4c91c4ac5d47255eeb8c4525a1970bbb0e88265..892468173ac57f514c10a0629b801761caab7487 100644 --- a/frameworks/inner_api/security_component/include/sec_comp_client.h +++ b/frameworks/inner_api/security_component/include/sec_comp_client.h @@ -30,7 +30,8 @@ class SecCompClient final { public: static SecCompClient& GetInstance(); - int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId); + int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, + int32_t& scId, std::string& message); int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo); int32_t UnregisterSecurityComponent(int32_t scId); int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, diff --git a/frameworks/inner_api/security_component/include/sec_comp_proxy.h b/frameworks/inner_api/security_component/include/sec_comp_proxy.h index cc1b213706890031cfe75383ea02173a1c00629b..5951c367091912afc614bc7aa6f76600b407f856 100644 --- a/frameworks/inner_api/security_component/include/sec_comp_proxy.h +++ b/frameworks/inner_api/security_component/include/sec_comp_proxy.h @@ -26,7 +26,8 @@ class SecCompProxy : public IRemoteProxy { public: explicit SecCompProxy(const sptr& impl); ~SecCompProxy() override; - int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId) override; + int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, + int32_t& scId, std::string& message) override; int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) override; int32_t UnregisterSecurityComponent(int32_t scId) override; int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, sptr callerToken, @@ -37,6 +38,8 @@ public: private: int32_t SendReportClickEventRequest(MessageParcel& data, std::string& message); + int32_t ReadRegisterSecurityComponentResult(int32_t& scId, std::string& message, + MessageParcel& deserializedReply); static inline BrokerDelegator delegator_; std::mutex useIPCMutex_; }; diff --git a/frameworks/inner_api/security_component/src/sec_comp_client.cpp b/frameworks/inner_api/security_component/src/sec_comp_client.cpp index b7815d69d653ee05e876ad12be77e61be8e4f140..5f07a2e9c5b8742fe54027556fcf3ffbe9138a7a 100644 --- a/frameworks/inner_api/security_component/src/sec_comp_client.cpp +++ b/frameworks/inner_api/security_component/src/sec_comp_client.cpp @@ -56,7 +56,7 @@ SecCompClient::~SecCompClient() } int32_t SecCompClient::RegisterSecurityComponent(SecCompType type, - const std::string& componentInfo, int32_t& scId) + const std::string& componentInfo, int32_t& scId, std::string& message) { auto proxy = GetProxy(true); if (proxy == nullptr) { @@ -64,7 +64,7 @@ int32_t SecCompClient::RegisterSecurityComponent(SecCompType type, return SC_SERVICE_ERROR_VALUE_INVALID; } - return proxy->RegisterSecurityComponent(type, componentInfo, scId); + return proxy->RegisterSecurityComponent(type, componentInfo, scId, message); } int32_t SecCompClient::UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) diff --git a/frameworks/inner_api/security_component/src/sec_comp_kit.cpp b/frameworks/inner_api/security_component/src/sec_comp_kit.cpp index 4bc666292e2d6737f97c7086786d3f83c52206e2..6c1736413f14b21e0eb2d262e5a09404a095268a 100644 --- a/frameworks/inner_api/security_component/src/sec_comp_kit.cpp +++ b/frameworks/inner_api/security_component/src/sec_comp_kit.cpp @@ -31,7 +31,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ } // namespace int32_t SecCompKit::RegisterSecurityComponent(SecCompType type, - std::string& componentInfo, int32_t& scId) + std::string& componentInfo, int32_t& scId, std::string& message) { if (!SecCompCallerAuthorization::GetInstance().IsKitCaller( reinterpret_cast(__builtin_return_address(0)))) { @@ -51,7 +51,7 @@ int32_t SecCompKit::RegisterSecurityComponent(SecCompType type, return SC_ENHANCE_ERROR_VALUE_INVALID; } - int32_t res = SecCompClient::GetInstance().RegisterSecurityComponent(type, componentInfo, scId); + int32_t res = SecCompClient::GetInstance().RegisterSecurityComponent(type, componentInfo, scId, message); if (res != SC_OK) { SC_LOG_ERROR(LABEL, "register security component fail, error: %{public}d", res); return res; diff --git a/frameworks/inner_api/security_component/src/sec_comp_proxy.cpp b/frameworks/inner_api/security_component/src/sec_comp_proxy.cpp index 7cd7798fd80ca77e66ee4a6d3886614d41a6e008..39b8f7390fc0e32f942f6b94612f19accb3b3903 100644 --- a/frameworks/inner_api/security_component/src/sec_comp_proxy.cpp +++ b/frameworks/inner_api/security_component/src/sec_comp_proxy.cpp @@ -33,8 +33,29 @@ SecCompProxy::SecCompProxy(const sptr& impl) : IRemoteProxy lock(useIPCMutex_); MessageParcel rawData; @@ -81,17 +102,7 @@ int32_t SecCompProxy::RegisterSecurityComponent(SecCompType type, return requestResult; } - int32_t res; - if (!deserializedReply.ReadInt32(res)) { - SC_LOG_ERROR(LABEL, "Register read res failed."); - return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; - } - - if (!deserializedReply.ReadInt32(scId)) { - SC_LOG_ERROR(LABEL, "Register read scId failed."); - return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; - } - return res; + return ReadRegisterSecurityComponentResult(scId, message, deserializedReply); } int32_t SecCompProxy::UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) diff --git a/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp index 335bb9845ef5f030b4e13cab179f744f335fe963..ceede45c74ae1c78df29844a231232e9fd05c95f 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/location_button_test.cpp @@ -54,8 +54,9 @@ HWTEST_F(LocationButtonTest, FromJson001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton comp; - - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); } /** @@ -68,7 +69,8 @@ HWTEST_F(LocationButtonTest, FromJson002, TestSize.Level1) { nlohmann::json jsonComponent; LocationButton comp; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); } /** @@ -82,13 +84,14 @@ HWTEST_F(LocationButtonTest, FromJson003, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton comp; - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); jsonComponent[JsonTagConstants::JSON_SC_TYPE] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); jsonComponent[JsonTagConstants::JSON_SC_TYPE] = 0; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); } /** @@ -104,26 +107,27 @@ HWTEST_F(LocationButtonTest, FromJson004, TestSize.Level1) jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT; nlohmann::json wrongJson = nlohmann::json::parse("{", nullptr, false); jsonComponent[JsonTagConstants::JSON_RECT] = wrongJson; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); auto& rectJson = jsonComponent[JsonTagConstants::JSON_RECT]; rectJson[JsonTagConstants::JSON_RECT_X] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); rectJson[JsonTagConstants::JSON_RECT_X] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_Y] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); rectJson[JsonTagConstants::JSON_RECT_Y] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_WIDTH] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); rectJson[JsonTagConstants::JSON_RECT_WIDTH] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_HEIGHT] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); } /** @@ -139,26 +143,27 @@ HWTEST_F(LocationButtonTest, FromJson005, TestSize.Level1) jsonComponent[JsonTagConstants::JSON_SC_TYPE] = LOCATION_COMPONENT; nlohmann::json wrongJson = nlohmann::json::parse("{", nullptr, false); jsonComponent[JsonTagConstants::JSON_WINDOW_RECT] = wrongJson; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); auto& rectJson = jsonComponent[JsonTagConstants::JSON_WINDOW_RECT]; rectJson[JsonTagConstants::JSON_RECT_X] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); rectJson[JsonTagConstants::JSON_RECT_X] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_Y] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); rectJson[JsonTagConstants::JSON_RECT_Y] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_WIDTH] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); rectJson[JsonTagConstants::JSON_RECT_WIDTH] = TestCommon::TEST_COORDINATE; rectJson[JsonTagConstants::JSON_RECT_HEIGHT] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); } /** @@ -172,19 +177,20 @@ HWTEST_F(LocationButtonTest, FromJson006, TestSize.Level1) nlohmann::json jsonComponent; LocationButton comp; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); sizeJson[JsonTagConstants::JSON_FONT_SIZE_TAG] = TestCommon::TEST_SIZE; sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); sizeJson[JsonTagConstants::JSON_ICON_SIZE_TAG] = TestCommon::TEST_SIZE; sizeJson[JsonTagConstants::JSON_TEXT_ICON_PADDING_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); } /** @@ -198,16 +204,17 @@ HWTEST_F(LocationButtonTest, FromJson007, TestSize.Level1) nlohmann::json jsonComponent; LocationButton comp; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); paddingJson[JsonTagConstants::JSON_PADDING_TOP_TAG] = TestCommon::TEST_DIMENSION; paddingJson[JsonTagConstants::JSON_PADDING_RIGHT_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); } /** @@ -221,16 +228,17 @@ HWTEST_F(LocationButtonTest, FromJson008, TestSize.Level1) nlohmann::json jsonComponent; LocationButton comp; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); auto& sizeJson = jsonComponent[JsonTagConstants::JSON_SIZE_TAG]; auto& paddingJson = sizeJson[JsonTagConstants::JSON_PADDING_SIZE_TAG]; paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); paddingJson[JsonTagConstants::JSON_PADDING_BOTTOM_TAG] = TestCommon::TEST_DIMENSION; paddingJson[JsonTagConstants::JSON_PADDING_LEFT_TAG] = WRONG_TYPE; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); } /** @@ -244,18 +252,19 @@ HWTEST_F(LocationButtonTest, FromJson009, TestSize.Level1) nlohmann::json jsonComponent; LocationButton comp; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp.FromJson(jsonComponent, message)); jsonComponent[JsonTagConstants::JSON_BORDER_TAG] = nlohmann::json { { JsonTagConstants::JSON_BORDER_WIDTH_TAG, WRONG_TYPE }, }; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); TestCommon::BuildLocationComponentInfo(jsonComponent); jsonComponent[JsonTagConstants::JSON_PARENT_TAG] = nlohmann::json { { JsonTagConstants::JSON_PARENT_EFFECT_TAG, WRONG_TYPE }, }; - ASSERT_FALSE(comp.FromJson(jsonComponent)); + ASSERT_FALSE(comp.FromJson(jsonComponent, message)); } /** @@ -269,19 +278,20 @@ HWTEST_F(LocationButtonTest, FromJson010, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; - ASSERT_TRUE(button.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(button.FromJson(jsonComponent, message)); auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; styleJson[JsonTagConstants::JSON_TEXT_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; styleJson[JsonTagConstants::JSON_ICON_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); } /** @@ -295,19 +305,20 @@ HWTEST_F(LocationButtonTest, FromJson011, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; - ASSERT_TRUE(button.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(button.FromJson(jsonComponent, message)); auto& colorJson = jsonComponent[JsonTagConstants::JSON_COLORS_TAG]; colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); colorJson[JsonTagConstants::JSON_FONT_COLOR_TAG] = TestCommon::TEST_COLOR_RED; colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); colorJson[JsonTagConstants::JSON_ICON_COLOR_TAG] = TestCommon::TEST_COLOR_BLUE; colorJson[JsonTagConstants::JSON_BG_COLOR_TAG] = WRONG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); } /** @@ -321,32 +332,33 @@ HWTEST_F(LocationButtonTest, FromJson012, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; + std::string message; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message)); auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; styleJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; styleJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::MAX_LABEL_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = LocationDesc::SELECT_LOCATION; styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::MAX_ICON_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); styleJson[JsonTagConstants::JSON_ICON_TAG] = LocationIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); } /** @@ -360,8 +372,9 @@ HWTEST_F(LocationButtonTest, ToJsonStr001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); LocationButton button; + std::string message; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message)); ASSERT_EQ(jsonComponent.dump(), button.ToJsonStr()); } @@ -393,9 +406,10 @@ HWTEST_F(LocationButtonTest, CompareLocationButton001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); + std::string message; - ASSERT_TRUE(button1.FromJson(jsonComponent)); - ASSERT_TRUE(button2.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message)); + ASSERT_TRUE(button2.FromJson(jsonComponent, message)); ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true)); button1.text_ = UNKNOWN_TEXT; @@ -424,7 +438,8 @@ HWTEST_F(LocationButtonTest, CompareLocationButton002, TestSize.Level1) nlohmann::json jsonComponent; LocationButton comp1; TestCommon::BuildLocationComponentInfo(jsonComponent); - ASSERT_TRUE(comp1.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp1.FromJson(jsonComponent, message)); LocationButton comp2 = comp1; comp1.type_ = SAVE_COMPONENT; @@ -490,7 +505,8 @@ HWTEST_F(LocationButtonTest, CompareLocationButton003, TestSize.Level1) SaveButton button2; nlohmann::json jsonComponent; TestCommon::BuildLocationComponentInfo(jsonComponent); + std::string message; - ASSERT_TRUE(button1.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message)); ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, false)); } diff --git a/frameworks/inner_api/security_component/test/unittest/src/paste_button_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/paste_button_test.cpp index d79349ddb51e352852008fe32485db266f0a9f43..1d1f194167c60b7f13a8559aa4e370de8061fed9 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/paste_button_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/paste_button_test.cpp @@ -53,32 +53,33 @@ HWTEST_F(PasteButtonTest, IsParamValid001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildPasteComponentInfo(jsonComponent); PasteButton button; + std::string message; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message)); auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; styleJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::PASTE; styleJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::MAX_LABEL_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::PASTE; styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::MAX_ICON_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::LINE_ICON; styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); } /** @@ -94,9 +95,10 @@ HWTEST_F(PasteButtonTest, ComparePasteButton001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildPasteComponentInfo(jsonComponent); + std::string message; - ASSERT_TRUE(button1.FromJson(jsonComponent)); - ASSERT_TRUE(button2.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message)); + ASSERT_TRUE(button2.FromJson(jsonComponent, message)); ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true)); button1.text_ = UNKNOWN_TEXT; @@ -125,7 +127,8 @@ HWTEST_F(PasteButtonTest, ComparePasteButton002, TestSize.Level1) nlohmann::json jsonComponent; PasteButton comp1; TestCommon::BuildPasteComponentInfo(jsonComponent); - ASSERT_TRUE(comp1.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp1.FromJson(jsonComponent, message)); PasteButton comp2 = comp1; comp1.type_ = SAVE_COMPONENT; @@ -159,7 +162,8 @@ HWTEST_F(PasteButtonTest, ComparePasteButton003, TestSize.Level1) SaveButton button2; nlohmann::json jsonComponent; TestCommon::BuildPasteComponentInfo(jsonComponent); + std::string message; - ASSERT_TRUE(button1.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message)); ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, true)); } diff --git a/frameworks/inner_api/security_component/test/unittest/src/save_button_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/save_button_test.cpp index ffe975ece56f5c4c3b171750a78d8a912d0eaede..0afb25d0288e247319e7aa35c87eda776ce4796a 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/save_button_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/save_button_test.cpp @@ -53,36 +53,37 @@ HWTEST_F(SaveButtonTest, IsParamValid001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildSaveComponentInfo(jsonComponent); SaveButton button; + std::string message; - ASSERT_TRUE(button.FromJson(jsonComponent)); + ASSERT_TRUE(button.FromJson(jsonComponent, message)); auto& stylesJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG]; stylesJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::DOWNLOAD; stylesJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::LINE_ICON; stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::MAX_LABEL_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::DOWNLOAD; stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::MAX_ICON_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::LINE_ICON; stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::PICTURE_ICON; stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE; - ASSERT_FALSE(button.FromJson(jsonComponent)); + ASSERT_FALSE(button.FromJson(jsonComponent, message)); } /** @@ -98,9 +99,10 @@ HWTEST_F(SaveButtonTest, CompareSaveButton001, TestSize.Level1) nlohmann::json jsonComponent; TestCommon::BuildSaveComponentInfo(jsonComponent); + std::string message; - ASSERT_TRUE(button1.FromJson(jsonComponent)); - ASSERT_TRUE(button2.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message)); + ASSERT_TRUE(button2.FromJson(jsonComponent, message)); ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true)); button1.text_ = UNKNOWN_TEXT; @@ -129,7 +131,8 @@ HWTEST_F(SaveButtonTest, CompareSaveButton002, TestSize.Level1) nlohmann::json jsonComponent; SaveButton comp1; TestCommon::BuildSaveComponentInfo(jsonComponent); - ASSERT_TRUE(comp1.FromJson(jsonComponent)); + std::string message; + ASSERT_TRUE(comp1.FromJson(jsonComponent, message)); SaveButton comp2 = comp1; comp1.type_ = PASTE_COMPONENT; @@ -163,7 +166,8 @@ HWTEST_F(SaveButtonTest, CompareSaveButton003, TestSize.Level1) PasteButton button2; nlohmann::json jsonComponent; TestCommon::BuildSaveComponentInfo(jsonComponent); + std::string message; - ASSERT_TRUE(button1.FromJson(jsonComponent)); + ASSERT_TRUE(button1.FromJson(jsonComponent, message)); ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, true)); } diff --git a/frameworks/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp index 85f469ebf7229d2fa7b333bae4a85e97ca8fc6c1..753c68c45523f6440a59a4add12a2b0c93ecb077 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp @@ -38,11 +38,11 @@ static void TestInCallerNotCheckList() int32_t scId = -1; struct SecCompClickEvent click; std::string emptyStr = ""; - int registerRes = SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, emptyStr, scId); + std::string message; + int registerRes = SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, emptyStr, scId, message); int updateRes = SecCompKit::UpdateSecurityComponent(scId, emptyStr); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; SecCompInfo SecCompInfo{ scId, emptyStr, click }; - std::string message; int reportRes = SecCompKit::ReportSecurityComponentClickEvent(SecCompInfo, nullptr, std::move(func), message); EXPECT_EQ(registerRes, SC_SERVICE_ERROR_CALLER_INVALID); @@ -55,11 +55,11 @@ static void TestInCallerCheckList() int32_t scId = -1; struct SecCompClickEvent click; std::string emptyStr = ""; - int registerRes = SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, emptyStr, scId); + std::string message; + int registerRes = SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, emptyStr, scId, message); int updateRes = SecCompKit::UpdateSecurityComponent(scId, emptyStr); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; SecCompInfo secCompInfo{ scId, emptyStr, click }; - std::string message; int reportRes = SecCompKit::ReportSecurityComponentClickEvent(secCompInfo, nullptr, std::move(func), message); EXPECT_NE(registerRes, SC_SERVICE_ERROR_CALLER_INVALID); @@ -118,8 +118,9 @@ HWTEST_F(SecCompKitTest, ExceptCall001, TestSize.Level1) nlohmann::json jsonRes; comp.ToJson(jsonRes); int32_t scId = -1; + std::string message; std::string jsonStr = jsonRes.dump(); - ASSERT_NE(SC_OK, SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, jsonStr, scId)); + ASSERT_NE(SC_OK, SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, jsonStr, scId, message)); ASSERT_EQ(-1, scId); ASSERT_NE(SC_OK, SecCompKit::UpdateSecurityComponent(scId, jsonStr)); @@ -131,7 +132,6 @@ HWTEST_F(SecCompKitTest, ExceptCall001, TestSize.Level1) }; OnFirstUseDialogCloseFunc func = nullptr; SecCompInfo secCompInfo{ scId, jsonStr, touch }; - std::string message; EXPECT_NE(SC_OK, SecCompKit::ReportSecurityComponentClickEvent(secCompInfo, nullptr, std::move(func), message)); EXPECT_NE(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); } @@ -197,13 +197,14 @@ HWTEST_F(SecCompKitTest, RegisterWithoutCallback001, TestSize.Level1) std::string locationInfo = jsonRes.dump(); int32_t scId; + std::string message; #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE ASSERT_EQ(SC_ENHANCE_ERROR_VALUE_INVALID, - SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId, message)); ASSERT_EQ(0, scId); #else ASSERT_EQ(SC_OK, - SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId, message)); ASSERT_NE(-1, scId); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); #endif diff --git a/frameworks/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp b/frameworks/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp index 6507bdc1d7f8d9e15e6eb9dec80694fe416e62c9..2bd9fa0db6905e9eaea614f46cc6259522954f83 100644 --- a/frameworks/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp +++ b/frameworks/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp @@ -53,10 +53,10 @@ public: static MockUiSecCompProbe g_probe; static __attribute__((noinline)) int32_t RegisterSecurityComponent( - SecCompType type, std::string& componentInfo, int32_t& scId) + SecCompType type, std::string& componentInfo, int32_t& scId, std::string& message) { SC_LOG_INFO(LABEL, "RegisterSecurityComponent enter"); - return SecCompKit::RegisterSecurityComponent(type, componentInfo, scId); + return SecCompKit::RegisterSecurityComponent(type, componentInfo, scId, message); } static __attribute__((noinline)) int32_t ReportSecurityComponentClickEvent( @@ -138,7 +138,8 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent001, TestSize.Lev g_probe.mockRes = 0; int32_t scId; - ASSERT_EQ(SC_OK, RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + std::string message; + ASSERT_EQ(SC_OK, RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId, message)); ASSERT_NE(-1, scId); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); @@ -159,13 +160,14 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent002, TestSize.Lev g_probe.mockRes = -1; int32_t scId; + std::string message; #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE ASSERT_EQ(SC_ENHANCE_ERROR_CALLBACK_OPER_FAIL, - RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId, message)); ASSERT_EQ(-1, scId); #else ASSERT_EQ(SC_OK, - RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId, message)); ASSERT_NE(-1, scId); ASSERT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); #endif @@ -186,7 +188,8 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent003, TestSize.Lev g_probe.mockRes = 0; int32_t scId; - ASSERT_EQ(SC_OK, RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + std::string message; + ASSERT_EQ(SC_OK, RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId, message)); ASSERT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); } @@ -203,8 +206,9 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent004, TestSize.Lev TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; + std::string message; - EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -221,7 +225,6 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent004, TestSize.Lev auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; - std::string message; EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); @@ -241,8 +244,9 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent005, TestSize.Lev TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; + std::string message; - EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -258,7 +262,6 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent005, TestSize.Lev auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; - std::string message; EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); @@ -277,8 +280,9 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterSecurityComponent006, TestSize.Lev TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; + std::string message; setuid(100); - EXPECT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); } /** @@ -294,8 +298,9 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent001, Test TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; + std::string message; - EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -312,7 +317,6 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent001, Test auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; - std::string message; ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); @@ -332,10 +336,11 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent002, Test TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; + std::string message; ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID + g_token_sum)); g_token_sum ++; - EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -353,7 +358,6 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent002, Test auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; - std::string message; ASSERT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); setuid(g_selfUid); @@ -373,10 +377,11 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent003, Test TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; + std::string message; ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID + g_token_sum)); g_token_sum ++; - EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -390,7 +395,6 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent003, Test auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; - std::string message; #ifdef SECURITY_COMPONENT_ENHANCE_ENABLE ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); @@ -413,10 +417,11 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent004, Test TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; + std::string message; ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID + g_token_sum)); g_token_sum ++; - EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -430,7 +435,6 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportSecurityComponentClickEvent004, Test auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = nullptr; SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; - std::string message; ASSERT_EQ(SC_ENHANCE_ERROR_VALUE_INVALID, ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); @@ -452,7 +456,8 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportClickWithoutHmac001, TestSize.Level1 g_probe.mockRes = 0; int32_t scId; - ASSERT_EQ(SC_OK, RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + std::string message; + ASSERT_EQ(SC_OK, RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId, message)); ASSERT_NE(-1, scId); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { @@ -469,7 +474,6 @@ HWTEST_F(SecCompRegisterCallbackTest, ReportClickWithoutHmac001, TestSize.Level1 auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; SecCompInfo secCompInfo{ scId, locationInfo, clickInfo }; - std::string message; EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); @@ -489,10 +493,11 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission001, TestSize.Level1) TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; + std::string message; ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID + g_token_sum)); g_token_sum ++; - EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -508,7 +513,6 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission001, TestSize.Level1) auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; - std::string message; ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); setuid(100); @@ -533,8 +537,9 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission002, TestSize.Level1) TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; + std::string message; - EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -550,7 +555,6 @@ HWTEST_F(SecCompRegisterCallbackTest, VerifySavePermission002, TestSize.Level1) auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; - std::string message; ASSERT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); @@ -570,8 +574,9 @@ HWTEST_F(SecCompRegisterCallbackTest, UnregisterSecurityComponent001, TestSize.L TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; + std::string message; - EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); uint8_t data[TestCommon::MAX_HMAC_SIZE] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -587,7 +592,6 @@ HWTEST_F(SecCompRegisterCallbackTest, UnregisterSecurityComponent001, TestSize.L auto token = callback->AsObject(); OnFirstUseDialogCloseFunc func = [] (int32_t) {}; SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; - std::string message; EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, ReportSecurityComponentClickEvent(secCompInfo, token, std::move(func), message)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); @@ -606,7 +610,8 @@ HWTEST_F(SecCompRegisterCallbackTest, UpdateSecurityComponent001, TestSize.Level TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; - ASSERT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + std::string message; + ASSERT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); ASSERT_NE(-1, scId); ASSERT_EQ(SC_OK, UpdateSecurityComponent(scId, saveInfo)); EXPECT_EQ(SC_OK, SecCompKit::UnregisterSecurityComponent(scId)); @@ -624,10 +629,11 @@ HWTEST_F(SecCompRegisterCallbackTest, UpdateSecurityComponent002, TestSize.Level TestCommon::BuildSaveComponentInfo(jsonRes); std::string saveInfo = jsonRes.dump(); int32_t scId; + std::string message; ASSERT_EQ(0, SetSelfTokenID(TestCommon::HAP_TOKEN_ID + g_token_sum)); g_token_sum ++; - ASSERT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + ASSERT_EQ(SC_OK, RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); ASSERT_NE(-1, scId); setuid(100); ASSERT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, UpdateSecurityComponent(scId, saveInfo)); @@ -649,9 +655,10 @@ HWTEST_F(SecCompRegisterCallbackTest, CheckCipherPrint001, TestSize.Level1) g_probe.mockComponentInfo = locationInfo; g_probe.mockRes = 0; int32_t scId; + std::string message; system("param set sec.comp.enhance 3"); - ASSERT_EQ(SC_OK, RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); - ASSERT_EQ(SC_OK, RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + ASSERT_EQ(SC_OK, RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId, message)); + ASSERT_EQ(SC_OK, RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId, message)); system("param set sec.comp.enhance -1"); } diff --git a/frameworks/security_component/src/location_button.cpp b/frameworks/security_component/src/location_button.cpp index b8c4c388ae6de4c1fe470683d0b184fcacd5a8da..78e70426deeb9b0beff7395e105932e46cb1ae6b 100644 --- a/frameworks/security_component/src/location_button.cpp +++ b/frameworks/security_component/src/location_button.cpp @@ -24,7 +24,7 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "LocationButton"}; } -bool LocationButton::IsTextIconTypeValid() +bool LocationButton::IsTextIconTypeValid(std::string &message) { if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= LocationDesc::MAX_LABEL_TYPE) || (icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= LocationIcon::MAX_ICON_TYPE)) { diff --git a/frameworks/security_component/src/paste_button.cpp b/frameworks/security_component/src/paste_button.cpp index 23d353b752ff7a06df2663293e9a0f801edfd8a3..9a7d03732018280231d002012e9309121c09f3f8 100644 --- a/frameworks/security_component/src/paste_button.cpp +++ b/frameworks/security_component/src/paste_button.cpp @@ -24,7 +24,7 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "PasteButton"}; } -bool PasteButton::IsTextIconTypeValid() +bool PasteButton::IsTextIconTypeValid(std::string& message) { if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= PasteDesc::MAX_LABEL_TYPE) || (icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= PasteIcon::MAX_ICON_TYPE)) { diff --git a/frameworks/security_component/src/save_button.cpp b/frameworks/security_component/src/save_button.cpp index 73a5a9dca912c0882b003b5bb6ac94e29ddc14cd..1215cca7211eebb0e838e2b48ba281d0b688a6c5 100644 --- a/frameworks/security_component/src/save_button.cpp +++ b/frameworks/security_component/src/save_button.cpp @@ -26,7 +26,7 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SaveButton"}; } -bool SaveButton::IsTextIconTypeValid() +bool SaveButton::IsTextIconTypeValid(std::string &message) { if ((text_ <= UNKNOWN_TEXT) || (static_cast(text_) >= SaveDesc::MAX_LABEL_TYPE) || (icon_ <= UNKNOWN_ICON) || (static_cast(icon_) >= SaveIcon::MAX_ICON_TYPE)) { @@ -35,6 +35,8 @@ bool SaveButton::IsTextIconTypeValid() if ((static_cast(icon_) == SaveIcon::PICTURE_ICON) && !IsSystemAppCalling()) { SC_LOG_ERROR(LABEL, "Picture icon only for system application."); + message = ", security component icon type = " + std::to_string(icon_) + + ", picture icon only for system application."; return false; } diff --git a/frameworks/security_component/src/sec_comp_base.cpp b/frameworks/security_component/src/sec_comp_base.cpp index 323d9e3ba54765130e45dfe6c76c65bfb94c826b..2684b701c6fc574255e28f24fbd79ed1775cc513 100644 --- a/frameworks/security_component/src/sec_comp_base.cpp +++ b/frameworks/security_component/src/sec_comp_base.cpp @@ -302,7 +302,7 @@ bool SecCompBase::ParseCrossAxisState(const nlohmann::json& json, const std::str return true; } -bool SecCompBase::FromJson(const nlohmann::json& jsonSrc) +bool SecCompBase::FromJson(const nlohmann::json& jsonSrc, std::string& message) { SC_LOG_DEBUG(LABEL, "Button info %{public}s.", jsonSrc.dump().c_str()); if (!ParseType(jsonSrc, JsonTagConstants::JSON_SC_TYPE)) { @@ -329,7 +329,7 @@ bool SecCompBase::FromJson(const nlohmann::json& jsonSrc) if (!ParseParent(jsonSrc, JsonTagConstants::JSON_PARENT_TAG)) { return false; } - if (!ParseStyle(jsonSrc, JsonTagConstants::JSON_STYLE_TAG)) { + if (!ParseStyle(jsonSrc, JsonTagConstants::JSON_STYLE_TAG, message)) { return false; } if (!ParseValue(jsonSrc, JsonTagConstants::JSON_WINDOW_ID, windowId_)) { @@ -436,7 +436,7 @@ bool SecCompBase::CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck return (leftValue == rightValue); } -bool SecCompBase::ParseStyle(const nlohmann::json& json, const std::string& tag) +bool SecCompBase::ParseStyle(const nlohmann::json& json, const std::string& tag, std::string& message) { if ((json.find(tag) == json.end()) || !json.at(tag).is_object()) { SC_LOG_ERROR(LABEL, "json: %{public}s tag invalid.", tag.c_str()); @@ -460,7 +460,7 @@ bool SecCompBase::ParseStyle(const nlohmann::json& json, const std::string& tag) } text_ = jsonStyle.at(JsonTagConstants::JSON_TEXT_TAG).get(); icon_ = jsonStyle.at(JsonTagConstants::JSON_ICON_TAG).get(); - if (!IsTextIconTypeValid()) { + if (!IsTextIconTypeValid(message)) { SC_LOG_ERROR(LABEL, "text or icon is invalid."); return false; } diff --git a/interfaces/inner_api/security_component/include/location_button.h b/interfaces/inner_api/security_component/include/location_button.h index 9788b0ca81b4215306ee74772c1abb2bbd5cfb52..a482160e51fca8bcd8fa55306a73742fa11b318e 100644 --- a/interfaces/inner_api/security_component/include/location_button.h +++ b/interfaces/inner_api/security_component/include/location_button.h @@ -46,7 +46,7 @@ enum class LocationIcon : int32_t { class __attribute__((visibility("default"))) LocationButton : public SecCompBase { public: - virtual bool IsTextIconTypeValid() override; + virtual bool IsTextIconTypeValid(std::string& message) override; virtual bool IsCorrespondenceType() override; virtual bool CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const override; private: diff --git a/interfaces/inner_api/security_component/include/paste_button.h b/interfaces/inner_api/security_component/include/paste_button.h index 0e43c8f8fd20dfd4f8068102be74e30a4fbcd519..1148ae43c440bd5d11f585db5cd5db0dc3c553f4 100644 --- a/interfaces/inner_api/security_component/include/paste_button.h +++ b/interfaces/inner_api/security_component/include/paste_button.h @@ -35,7 +35,7 @@ enum class PasteIcon : int32_t { class __attribute__((visibility("default"))) PasteButton : public SecCompBase { public: - virtual bool IsTextIconTypeValid() override; + virtual bool IsTextIconTypeValid(std::string& message) override; virtual bool IsCorrespondenceType() override; virtual bool CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const override; diff --git a/interfaces/inner_api/security_component/include/save_button.h b/interfaces/inner_api/security_component/include/save_button.h index b547399c382008d0ae9da0909e78f25b13488abf..2e8e033437b4ac36fada0613b814fb99cf4afe24 100644 --- a/interfaces/inner_api/security_component/include/save_button.h +++ b/interfaces/inner_api/security_component/include/save_button.h @@ -49,7 +49,7 @@ enum class SaveIcon : int32_t { class __attribute__((visibility("default"))) SaveButton : public SecCompBase { public: - virtual bool IsTextIconTypeValid() override; + virtual bool IsTextIconTypeValid(std::string& message) override; virtual bool IsCorrespondenceType() override; virtual bool CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const override; private: diff --git a/interfaces/inner_api/security_component/include/sec_comp_base.h b/interfaces/inner_api/security_component/include/sec_comp_base.h index 02f77402da8dc9bff59b4d75b12ce79ece8328eb..f2c720442d3e0f29c93ca41479e3761e90425ad1 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_base.h +++ b/interfaces/inner_api/security_component/include/sec_comp_base.h @@ -87,7 +87,7 @@ class __attribute__((visibility("default"))) SecCompBase { public: SecCompBase() = default; virtual ~SecCompBase() = default; - bool FromJson(const nlohmann::json& jsonSrc); + bool FromJson(const nlohmann::json& jsonSrc, std::string& message); void ToJson(nlohmann::json& jsonRes) const; std::string ToJsonStr(void) const; virtual bool CompareComponentBasicInfo(SecCompBase *other, bool isRectCheck) const; @@ -138,7 +138,7 @@ public: int32_t nodeId_ = 0; CrossAxisState crossAxisState_ = CrossAxisState::STATE_INVALID; protected: - virtual bool IsTextIconTypeValid() = 0; + virtual bool IsTextIconTypeValid(std::string& message) = 0; virtual bool IsCorrespondenceType() = 0; private: bool ParseDimension(const nlohmann::json& json, const std::string& tag, DimensionT& res); @@ -151,7 +151,7 @@ private: bool ParseSize(const nlohmann::json& json, const std::string& tag); bool ParseParent(const nlohmann::json& json, const std::string& tag); bool ParseRect(const nlohmann::json& json, const std::string& tag, SecCompRect& rect); - bool ParseStyle(const nlohmann::json& json, const std::string& tag); + bool ParseStyle(const nlohmann::json& json, const std::string& tag, std::string& message); bool ParseType(const nlohmann::json& json, const std::string& tag); bool ParseValue(const nlohmann::json& json, const std::string& tag, int32_t& value); bool ParseDisplayId(const nlohmann::json& json, const std::string& tag); diff --git a/interfaces/inner_api/security_component/include/sec_comp_kit.h b/interfaces/inner_api/security_component/include/sec_comp_kit.h index bfa8d08099235dca536dac0713436b6a8969006f..086c6913e056a7cb8052bd53ef57641c02a47838 100644 --- a/interfaces/inner_api/security_component/include/sec_comp_kit.h +++ b/interfaces/inner_api/security_component/include/sec_comp_kit.h @@ -26,7 +26,8 @@ namespace Security { namespace SecurityComponent { class __attribute__((visibility("default"))) SecCompKit { public: - static int32_t RegisterSecurityComponent(SecCompType type, std::string& componentInfo, int32_t& scId); + static int32_t RegisterSecurityComponent(SecCompType type, std::string& componentInfo, + int32_t& scId, std::string& message); static int32_t UpdateSecurityComponent(int32_t scId, std::string& componentInfo); static int32_t UnregisterSecurityComponent(int32_t scId); static int32_t ReportSecurityComponentClickEvent(SecCompInfo& SecCompInfo, sptr callerToken, diff --git a/interfaces/inner_api/security_component_common/sec_comp_info_helper.h b/interfaces/inner_api/security_component_common/sec_comp_info_helper.h index 42005c932bf5c3120e733d45488469c0561ab94a..380255afc7197ffba8c0696bf82f5eeb546354fd 100644 --- a/interfaces/inner_api/security_component_common/sec_comp_info_helper.h +++ b/interfaces/inner_api/security_component_common/sec_comp_info_helper.h @@ -24,10 +24,10 @@ namespace OHOS { namespace Security { namespace SecurityComponent { template -T* ConstructComponent(const nlohmann::json& jsonComponent) +T* ConstructComponent(const nlohmann::json& jsonComponent, std::string& message) { T *componentPtr = new (std::nothrow)T(); - if ((componentPtr != nullptr) && !componentPtr->FromJson(jsonComponent)) { + if ((componentPtr != nullptr) && !componentPtr->FromJson(jsonComponent, message)) { delete componentPtr; return nullptr; } diff --git a/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp b/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp index 6c2a3c9fee91997c350c10a8e772911072524feb..025ee554e213f3d10064e0740899a6bcbb019646 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_info_helper.cpp @@ -61,13 +61,13 @@ SecCompBase* SecCompInfoHelper::ParseComponent(SecCompType type, const nlohmann: SecCompBase* comp = nullptr; switch (type) { case LOCATION_COMPONENT: - comp = ConstructComponent(jsonComponent); + comp = ConstructComponent(jsonComponent, message); break; case PASTE_COMPONENT: - comp = ConstructComponent(jsonComponent); + comp = ConstructComponent(jsonComponent, message); break; case SAVE_COMPONENT: - comp = ConstructComponent(jsonComponent); + comp = ConstructComponent(jsonComponent, message); break; default: SC_LOG_ERROR(LABEL, "Parse component type unknown"); diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp index 98e41dec86b5adeec63b65f4332e2c6de5db44fb..7de4a06b30c1b4dbb3af97ece3691cd24d44cc13 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.cpp @@ -350,7 +350,7 @@ int32_t SecCompManager::AddSecurityComponentProcess(const SecCompCallerInfo& cal } int32_t SecCompManager::RegisterSecurityComponent(SecCompType type, - const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller, int32_t& scId) + const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller, int32_t& scId, std::string& message) { SC_LOG_DEBUG(LABEL, "PID: %{public}d, register security component", caller.pid); if (malicious_.IsInMaliciousAppList(caller.pid, caller.uid)) { @@ -358,7 +358,6 @@ int32_t SecCompManager::RegisterSecurityComponent(SecCompType type, return SC_ENHANCE_ERROR_IN_MALICIOUS_LIST; } - std::string message; SecCompBase* componentPtr = SecCompInfoHelper::ParseComponent(type, jsonComponent, message); std::shared_ptr component(componentPtr); if (component == nullptr) { diff --git a/services/security_component_service/sa/sa_main/sec_comp_manager.h b/services/security_component_service/sa/sa_main/sec_comp_manager.h index 30de2ddecb21dcae455a860f01e3b3097d13276a..316570b04d38b76dcdb9500f9be1611e9f8f0686 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_manager.h +++ b/services/security_component_service/sa/sa_main/sec_comp_manager.h @@ -53,7 +53,7 @@ public: virtual ~SecCompManager() = default; int32_t RegisterSecurityComponent(SecCompType type, const nlohmann::json& jsonComponent, - const SecCompCallerInfo& caller, int32_t& scId); + const SecCompCallerInfo& caller, int32_t& scId, std::string& message); int32_t UpdateSecurityComponent(int32_t scId, const nlohmann::json& jsonComponent, const SecCompCallerInfo& caller); int32_t UnregisterSecurityComponent(int32_t scId, const SecCompCallerInfo& caller); diff --git a/services/security_component_service/sa/sa_main/sec_comp_service.cpp b/services/security_component_service/sa/sa_main/sec_comp_service.cpp index 35cce2879a982c7a6cc99518466790445c24f5ed..406f275bdfb2a4358044fecc079de51e925a78b2 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_service.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_service.cpp @@ -185,7 +185,7 @@ int32_t SecCompService::ParseParams(const std::string& componentInfo, } int32_t SecCompService::RegisterSecurityComponent(SecCompType type, - const std::string& componentInfo, int32_t& scId) + const std::string& componentInfo, int32_t& scId, std::string& message) { StartTrace(HITRACE_TAG_ACCESS_CONTROL, "SecurityComponentRegister"); SecCompCallerInfo caller; @@ -205,7 +205,7 @@ int32_t SecCompService::RegisterSecurityComponent(SecCompType type, return SC_SERVICE_ERROR_VALUE_INVALID; } - int32_t res = SecCompManager::GetInstance().RegisterSecurityComponent(type, jsonRes, caller, scId); + int32_t res = SecCompManager::GetInstance().RegisterSecurityComponent(type, jsonRes, caller, scId, message); FinishTrace(HITRACE_TAG_ACCESS_CONTROL); int32_t uid = IPCSkeleton::GetCallingUid(); diff --git a/services/security_component_service/sa/sa_main/sec_comp_service.h b/services/security_component_service/sa/sa_main/sec_comp_service.h index 9a4541076f6285ea4763f1d6c8faf7641f21984f..7a39cbf98740d322845418ab4c9fe9c55a35dd39 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_service.h +++ b/services/security_component_service/sa/sa_main/sec_comp_service.h @@ -40,7 +40,8 @@ public: void OnStart() override; void OnStop() override; - int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, int32_t& scId) override; + int32_t RegisterSecurityComponent(SecCompType type, const std::string& componentInfo, + int32_t& scId, std::string& message) override; int32_t UpdateSecurityComponent(int32_t scId, const std::string& componentInfo) override; int32_t UnregisterSecurityComponent(int32_t scId) override; int32_t ReportSecurityComponentClickEvent(SecCompInfo& secCompInfo, sptr callerToken, diff --git a/services/security_component_service/sa/sa_main/sec_comp_stub.cpp b/services/security_component_service/sa/sa_main/sec_comp_stub.cpp index 198b0876d395562fc118c2a9764d5f4760cef696..2886cff7275b862050cdeb1258d9cb0c31700209 100644 --- a/services/security_component_service/sa/sa_main/sec_comp_stub.cpp +++ b/services/security_component_service/sa/sa_main/sec_comp_stub.cpp @@ -75,7 +75,8 @@ int32_t SecCompStub::RegisterSecurityComponentInner(MessageParcel& data, Message } int32_t scId = INVALID_SC_ID; - int32_t res = this->RegisterSecurityComponent(static_cast(type), componentInfo, scId); + std::string message; + int32_t res = this->RegisterSecurityComponent(static_cast(type), componentInfo, scId, message); MessageParcel rawReply; if (!rawReply.WriteInt32(res)) { SC_LOG_ERROR(LABEL, "Register security component result failed"); @@ -87,6 +88,11 @@ int32_t SecCompStub::RegisterSecurityComponentInner(MessageParcel& data, Message return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; } + if (!rawReply.WriteString(message)) { + SC_LOG_ERROR(LABEL, "Register security component result failed"); + return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; + } + if (!SecCompEnhanceAdapter::EnhanceSrvSerialize(rawReply, reply)) { SC_LOG_ERROR(LABEL, "Register serialize session info failed"); return SC_SERVICE_ERROR_PARCEL_OPERATE_FAIL; diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp index 5f961960179b75164dbc421cf432638eb74a48e0..73ae3ea309585c85e45999a120d5704217e5355a 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp @@ -336,23 +336,26 @@ HWTEST_F(SecCompManagerTest, RegisterSecurityComponent001, TestSize.Level1) .pid = ServiceTestCommon::TEST_PID_1 }; int32_t scId; + std::string message; SecCompManager::GetInstance().malicious_.maliciousAppList_.insert(ServiceTestCommon::TEST_PID_1); nlohmann::json jsonInvalid; EXPECT_EQ(SC_ENHANCE_ERROR_IN_MALICIOUS_LIST, - SecCompManager::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, jsonInvalid, caller, scId)); + SecCompManager::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, + jsonInvalid, caller, scId, message)); SecCompManager::GetInstance().malicious_.maliciousAppList_.clear(); LocationButton buttonInvalid = BuildInvalidLocationComponent(); buttonInvalid.ToJson(jsonInvalid); EXPECT_EQ(SC_SERVICE_ERROR_COMPONENT_INFO_INVALID, - SecCompManager::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, jsonInvalid, caller, scId)); + SecCompManager::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, + jsonInvalid, caller, scId, message)); nlohmann::json jsonValid; LocationButton buttonValid = BuildValidLocationComponent(); buttonValid.ToJson(jsonValid); EXPECT_EQ(SC_OK, - SecCompManager::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, jsonValid, caller, scId)); + SecCompManager::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, jsonValid, caller, scId, message)); SecCompManager::GetInstance().malicious_.maliciousAppList_.clear(); } diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_service_mock_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_service_mock_test.cpp index d86203c79da94271e48fe0a4f3e56cde6d8781b9..ef39b9831d5cc86dc63a7fa74330cd921191851c 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_service_mock_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_service_mock_test.cpp @@ -81,9 +81,11 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent001, TestSize.Level1) { // get caller fail int32_t scId; + std::string message; secCompService_->state_ = ServiceRunningState::STATE_RUNNING; secCompService_->Initialize(); - EXPECT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, secCompService_->RegisterSecurityComponent(SAVE_COMPONENT, "", scId)); + EXPECT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, + secCompService_->RegisterSecurityComponent(SAVE_COMPONENT, "", scId, message)); nlohmann::json jsonRes; ServiceTestCommon::BuildSaveComponentJson(jsonRes); std::string saveInfo = jsonRes.dump(); @@ -95,10 +97,11 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent001, TestSize.Level1) }; secCompService_->appStateObserver_->AddProcessToForegroundSet(stateData); // wrong json - EXPECT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, secCompService_->RegisterSecurityComponent(SAVE_COMPONENT, "{a=", scId)); + EXPECT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, + secCompService_->RegisterSecurityComponent(SAVE_COMPONENT, "{a=", scId, message)); // register security component ok - EXPECT_EQ(SC_OK, secCompService_->RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, secCompService_->RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); EXPECT_EQ(SC_OK, secCompService_->UpdateSecurityComponent(scId, saveInfo)); uint8_t buffer[1] = { 0 }; struct SecCompClickEvent touch = { @@ -114,7 +117,6 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent001, TestSize.Level1) }, }; SecCompInfo secCompInfo{ scId, saveInfo, touch }; - std::string message; EXPECT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); SecCompPermManager::GetInstance().applySaveCountMap_.clear(); @@ -129,6 +131,7 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent001, TestSize.Level1) HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent002, TestSize.Level1) { int32_t scId; + std::string message; secCompService_->state_ = ServiceRunningState::STATE_RUNNING; secCompService_->Initialize(); nlohmann::json jsonRes; @@ -141,7 +144,7 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent002, TestSize.Level1) }; secCompService_->appStateObserver_->AddProcessToForegroundSet(stateData); // register security component ok - EXPECT_EQ(SC_OK, secCompService_->RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, secCompService_->RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); struct SecCompClickEvent touch = { .type = ClickEventType::POINT_EVENT_TYPE, .point.touchX = 100, @@ -150,7 +153,6 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent002, TestSize.Level1) std::chrono::high_resolution_clock::now().time_since_epoch().count()) }; SecCompInfo secCompInfo{ scId, saveInfo, touch }; - std::string message; EXPECT_EQ(SC_SERVICE_ERROR_CLICK_EVENT_INVALID, secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); @@ -166,6 +168,7 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent002, TestSize.Level1) HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent003, TestSize.Level1) { int32_t scId; + std::string message; secCompService_->state_ = ServiceRunningState::STATE_RUNNING; secCompService_->Initialize(); nlohmann::json jsonRes; @@ -178,7 +181,7 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent003, TestSize.Level1) }; secCompService_->appStateObserver_->AddProcessToForegroundSet(stateData); // register security component ok - EXPECT_EQ(SC_OK, secCompService_->RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + EXPECT_EQ(SC_OK, secCompService_->RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); uint8_t buffer[1] = { 0 }; struct SecCompClickEvent touch = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -193,7 +196,6 @@ HWTEST_F(SecCompServiceMockTest, RegisterSecurityComponent003, TestSize.Level1) }, }; SecCompInfo secCompInfo{ scId, saveInfo, touch }; - std::string message; EXPECT_EQ(SC_SERVICE_ERROR_PERMISSION_OPER_FAIL, secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); @@ -221,7 +223,8 @@ HWTEST_F(SecCompServiceMockTest, ReportSecurityComponentClickEvent001, TestSize. }; secCompService_->appStateObserver_->AddProcessToForegroundSet(stateData); // register security component ok - EXPECT_EQ(SC_OK, secCompService_->RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId)); + std::string message; + EXPECT_EQ(SC_OK, secCompService_->RegisterSecurityComponent(SAVE_COMPONENT, saveInfo, scId, message)); uint8_t buffer[1] = { 0 }; struct SecCompClickEvent clickInfo = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -236,7 +239,6 @@ HWTEST_F(SecCompServiceMockTest, ReportSecurityComponentClickEvent001, TestSize. }, }; SecCompInfo secCompInfo{ scId, saveInfo, clickInfo }; - std::string message; ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); // test 10s valid @@ -281,7 +283,8 @@ HWTEST_F(SecCompServiceMockTest, ReportSecurityComponentClickEvent002, TestSize. }; secCompService_->appStateObserver_->AddProcessToForegroundSet(stateData); // register security component ok - EXPECT_EQ(SC_OK, secCompService_->RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + std::string message; + EXPECT_EQ(SC_OK, secCompService_->RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId, message)); uint8_t buffer[1] = { 0 }; struct SecCompClickEvent clickInfo1 = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -296,7 +299,6 @@ HWTEST_F(SecCompServiceMockTest, ReportSecurityComponentClickEvent002, TestSize. }, }; SecCompInfo secCompInfo{ scId, locationInfo, clickInfo1 }; - std::string message; ASSERT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp index f8936c8b01d519453deff115f8a541522b88a0f3..fdd47d4c61c0c2c46b5a628912964ce2e9dbfe09 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp @@ -245,8 +245,9 @@ HWTEST_F(SecCompServiceTest, ReportSecurityComponentClickEvent001, TestSize.Leve auto uid = getuid(); // get caller fail int32_t scId; + std::string message; EXPECT_EQ(SC_SERVICE_ERROR_VALUE_INVALID, - secCompService_->RegisterSecurityComponent(LOCATION_COMPONENT, "", scId)); + secCompService_->RegisterSecurityComponent(LOCATION_COMPONENT, "", scId, message)); nlohmann::json jsonRes; ServiceTestCommon::BuildLocationComponentJson(jsonRes); @@ -261,7 +262,7 @@ HWTEST_F(SecCompServiceTest, ReportSecurityComponentClickEvent001, TestSize.Leve secCompService_->appStateObserver_->AddProcessToForegroundSet(stateData); EXPECT_EQ(SC_OK, - secCompService_->RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + secCompService_->RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId, message)); uint8_t data[16] = { 0 }; struct SecCompClickEvent touch = { .type = ClickEventType::POINT_EVENT_TYPE, @@ -274,7 +275,6 @@ HWTEST_F(SecCompServiceTest, ReportSecurityComponentClickEvent001, TestSize.Leve .extraInfo.dataSize = 16, }; SecCompInfo secCompInfo{ scId, locationInfo, touch }; - std::string message; EXPECT_EQ(SC_OK, secCompService_->ReportSecurityComponentClickEvent(secCompInfo, nullptr, nullptr, message)); EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_stub_mock_test.h b/services/security_component_service/sa/test/unittest/src/sec_comp_stub_mock_test.h index 4a197be5e6caa1fb3dcab352217640695e8bffc7..c43a55079558c92d95f17ed799ee65843baeb85a 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_stub_mock_test.h +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_stub_mock_test.h @@ -28,7 +28,7 @@ namespace SecurityComponent { struct SecCompStubMock : public SecCompStub { public: int32_t RegisterSecurityComponent(SecCompType type, - const std::string& componentInfo, int32_t& scId) override + const std::string& componentInfo, int32_t& scId, std::string& message) override { return 0; }; diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_stub_test.h b/services/security_component_service/sa/test/unittest/src/sec_comp_stub_test.h index a29772a782bbc3c63ee8073b915f975996bec6b7..0c09982ba2d80533e4de2699c22ed10993e35a21 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_stub_test.h +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_stub_test.h @@ -28,7 +28,7 @@ namespace SecurityComponent { struct SecCompStubMock : public SecCompStub { public: int32_t RegisterSecurityComponent(SecCompType type, - const std::string& componentInfo, int32_t& scId) override + const std::string& componentInfo, int32_t& scId, std::string& message) override { return 0; }; diff --git a/test/fuzztest/security_component/innerkits/registersecuritycomponent_fuzzer/registersecuritycomponent_fuzzer.cpp b/test/fuzztest/security_component/innerkits/registersecuritycomponent_fuzzer/registersecuritycomponent_fuzzer.cpp index 34ae96a07d2e3ee27fe088f225736913ff939744..c0d5d55a36c57b900adfd146e787172fa67b0375 100644 --- a/test/fuzztest/security_component/innerkits/registersecuritycomponent_fuzzer/registersecuritycomponent_fuzzer.cpp +++ b/test/fuzztest/security_component/innerkits/registersecuritycomponent_fuzzer/registersecuritycomponent_fuzzer.cpp @@ -31,10 +31,11 @@ namespace OHOS { static void RegisterSecurityComponentFuzzTest(const uint8_t *data, size_t size) { CompoRandomGenerator generator(data, size); - SecCompType type = static_cast(generator.GetScType()) ; + SecCompType type = static_cast(generator.GetScType()); std::string componentInfo = generator.GenerateRandomCompoStr(type); int32_t scId = generator.GetData(); - SecCompKit::RegisterSecurityComponent(type, componentInfo, scId); + std::string message = generator.GenerateRandomCompoStr(type); + SecCompKit::RegisterSecurityComponent(type, componentInfo, scId, message); } } // namespace OHOS