mirror of
https://github.com/openharmony/security_security_component_manager.git
synced 2026-08-24 22:51:27 -04:00
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
// for security component service to send command to enhance service
|
||||
class SecCompSrvEnhanceInterface {
|
||||
public:
|
||||
public:
|
||||
// enable input enhance, then enhance service send config to multimodalinput
|
||||
virtual int32_t EnableInputEnhance() = 0;
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "sec_comp_enhance_test.h"
|
||||
#include <unistd.h>
|
||||
#include "sec_comp_err.h"
|
||||
#include "sec_comp_log.h"
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Security::SecurityComponent;
|
||||
|
||||
@@ -43,6 +43,8 @@ const std::string TYPE_KEY = "ohos.user.security.type";
|
||||
const std::string TOKEN_KEY = "ohos.ability.params.token";
|
||||
|
||||
constexpr uint32_t MAX_CFG_FILE_SIZE = 100 * 1024; // 100k
|
||||
constexpr uint64_t LOCATION_BUTTON_FIRST_USE = 1 << 0;
|
||||
constexpr uint64_t SAVE_BUTTON_FIRST_USE = 1 << 1;
|
||||
}
|
||||
|
||||
bool FirstUseDialog::IsCfgDirExist(void)
|
||||
@@ -78,7 +80,7 @@ bool FirstUseDialog::IsCfgFileValid(void)
|
||||
return false;
|
||||
}
|
||||
if (fstat.st_size > MAX_CFG_FILE_SIZE) {
|
||||
SC_LOG_INFO(LABEL, "path %{public}s errno %{public}d.", FIRST_USE_RECORD_JSON.c_str(), errno);
|
||||
SC_LOG_INFO(LABEL, "path %{public}s size too large.", FIRST_USE_RECORD_JSON.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -243,16 +245,16 @@ void FirstUseDialog::SendSaveEventHandler(void)
|
||||
secHandler_->ProxyPostTask(delayed);
|
||||
}
|
||||
|
||||
void FirstUseDialog::NotifyFirstUseDialog(AccessToken::AccessTokenID tokenId, SecCompType type,
|
||||
bool FirstUseDialog::NotifyFirstUseDialog(AccessToken::AccessTokenID tokenId, SecCompType type,
|
||||
sptr<IRemoteObject> callerToken)
|
||||
{
|
||||
if (secHandler_ == nullptr) {
|
||||
SC_LOG_ERROR(LABEL, "event handler invalid.");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
if (callerToken == nullptr) {
|
||||
SC_LOG_INFO(LABEL, "callerToken is null, no need to notify dialog");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t typeMask;
|
||||
@@ -262,7 +264,7 @@ void FirstUseDialog::NotifyFirstUseDialog(AccessToken::AccessTokenID tokenId, Se
|
||||
typeMask = SAVE_BUTTON_FIRST_USE;
|
||||
} else {
|
||||
SC_LOG_INFO(LABEL, "this type need not notify dialog to user");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(useMapMutex_);
|
||||
@@ -272,17 +274,18 @@ void FirstUseDialog::NotifyFirstUseDialog(AccessToken::AccessTokenID tokenId, Se
|
||||
StartDialogAbility(type, callerToken);
|
||||
firstUseMap_[tokenId] = typeMask;
|
||||
SendSaveEventHandler();
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t compTypes = firstUseMap_[tokenId];
|
||||
if ((compTypes & typeMask) == typeMask) {
|
||||
SC_LOG_INFO(LABEL, "no need notify again.");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
StartDialogAbility(type, callerToken);
|
||||
firstUseMap_[tokenId] |= typeMask;
|
||||
SendSaveEventHandler();
|
||||
return true;
|
||||
}
|
||||
|
||||
void FirstUseDialog::Init(std::shared_ptr<SecEventHandler> secHandler)
|
||||
@@ -294,4 +297,3 @@ void FirstUseDialog::Init(std::shared_ptr<SecEventHandler> secHandler)
|
||||
} // namespace SecurityComponent
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
|
||||
|
||||
@@ -29,14 +29,11 @@
|
||||
namespace OHOS {
|
||||
namespace Security {
|
||||
namespace SecurityComponent {
|
||||
constexpr uint64_t LOCATION_BUTTON_FIRST_USE = 1 << 0;
|
||||
constexpr uint64_t SAVE_BUTTON_FIRST_USE = 1 << 1;
|
||||
|
||||
class FirstUseDialog final {
|
||||
public:
|
||||
FirstUseDialog() = default;
|
||||
~FirstUseDialog() = default;
|
||||
void NotifyFirstUseDialog(AccessToken::AccessTokenID tokenId, SecCompType type, sptr<IRemoteObject> callerToken);
|
||||
bool NotifyFirstUseDialog(AccessToken::AccessTokenID tokenId, SecCompType type, sptr<IRemoteObject> callerToken);
|
||||
void Init(std::shared_ptr<SecEventHandler> secHandler);
|
||||
|
||||
private:
|
||||
@@ -61,4 +58,3 @@ private:
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
#endif // FIRST_USE_DIALOG_H
|
||||
|
||||
|
||||
@@ -121,7 +121,6 @@ bool SecCompPermManager::InitEventHandler(const std::shared_ptr<SecEventHandler>
|
||||
secHandler_ = secHandler;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace SecurityComponent
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -43,6 +43,7 @@ ohos_unittest("sec_comp_service_test") {
|
||||
"${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_comp_service.cpp",
|
||||
"${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_comp_stub.cpp",
|
||||
"${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_event_handler.cpp",
|
||||
"${sec_comp_root_dir}/services/security_component_service/sa/test/mock/src/accesstoken_kit.cpp",
|
||||
"${sec_comp_root_dir}/services/security_component_service/sa/test/mock/src/mock_app_mgr_proxy.cpp",
|
||||
"${sec_comp_root_dir}/services/security_component_service/sa/test/mock/src/mock_iservice_registry.cpp",
|
||||
"unittest/src/app_state_observer_test.cpp",
|
||||
@@ -111,9 +112,11 @@ ohos_unittest("sec_comp_service_mock_test") {
|
||||
"${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_comp_service.cpp",
|
||||
"${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_comp_stub.cpp",
|
||||
"${sec_comp_root_dir}/services/security_component_service/sa/sa_main/sec_event_handler.cpp",
|
||||
"${sec_comp_root_dir}/services/security_component_service/sa/test/mock/src/accesstoken_kit.cpp",
|
||||
"${sec_comp_root_dir}/services/security_component_service/sa/test/mock/src/mock_app_mgr_proxy.cpp",
|
||||
"${sec_comp_root_dir}/services/security_component_service/sa/test/mock/src/mock_iservice_registry.cpp",
|
||||
"${sec_comp_root_dir}/services/security_component_service/sa/test/mock/src/sec_comp_enhance_adapter.cpp",
|
||||
"unittest/src/first_use_dialog_test.cpp",
|
||||
"unittest/src/sec_comp_service_mock_test.cpp",
|
||||
"unittest/src/service_test_common.cpp",
|
||||
]
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
|
||||
static int GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo& hapTokenInfoRes)
|
||||
{
|
||||
return 0;
|
||||
return AccessTokenKit::getHapTokenInfoRes;
|
||||
};
|
||||
|
||||
static AccessTokenID GetHapTokenID(int32_t userID, const std::string& bundleName, int32_t instIndex)
|
||||
@@ -51,6 +51,7 @@ public:
|
||||
AccessTokenIDInner *idInner = reinterpret_cast<AccessTokenIDInner *>(&tokenID);
|
||||
return static_cast<ATokenTypeEnum>(idInner->type);
|
||||
};
|
||||
static int getHapTokenInfoRes;
|
||||
};
|
||||
} // namespace SECURITY_COMPONENT_INTERFACES_INNER_KITS_ACCESSTOKEN_KIT_H
|
||||
} // namespace Security
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
|
||||
class IAppMgr : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.mock.AppMgr");
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Security {
|
||||
namespace AccessToken {
|
||||
int32_t AccessTokenKit::getHapTokenInfoRes = 0;
|
||||
} // namespace SECURITY_COMPONENT_INTERFACES_INNER_KITS_ACCESSTOKEN_KIT_H
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "first_use_dialog_test.h"
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
#include "sec_comp_log.h"
|
||||
#include "sec_comp_err.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::Security::SecurityComponent;
|
||||
using namespace OHOS::Security::AccessToken;
|
||||
|
||||
namespace {
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
|
||||
LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "FirstUseDialogTest"};
|
||||
static const std::string SEC_COMP_SRV_CFG_PATH = "/data/service/el1/public/security_component_service";
|
||||
static const std::string SEC_COMP_SRV_CFG_FILE = SEC_COMP_SRV_CFG_PATH + "/" + "first_use_record.json";
|
||||
static const std::string SEC_COMP_SRV_CFG_BACK_FILE = SEC_COMP_SRV_CFG_PATH + "/" + "first_use_record.json.bak";
|
||||
constexpr uint64_t LOCATION_BUTTON_FIRST_USE = 1 << 0;
|
||||
constexpr uint64_t SAVE_BUTTON_FIRST_USE = 1 << 1;
|
||||
}
|
||||
|
||||
void FirstUseDialogTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void FirstUseDialogTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void FirstUseDialogTest::SetUp()
|
||||
{
|
||||
SC_LOG_INFO(LABEL, "setup");
|
||||
struct stat fstat = {};
|
||||
if (stat(SEC_COMP_SRV_CFG_FILE.c_str(), &fstat) != 0) {
|
||||
return;
|
||||
}
|
||||
std::string cmdline = "mv " + SEC_COMP_SRV_CFG_FILE + " " + SEC_COMP_SRV_CFG_BACK_FILE;
|
||||
system(cmdline.c_str());
|
||||
}
|
||||
|
||||
void FirstUseDialogTest::TearDown()
|
||||
{
|
||||
struct stat fstat = {};
|
||||
if (stat(SEC_COMP_SRV_CFG_BACK_FILE.c_str(), &fstat) != 0) {
|
||||
return;
|
||||
}
|
||||
std::string cmdline = "mv " + SEC_COMP_SRV_CFG_BACK_FILE + " " + SEC_COMP_SRV_CFG_FILE;
|
||||
system(cmdline.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadFirstUseRecord001
|
||||
* @tc.desc: Test cfg file not exist
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord001, TestSize.Level1)
|
||||
{
|
||||
FirstUseDialog diag;
|
||||
diag.LoadFirstUseRecord();
|
||||
ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadFirstUseRecord002
|
||||
* @tc.desc: Test cfg file too large
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord002, TestSize.Level1)
|
||||
{
|
||||
std::string cmdline = "dd if=/dev/random of=" + SEC_COMP_SRV_CFG_FILE + " bs=101k count=1";
|
||||
system(cmdline.c_str());
|
||||
FirstUseDialog diag;
|
||||
diag.LoadFirstUseRecord();
|
||||
ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadFirstUseRecord003
|
||||
* @tc.desc: Test cfg file is not json
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord003, TestSize.Level1)
|
||||
{
|
||||
std::string cmdline = "echo {x=\\\' > " + SEC_COMP_SRV_CFG_FILE;
|
||||
system(cmdline.c_str());
|
||||
FirstUseDialog diag;
|
||||
diag.LoadFirstUseRecord();
|
||||
ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadFirstUseRecord004
|
||||
* @tc.desc: Test cfg file has no tag named FIRST_USE_RECORD_TAG
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord004, TestSize.Level1)
|
||||
{
|
||||
std::string cmdline = "echo {\\\"x\\\":1} > " + SEC_COMP_SRV_CFG_FILE;
|
||||
system(cmdline.c_str());
|
||||
FirstUseDialog diag;
|
||||
diag.LoadFirstUseRecord();
|
||||
ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadFirstUseRecord005
|
||||
* @tc.desc: Test cfg file has no tag named TOKEN_ID_TAG
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord005, TestSize.Level1)
|
||||
{
|
||||
std::string cmdline = "echo {\\\"FirstUseRecord\\\":[{\\\"CompType\\\":1}]} > "
|
||||
+ SEC_COMP_SRV_CFG_FILE;
|
||||
system(cmdline.c_str());
|
||||
FirstUseDialog diag;
|
||||
diag.LoadFirstUseRecord();
|
||||
ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadFirstUseRecord006
|
||||
* @tc.desc: Test cfg file TOKEN_ID_TAG is not number
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord006, TestSize.Level1)
|
||||
{
|
||||
std::string cmdline = "echo {\\\"FirstUseRecord\\\":[{\\\"CompType\\\":1,\\\"TokenId\\\":\\\"kk\\\"}]} > "
|
||||
+ SEC_COMP_SRV_CFG_FILE;
|
||||
system(cmdline.c_str());
|
||||
FirstUseDialog diag;
|
||||
diag.LoadFirstUseRecord();
|
||||
ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadFirstUseRecord007
|
||||
* @tc.desc: Test cfg file TOKEN_ID_TAG value is 0
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord007, TestSize.Level1)
|
||||
{
|
||||
std::string cmdline = "echo {\\\"FirstUseRecord\\\":[{\\\"CompType\\\":1,\\\"TokenId\\\":0}]} > "
|
||||
+ SEC_COMP_SRV_CFG_FILE;
|
||||
system(cmdline.c_str());
|
||||
FirstUseDialog diag;
|
||||
diag.LoadFirstUseRecord();
|
||||
ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadFirstUseRecord008
|
||||
* @tc.desc: Test cfg file COMP_TYPE_TAG is not exist
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord008, TestSize.Level1)
|
||||
{
|
||||
std::string cmdline = "echo {\\\"FirstUseRecord\\\":[{\\\"TokenId\\\":1}]} > "
|
||||
+ SEC_COMP_SRV_CFG_FILE;
|
||||
system(cmdline.c_str());
|
||||
FirstUseDialog diag;
|
||||
diag.LoadFirstUseRecord();
|
||||
ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadFirstUseRecord009
|
||||
* @tc.desc: Test cfg file COMP_TYPE_TAG is number
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord009, TestSize.Level1)
|
||||
{
|
||||
std::string cmdline = "echo {\\\"FirstUseRecord\\\":[{\\\"CompType\\\":\\\"k\\\",\\\"TokenId\\\":1}]} > "
|
||||
+ SEC_COMP_SRV_CFG_FILE;
|
||||
system(cmdline.c_str());
|
||||
FirstUseDialog diag;
|
||||
diag.LoadFirstUseRecord();
|
||||
ASSERT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: LoadFirstUseRecord010
|
||||
* @tc.desc: Test cfg file is success
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, LoadFirstUseRecord010, TestSize.Level1)
|
||||
{
|
||||
std::string cmdline = "echo {\\\"FirstUseRecord\\\":[{\\\"CompType\\\":1,\\\"TokenId\\\":1}]} > "
|
||||
+ SEC_COMP_SRV_CFG_FILE;
|
||||
system(cmdline.c_str());
|
||||
FirstUseDialog diag;
|
||||
diag.LoadFirstUseRecord();
|
||||
ASSERT_EQ(1, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
ASSERT_EQ(1, static_cast<int32_t>(diag.firstUseMap_[1]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SaveFirstUseRecord001
|
||||
* @tc.desc: Test cfg dir is not exist
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, SaveFirstUseRecord001, TestSize.Level1)
|
||||
{
|
||||
std::string cmdline = "rm " + SEC_COMP_SRV_CFG_PATH + " -rf";
|
||||
system(cmdline.c_str());
|
||||
FirstUseDialog diag;
|
||||
diag.firstUseMap_[1] = 1;
|
||||
diag.SaveFirstUseRecord();
|
||||
diag.firstUseMap_.clear();
|
||||
diag.LoadFirstUseRecord();
|
||||
EXPECT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
std::string cmdline1 = "mkdir " + SEC_COMP_SRV_CFG_PATH + " 0750 security_component security_component";
|
||||
system(cmdline1.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SaveFirstUseRecord002
|
||||
* @tc.desc: Test cfg dir is not dir
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, SaveFirstUseRecord002, TestSize.Level1)
|
||||
{
|
||||
std::string cmdline = "rm " + SEC_COMP_SRV_CFG_PATH + " -rf && touch " + SEC_COMP_SRV_CFG_PATH;
|
||||
system(cmdline.c_str());
|
||||
FirstUseDialog diag;
|
||||
diag.firstUseMap_[1] = 1;
|
||||
diag.SaveFirstUseRecord();
|
||||
diag.firstUseMap_.clear();
|
||||
diag.LoadFirstUseRecord();
|
||||
EXPECT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
std::string cmdline1 = "rm " + SEC_COMP_SRV_CFG_PATH + " && mkdir " +
|
||||
SEC_COMP_SRV_CFG_PATH + " 0750 security_component security_component";
|
||||
system(cmdline1.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SaveFirstUseRecord003
|
||||
* @tc.desc: Test cfg file is not exist, tokenid is invalid.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, SaveFirstUseRecord003, TestSize.Level1)
|
||||
{
|
||||
FirstUseDialog diag;
|
||||
OHOS::Security::AccessToken::AccessTokenKit::getHapTokenInfoRes = -1;
|
||||
diag.firstUseMap_[1] = 1;
|
||||
diag.SaveFirstUseRecord();
|
||||
diag.firstUseMap_.clear();
|
||||
diag.LoadFirstUseRecord();
|
||||
EXPECT_EQ(0, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
OHOS::Security::AccessToken::AccessTokenKit::getHapTokenInfoRes = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SaveFirstUseRecord004
|
||||
* @tc.desc: Test cfg file is exist, save ok
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, SaveFirstUseRecord004, TestSize.Level1)
|
||||
{
|
||||
FirstUseDialog diag;
|
||||
diag.firstUseMap_[1] = 1;
|
||||
diag.SaveFirstUseRecord();
|
||||
diag.firstUseMap_.clear();
|
||||
diag.LoadFirstUseRecord();
|
||||
EXPECT_EQ(1, static_cast<int32_t>(diag.firstUseMap_.size()));
|
||||
EXPECT_EQ(1, static_cast<int32_t>(diag.firstUseMap_[1]));
|
||||
}
|
||||
|
||||
class TestRemoteObject : public IRemoteObject {
|
||||
public:
|
||||
explicit TestRemoteObject(std::u16string descriptor) : IRemoteObject(descriptor)
|
||||
{
|
||||
};
|
||||
|
||||
~TestRemoteObject() = default;
|
||||
|
||||
bool IsProxyObject() const override
|
||||
{
|
||||
return false;
|
||||
};
|
||||
|
||||
int32_t GetObjectRefCount() override
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
|
||||
int Dump(int fd, const std::vector<std::u16string>& args) override
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
|
||||
int SendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override
|
||||
{
|
||||
return -1;
|
||||
};
|
||||
|
||||
bool AddDeathRecipient(const sptr<DeathRecipient>& recipient) override
|
||||
{
|
||||
return false;
|
||||
};
|
||||
|
||||
bool RemoveDeathRecipient(const sptr<DeathRecipient>& recipient) override
|
||||
{
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
* @tc.name: NotifyFirstUseDialog001
|
||||
* @tc.desc: Test NotifyFirstUseDialog
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(FirstUseDialogTest, NotifyFirstUseDialog001, TestSize.Level1)
|
||||
{
|
||||
FirstUseDialog diag;
|
||||
diag.secHandler_ = nullptr;
|
||||
// no handler
|
||||
ASSERT_FALSE(diag.NotifyFirstUseDialog(0, LOCATION_COMPONENT, nullptr));
|
||||
|
||||
// no calltoken
|
||||
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(true);
|
||||
ASSERT_NE(nullptr, runner);
|
||||
std::shared_ptr<SecEventHandler> handler = std::make_shared<SecEventHandler>(runner);
|
||||
diag.secHandler_ = handler;
|
||||
ASSERT_FALSE(diag.NotifyFirstUseDialog(0, LOCATION_COMPONENT, nullptr));
|
||||
|
||||
// type invalid
|
||||
sptr<TestRemoteObject> testRemoteObject = new TestRemoteObject(std::u16string());
|
||||
ASSERT_FALSE(diag.NotifyFirstUseDialog(0, PASTE_COMPONENT, testRemoteObject));
|
||||
|
||||
// first use location button
|
||||
ASSERT_TRUE(diag.NotifyFirstUseDialog(0, LOCATION_COMPONENT, testRemoteObject));
|
||||
ASSERT_EQ(LOCATION_BUTTON_FIRST_USE, static_cast<uint64_t>(diag.firstUseMap_[0]));
|
||||
|
||||
// first use save button
|
||||
ASSERT_TRUE(diag.NotifyFirstUseDialog(0, SAVE_COMPONENT, testRemoteObject));
|
||||
ASSERT_EQ(LOCATION_BUTTON_FIRST_USE | SAVE_BUTTON_FIRST_USE, static_cast<uint64_t>(diag.firstUseMap_[0]));
|
||||
|
||||
// second use save button
|
||||
ASSERT_TRUE(diag.NotifyFirstUseDialog(0, SAVE_COMPONENT, testRemoteObject));
|
||||
ASSERT_EQ(LOCATION_BUTTON_FIRST_USE | SAVE_BUTTON_FIRST_USE, static_cast<uint64_t>(diag.firstUseMap_[0]));
|
||||
|
||||
diag.StartDialogAbility(PASTE_COMPONENT, nullptr);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SEC_COMP_FIRST_USE_DIALOG_TEST_H
|
||||
#define SEC_COMP_FIRST_USE_DIALOG_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#define private public
|
||||
#include "first_use_dialog.h"
|
||||
#undef private
|
||||
|
||||
namespace OHOS {
|
||||
namespace Security {
|
||||
namespace SecurityComponent {
|
||||
class FirstUseDialogTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
|
||||
static void TearDownTestCase();
|
||||
|
||||
void SetUp();
|
||||
|
||||
void TearDown();
|
||||
};
|
||||
} // namespace SecurityComponent
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
#endif // SEC_COMP_FIRST_USE_DIALOG_TEST_H
|
||||
@@ -24,7 +24,6 @@
|
||||
namespace OHOS {
|
||||
namespace Security {
|
||||
namespace SecurityComponent {
|
||||
|
||||
// stub is abstract class
|
||||
struct SecCompStubMock : public SecCompStub {
|
||||
public:
|
||||
|
||||
+1
-1
@@ -12,6 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "reduceafterverifysavepermissionInner_fuzzer.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@@ -20,7 +21,6 @@
|
||||
#include "accesstoken_kit.h"
|
||||
#include "securec.h"
|
||||
#include "token_setproc.h"
|
||||
#include "reduceafterverifysavepermissionInner_fuzzer.h"
|
||||
|
||||
using namespace OHOS::Security::SecurityComponent;
|
||||
using namespace OHOS::Security::AccessToken;
|
||||
|
||||
+1
-1
@@ -12,6 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "registersecuritycomponent_fuzzer.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@@ -20,7 +21,6 @@
|
||||
#include "accesstoken_kit.h"
|
||||
#include "securec.h"
|
||||
#include "token_setproc.h"
|
||||
#include "registersecuritycomponent_fuzzer.h"
|
||||
|
||||
using namespace OHOS::Security::SecurityComponent;
|
||||
using namespace OHOS::Security::AccessToken;
|
||||
|
||||
Reference in New Issue
Block a user