mirror of
https://gitee.com/openharmony/useriam_user_auth_framework
synced 2024-11-26 17:31:26 +00:00
fix: fix: ut coverage
Signed-off-by: 居凯 <shun0304@126.com> Change-Id: If304f59c9dac3544b737871f71824632198be970
This commit is contained in:
parent
295557ee1f
commit
3d4a0cc14d
@ -352,6 +352,34 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginAuthentication002, TestSize.Leve
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientImplBeginAuthentication001, TestSize.Level0)
|
||||
{
|
||||
std::optional<RemoteAuthParam> remoteAuthParam = {};
|
||||
RemoteAuthParam param = {};
|
||||
param.verifierNetworkId = "123";
|
||||
param.collectorNetworkId = "1233324321423412344134";
|
||||
remoteAuthParam = param;
|
||||
AuthParam testAuthParam = {
|
||||
.userId = 84548,
|
||||
.challenge = {1, 2, 3, 4, 8, 7, 5, 4},
|
||||
.authType = PIN,
|
||||
.authTrustLevel = ATL1,
|
||||
.remoteAuthParam = remoteAuthParam
|
||||
};
|
||||
std::shared_ptr<MockAuthenticationCallback> testCallback = nullptr;
|
||||
testCallback = Common::MakeShared<MockAuthenticationCallback>();
|
||||
uint64_t contextId = UserAuthClientImpl::GetInstance().BeginAuthentication(testAuthParam, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientImplPrepareRemoteAuth, TestSize.Level0)
|
||||
{
|
||||
const std::string networkId = "123";
|
||||
std::shared_ptr<PrepareRemoteAuthCallback> testCallback = nullptr;
|
||||
uint64_t contextId = UserAuthClientImpl::GetInstance().PrepareRemoteAuth(networkId, testCallback);
|
||||
EXPECT_EQ(contextId, 2);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientCancelAuthentication001, TestSize.Level0)
|
||||
{
|
||||
uint64_t testContextId = 12345562;
|
||||
@ -798,6 +826,15 @@ HWTEST_F(UserAuthClientTest, UserAuthClientSetGlobalConfigParam002, TestSize.Lev
|
||||
dr->OnRemoteDied(obj);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientGetNorthAvailableStatus, TestSize.Level0)
|
||||
{
|
||||
AuthType testAuthType = FACE;
|
||||
int32_t testApiVersion = 0;
|
||||
AuthTrustLevel testAtl = ATL1;
|
||||
int32_t ret = UserAuthClientImpl::Instance().GetNorthAvailableStatus(testApiVersion, testAuthType, testAtl);
|
||||
EXPECT_EQ(ret, GENERAL_ERROR);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "iam_ptr.h"
|
||||
#include "user_idm_client.h"
|
||||
#include "user_idm_client_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
@ -516,6 +517,14 @@ HWTEST_F(UserIdmClientTest, UserIdmClientGetSecUserInfo002, TestSize.Level0)
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientImplClearRedundancyCredential, TestSize.Level0)
|
||||
{
|
||||
std::shared_ptr<MockUserIdmClientCallback> testCallback = nullptr;
|
||||
testCallback = Common::MakeShared<MockUserIdmClientCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_NO_THROW(UserIdmClient::GetInstance().ClearRedundancyCredential(testCallback));
|
||||
}
|
||||
|
||||
void UserIdmClientTest::CallRemoteObject(const std::shared_ptr<MockUserIdmService> service,
|
||||
const sptr<MockRemoteObject> &obj, sptr<IRemoteObject::DeathRecipient> &dr)
|
||||
{
|
||||
|
@ -120,6 +120,7 @@ ohos_unittest("iam_services_test") {
|
||||
"mocks/mock_ipc_common.cpp",
|
||||
"mocks/mock_iuser_auth_interface.cpp",
|
||||
"src/attributes_test.cpp",
|
||||
"src/auth_event_listener_manager_test.cpp",
|
||||
"src/auth_widget_helper_test.cpp",
|
||||
"src/authentication_impl_test.cpp",
|
||||
"src/co_auth_service_test.cpp",
|
||||
@ -145,6 +146,7 @@ ohos_unittest("iam_services_test") {
|
||||
"src/secure_user_info_test.cpp",
|
||||
"src/simple_auth_context_test.cpp",
|
||||
"src/state_machine_test.cpp",
|
||||
"src/template_cache_manager_test.cpp",
|
||||
"src/ui_extension_ability_connection_test.cpp",
|
||||
"src/update_pin_param_test.cpp",
|
||||
"src/user_auth_service_test_part01.cpp",
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 AUTH_EVENT_LISTENER_MANAGER_TEST
|
||||
#define AUTH_EVENT_LISTENER_MANAGER_TEST
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class AuthEventListenerManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
|
||||
static void TearDownTestCase();
|
||||
|
||||
void SetUp() override;
|
||||
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // AUTH_EVENT_LISTENER_MANAGER_TEST
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 "auth_event_listener_manager_test.h"
|
||||
#include "auth_event_listener_manager.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "mock_auth_event_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
void AuthEventListenerManagerTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void AuthEventListenerManagerTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void AuthEventListenerManagerTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void AuthEventListenerManagerTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(AuthEventListenerManagerTest, AuthEventListenerManagerTestAddAuthSuccessEventListener, TestSize.Level0)
|
||||
{
|
||||
sptr<AuthEventListenerInterface> testCallback = new MockAuthEventListener();
|
||||
AuthType authType = AuthType::PIN;
|
||||
EXPECT_NO_THROW(AuthEventListenerManager::GetInstance().AddAuthSuccessEventListener(authType, testCallback));
|
||||
}
|
||||
|
||||
HWTEST_F(AuthEventListenerManagerTest, AuthEventListenerManagerTestRemoveAuthSuccessEventListener, TestSize.Level0)
|
||||
{
|
||||
sptr<AuthEventListenerInterface> testCallback = new MockAuthEventListener();
|
||||
AuthType authType = AuthType::PIN;
|
||||
EXPECT_NO_THROW(AuthEventListenerManager::GetInstance().RemoveAuthSuccessEventListener(authType, testCallback));
|
||||
}
|
||||
|
||||
HWTEST_F(AuthEventListenerManagerTest, AuthEventListenerManagerTestRemoveDeathRecipient, TestSize.Level0)
|
||||
{
|
||||
sptr<AuthEventListenerInterface> testCallback = new MockAuthEventListener();
|
||||
EXPECT_NO_THROW(AuthEventListenerManager::GetInstance().RemoveDeathRecipient(testCallback));
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
@ -293,6 +293,21 @@ HWTEST_F(AuthenticationImplTest, AuthenticationImplTestStart, TestSize.Level0)
|
||||
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex));
|
||||
}
|
||||
|
||||
HWTEST_F(AuthenticationImplTest, AuthenticationImplTestSetLatestError, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 1234;
|
||||
Authentication::AuthenticationPara para = {};
|
||||
para.userId = 0x11;
|
||||
para.callerName = "com.ohos.test";
|
||||
para.sdkVersion = 11;
|
||||
para.authType = FACE;
|
||||
para.atl = ATL3;
|
||||
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, para);
|
||||
ASSERT_NE(authentication, nullptr);
|
||||
authentication->SetLatestError(0);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
@ -96,6 +96,81 @@ HWTEST_F(ScheduleNodeHelperTest, ScheduleNodeHelperTest_002, TestSize.Level0)
|
||||
ResourceNodePool::Instance().DeleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST_F(ScheduleNodeHelperTest, ScheduleNodeHelperTestScheduleInfoToExecutors_001, TestSize.Level0)
|
||||
{
|
||||
HdiScheduleInfo scheduleInfo = {};
|
||||
scheduleInfo.authType = HdiAuthType::FACE;
|
||||
scheduleInfo.executorMatcher = 10;
|
||||
scheduleInfo.executorIndexes.push_back(60);
|
||||
scheduleInfo.executorMessages.push_back({6});
|
||||
scheduleInfo.scheduleId = 20;
|
||||
scheduleInfo.scheduleMode = HdiScheduleMode::AUTH;
|
||||
scheduleInfo.templateIds.push_back(30);
|
||||
std::vector<ExecutorRole> executorRole = {SCHEDULER, COLLECTOR, VERIFIER, ALL_IN_ONE};
|
||||
auto resourceNode1 = MockResourceNode::CreateWithExecuteIndex(60, FACE, executorRole[0]);
|
||||
EXPECT_NE(resourceNode1, nullptr);
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode1));
|
||||
std::shared_ptr<ResourceNode> collector;
|
||||
std::shared_ptr<ResourceNode> verifier;
|
||||
std::vector<uint8_t> collectorMessage;
|
||||
std::vector<uint8_t> verifierMessage;
|
||||
auto callback = Common::MakeShared<MockScheduleNodeCallback>();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_FALSE(ScheduleNodeHelper::ScheduleInfoToExecutors(scheduleInfo, collector, verifier, collectorMessage,
|
||||
verifierMessage));
|
||||
ResourceNodePool::Instance().DeleteAll();
|
||||
}
|
||||
|
||||
HWTEST_F(ScheduleNodeHelperTest, ScheduleNodeHelperTestScheduleInfoToExecutors_002, TestSize.Level0)
|
||||
{
|
||||
HdiScheduleInfo scheduleInfo = {};
|
||||
scheduleInfo.authType = HdiAuthType::FACE;
|
||||
scheduleInfo.executorMatcher = 10;
|
||||
scheduleInfo.executorIndexes.push_back(60);
|
||||
scheduleInfo.executorMessages.push_back({6});
|
||||
scheduleInfo.scheduleId = 20;
|
||||
scheduleInfo.scheduleMode = HdiScheduleMode::AUTH;
|
||||
scheduleInfo.templateIds.push_back(30);
|
||||
std::vector<ExecutorRole> executorRole = {SCHEDULER, COLLECTOR, VERIFIER, ALL_IN_ONE};
|
||||
auto resourceNode1 = MockResourceNode::CreateWithExecuteIndex(60, FACE, executorRole[1]);
|
||||
EXPECT_NE(resourceNode1, nullptr);
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode1));
|
||||
std::shared_ptr<ResourceNode> collector;
|
||||
std::shared_ptr<ResourceNode> verifier;
|
||||
std::vector<uint8_t> collectorMessage;
|
||||
std::vector<uint8_t> verifierMessage;
|
||||
auto callback = Common::MakeShared<MockScheduleNodeCallback>();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_FALSE(ScheduleNodeHelper::ScheduleInfoToExecutors(scheduleInfo, collector, verifier, collectorMessage,
|
||||
verifierMessage));
|
||||
ResourceNodePool::Instance().DeleteAll();
|
||||
}
|
||||
|
||||
HWTEST_F(ScheduleNodeHelperTest, ScheduleNodeHelperTestScheduleInfoToExecutors_003, TestSize.Level0)
|
||||
{
|
||||
HdiScheduleInfo scheduleInfo = {};
|
||||
scheduleInfo.authType = HdiAuthType::FACE;
|
||||
scheduleInfo.executorMatcher = 10;
|
||||
scheduleInfo.executorIndexes.push_back(60);
|
||||
scheduleInfo.executorMessages.push_back({6});
|
||||
scheduleInfo.scheduleId = 20;
|
||||
scheduleInfo.scheduleMode = HdiScheduleMode::AUTH;
|
||||
scheduleInfo.templateIds.push_back(30);
|
||||
std::vector<ExecutorRole> executorRole = {SCHEDULER, COLLECTOR, VERIFIER, ALL_IN_ONE};
|
||||
auto resourceNode1 = MockResourceNode::CreateWithExecuteIndex(60, FACE, executorRole[2]);
|
||||
EXPECT_NE(resourceNode1, nullptr);
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode1));
|
||||
std::shared_ptr<ResourceNode> collector;
|
||||
std::shared_ptr<ResourceNode> verifier;
|
||||
std::vector<uint8_t> collectorMessage;
|
||||
std::vector<uint8_t> verifierMessage;
|
||||
auto callback = Common::MakeShared<MockScheduleNodeCallback>();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_FALSE(ScheduleNodeHelper::ScheduleInfoToExecutors(scheduleInfo, collector, verifier, collectorMessage,
|
||||
verifierMessage));
|
||||
ResourceNodePool::Instance().DeleteAll();
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
|
@ -422,6 +422,89 @@ HWTEST_F(WidgetClientTest, WidgetClientTestSetPinSubType, TestSize.Level0)
|
||||
WidgetClient::Instance().SetPinSubType((PinSubType)123);
|
||||
EXPECT_EQ(WidgetClient::Instance().GetAuthTokenId(), 0);
|
||||
}
|
||||
|
||||
HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_001, TestSize.Level0)
|
||||
{
|
||||
WidgetNotice widgetNotice;
|
||||
widgetNotice.widgetContextId = 1;
|
||||
widgetNotice.event = NOTICE_EVENT_WIDGET_PARA_INVALID;
|
||||
widgetNotice.typeList.push_back("pin");
|
||||
WidgetClient::Instance().Reset();
|
||||
std::vector<AuthType> authTypeList;
|
||||
authTypeList.emplace_back(AuthType::PIN);
|
||||
WidgetClient::Instance().SetAuthTypeList(authTypeList);
|
||||
WidgetClient::Instance().SetWidgetSchedule(BuildSchedule());
|
||||
EXPECT_NO_THROW(WidgetClient::Instance().ProcessNotice(widgetNotice, authTypeList));
|
||||
}
|
||||
|
||||
HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_002, TestSize.Level0)
|
||||
{
|
||||
WidgetNotice widgetNotice;
|
||||
widgetNotice.widgetContextId = 1;
|
||||
widgetNotice.event = NOTICE_EVENT_END;
|
||||
widgetNotice.typeList.push_back("pin");
|
||||
WidgetClient::Instance().Reset();
|
||||
std::vector<AuthType> authTypeList;
|
||||
authTypeList.emplace_back(AuthType::PIN);
|
||||
WidgetClient::Instance().SetAuthTypeList(authTypeList);
|
||||
WidgetClient::Instance().SetWidgetSchedule(BuildSchedule());
|
||||
EXPECT_NO_THROW(WidgetClient::Instance().ProcessNotice(widgetNotice, authTypeList));
|
||||
}
|
||||
|
||||
HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_003, TestSize.Level0)
|
||||
{
|
||||
WidgetNotice widgetNotice;
|
||||
widgetNotice.widgetContextId = 1;
|
||||
widgetNotice.event = NOTICE_EVENT_RELOAD;
|
||||
widgetNotice.typeList.push_back("pin");
|
||||
WidgetClient::Instance().Reset();
|
||||
std::vector<AuthType> authTypeList;
|
||||
authTypeList.emplace_back(AuthType::PIN);
|
||||
WidgetClient::Instance().SetAuthTypeList(authTypeList);
|
||||
WidgetClient::Instance().SetWidgetSchedule(BuildSchedule());
|
||||
EXPECT_NO_THROW(WidgetClient::Instance().ProcessNotice(widgetNotice, authTypeList));
|
||||
}
|
||||
|
||||
HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_004, TestSize.Level0)
|
||||
{
|
||||
WidgetNotice widgetNotice;
|
||||
widgetNotice.widgetContextId = 1;
|
||||
widgetNotice.event = NOTICE_EVENT_RELOAD;
|
||||
widgetNotice.typeList.push_back("pin");
|
||||
WidgetClient::Instance().Reset();
|
||||
std::vector<AuthType> authTypeList;
|
||||
authTypeList.emplace_back(AuthType::ALL);
|
||||
WidgetClient::Instance().SetAuthTypeList(authTypeList);
|
||||
WidgetClient::Instance().SetWidgetSchedule(BuildSchedule());
|
||||
EXPECT_NO_THROW(WidgetClient::Instance().ProcessNotice(widgetNotice, authTypeList));
|
||||
}
|
||||
|
||||
HWTEST_F(WidgetClientTest, WidgetClientTestProcessNotice_005, TestSize.Level0)
|
||||
{
|
||||
WidgetNotice widgetNotice;
|
||||
widgetNotice.widgetContextId = 1;
|
||||
widgetNotice.event = NOTICE_EVENT_RELOAD;
|
||||
widgetNotice.typeList.push_back("pin");
|
||||
WidgetClient::Instance().Reset();
|
||||
std::vector<AuthType> authTypeList;
|
||||
authTypeList.emplace_back(AuthType::ALL);
|
||||
authTypeList.emplace_back(AuthType::PIN);
|
||||
WidgetClient::Instance().SetAuthTypeList(authTypeList);
|
||||
WidgetClient::Instance().SetWidgetSchedule(BuildSchedule());
|
||||
EXPECT_NO_THROW(WidgetClient::Instance().ProcessNotice(widgetNotice, authTypeList));
|
||||
}
|
||||
|
||||
HWTEST_F(WidgetClientTest, WidgetClientTestSetPinSubType_001, TestSize.Level0)
|
||||
{
|
||||
WidgetClient::Instance().Reset();
|
||||
EXPECT_NO_THROW(WidgetClient::Instance().SetPinSubType(PinSubType::PIN_FOUR));
|
||||
}
|
||||
|
||||
HWTEST_F(WidgetClientTest, WidgetClientTestSetPinSubType_002, TestSize.Level0)
|
||||
{
|
||||
WidgetClient::Instance().Reset();
|
||||
EXPECT_NO_THROW(WidgetClient::Instance().SetPinSubType(PinSubType::PIN_PATTERN));
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user