mirror of
https://gitee.com/openharmony/account_os_account
synced 2024-11-30 05:30:55 +00:00
add auth param testcase
Signed-off-by: bigtea <tianqushen@huawei.com>
This commit is contained in:
parent
84ac0704a0
commit
ae07895a98
@ -277,7 +277,7 @@ int32_t AccountIAMMgrProxy::PrepareRemoteAuth(
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
ACCOUNT_LOGE("Prepare remote auth callback is nullptr.");
|
||||
return ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR;
|
||||
return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
|
@ -89,6 +89,17 @@ public:
|
||||
};
|
||||
#endif
|
||||
|
||||
class MockPreRemoteAuthCallback final : public AccountSA::PreRemoteAuthCallback {
|
||||
public:
|
||||
void OnResult(int32_t result) override
|
||||
{
|
||||
result_ = result;
|
||||
}
|
||||
|
||||
public:
|
||||
int32_t result_ = -1;
|
||||
};
|
||||
|
||||
class AccountIAMClientNoPermissionTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
@ -323,5 +334,19 @@ HWTEST_F(AccountIAMClientNoPermissionTest, AccountIAMClientNoPermission_CancelAu
|
||||
int32_t res = AccountIAMClient::GetInstance().CancelAuth(TEST_CONTEXT_ID);
|
||||
EXPECT_EQ(res, ERR_ACCOUNT_COMMON_PERMISSION_DENIED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountIAMClientNoPermission_prepareRemoteAuth_0100
|
||||
* @tc.desc: prepare remote authentication without permission.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AccountIAMClientNoPermissionTest, AccountIAMClientNoPermission_prepareRemoteAuth_0100, TestSize.Level0)
|
||||
{
|
||||
auto callback = std::make_shared<MockPreRemoteAuthCallback>();
|
||||
ASSERT_NE(callback, nullptr);
|
||||
int32_t res = AccountIAMClient::GetInstance().PrepareRemoteAuth("testString", callback);
|
||||
EXPECT_EQ(res, ERR_ACCOUNT_COMMON_PERMISSION_DENIED);
|
||||
}
|
||||
} // namespace AccountTest
|
||||
} // namespace OHOS
|
@ -1090,5 +1090,75 @@ HWTEST_F(AccountIAMClientTest, ResetAccountIAMProxy001, TestSize.Level0)
|
||||
EXPECT_NE(AccountIAMClient::GetInstance().proxy_, nullptr);
|
||||
AccountIAMClient::GetInstance().ResetAccountIAMProxy(remote);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PrepareRemoteAuthTest001
|
||||
* @tc.desc: test PrepareRemoteAuth.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AccountIAMClientTest, PrepareRemoteAuthTest001, TestSize.Level0)
|
||||
{
|
||||
int32_t ret = AccountIAMClient::GetInstance().PrepareRemoteAuth("testString", nullptr);
|
||||
EXPECT_EQ(ret, ERR_ACCOUNT_COMMON_NULL_PTR_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountIAMClient_AuthUser_0300
|
||||
* @tc.desc: Auth user.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AccountIAMClientTest, AccountIAMClient_AuthUser_0300, TestSize.Level0)
|
||||
{
|
||||
SetPropertyRequest testRequest = {};
|
||||
auto callback = std::make_shared<MockIDMCallback>();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_CALL(*callback, OnResult(_, _)).Times(Exactly(1));
|
||||
auto testCallback = std::make_shared<TestIDMCallback>(callback);
|
||||
AuthOptions authOptions;
|
||||
|
||||
authOptions.hasRemoteAuthOptions = true;
|
||||
|
||||
AccountIAMClient::GetInstance().AuthUser(
|
||||
authOptions, TEST_CHALLENGE, AuthType::PIN, AuthTrustLevel::ATL1, testCallback);
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(testCallback->mutex);
|
||||
testCallback->cv.wait_for(
|
||||
lock, std::chrono::seconds(WAIT_TIME), [lockCallback = testCallback]() { return lockCallback->isReady; });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountIAMClient_AuthUser_0400
|
||||
* @tc.desc: Auth user.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AccountIAMClientTest, AccountIAMClient_AuthUser_0400, TestSize.Level0)
|
||||
{
|
||||
SetPropertyRequest testRequest = {};
|
||||
auto callback = std::make_shared<MockIDMCallback>();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_CALL(*callback, OnResult(_, _)).Times(Exactly(1));
|
||||
auto testCallback = std::make_shared<TestIDMCallback>(callback);
|
||||
AuthOptions authOptions;
|
||||
|
||||
authOptions.hasRemoteAuthOptions = true;
|
||||
authOptions.remoteAuthOptions.hasVerifierNetworkId = true;
|
||||
authOptions.remoteAuthOptions.verifierNetworkId = "testVerifierNetworkId";
|
||||
authOptions.remoteAuthOptions.hasCollectorNetworkId = true;
|
||||
authOptions.remoteAuthOptions.collectorNetworkId = "testCollectorNetworkId";
|
||||
authOptions.remoteAuthOptions.hasCollectorTokenId = true;
|
||||
authOptions.remoteAuthOptions.collectorTokenId = 0;
|
||||
|
||||
AccountIAMClient::GetInstance().AuthUser(
|
||||
authOptions, TEST_CHALLENGE, AuthType::PIN, AuthTrustLevel::ATL1, testCallback);
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(testCallback->mutex);
|
||||
testCallback->cv.wait_for(
|
||||
lock, std::chrono::seconds(WAIT_TIME), [lockCallback = testCallback]() { return lockCallback->isReady; });
|
||||
}
|
||||
}
|
||||
} // namespace AccountTest
|
||||
} // namespace OHOS
|
@ -106,6 +106,9 @@ HWTEST_F(AccountIAMMgrProxyTest, AccountIAMMgrProxy001, TestSize.Level0)
|
||||
EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER, ret);
|
||||
ret = accountIAMMgrProxy->AuthUser(authParam, nullptr, contextId);
|
||||
EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER, ret);
|
||||
|
||||
ret = accountIAMMgrProxy->PrepareRemoteAuth("testString", nullptr);
|
||||
EXPECT_EQ(ERR_ACCOUNT_COMMON_INVALID_PARAMETER, ret);
|
||||
}
|
||||
} // namespace AccountTest
|
||||
} // namespace OHOS
|
@ -76,6 +76,15 @@ public:
|
||||
int32_t result_;
|
||||
};
|
||||
|
||||
class PreRemoteAuthCallbackMockTest final : public AccountSA::PreRemoteAuthCallback {
|
||||
public:
|
||||
void OnResult(int32_t result) override
|
||||
{
|
||||
result_ = result;
|
||||
}
|
||||
int32_t result_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: AccountIAMClient_OpenSession_0100
|
||||
* @tc.desc: Test func with proxy is nullptr.
|
||||
@ -264,5 +273,19 @@ HWTEST_F(AccountIAMProxyMockTest, AccountIAMClient_GetAccountState_0100, TestSiz
|
||||
{
|
||||
EXPECT_EQ(IDLE, AccountIAMClient::GetInstance().GetAccountState(TEST_USER_ID));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountIAMClient_PrepareRemoteAuth_0100
|
||||
* @tc.desc: Test func PrepareRemoteAuth.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AccountIAMProxyMockTest, AccountIAMClient_PrepareRemoteAuth_0100, TestSize.Level0)
|
||||
{
|
||||
auto testCallback = std::make_shared<PreRemoteAuthCallbackMockTest>();
|
||||
ASSERT_NE(testCallback, nullptr);
|
||||
AccountIAMClient::GetInstance().PrepareRemoteAuth("testString", testCallback);
|
||||
EXPECT_NE(testCallback->result_, 0);
|
||||
}
|
||||
} // namespace AccountTest
|
||||
} // namespace OHOS
|
@ -415,6 +415,25 @@ public:
|
||||
uint32_t acquireInfo_ = 0;
|
||||
};
|
||||
|
||||
class MockPreRemoteAuthCallback : public PreRemoteAuthCallbackStub {
|
||||
public:
|
||||
MOCK_METHOD1(OnResult, void(int32_t result));
|
||||
};
|
||||
|
||||
class TestPreRemoteAuthCallback : public PreRemoteAuthCallbackStub {
|
||||
public:
|
||||
explicit TestPreRemoteAuthCallback(const std::shared_ptr<MockPreRemoteAuthCallback> &callback) : callback_(callback)
|
||||
{}
|
||||
void OnResult(int32_t result)
|
||||
{
|
||||
callback_->OnResult(result);
|
||||
return;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<MockPreRemoteAuthCallback> callback_;
|
||||
};
|
||||
|
||||
class AccountIamManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
@ -818,5 +837,24 @@ HWTEST_F(AccountIamManagerTest, UpdateCredCallback_OnResult_0002, TestSize.Level
|
||||
commitUpdateCredCallback->OnResult(1, extraInfo);
|
||||
innerIamMgr_.storageMgrProxy_ = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PrepareRemoteAuth001
|
||||
* @tc.desc: PrepareRemoteAuth.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AccountIamManagerTest, PrepareRemoteAuth001, TestSize.Level0)
|
||||
{
|
||||
ErrCode errCode = InnerAccountIAMManager::GetInstance().PrepareRemoteAuth("testString", nullptr);
|
||||
EXPECT_EQ(ERR_ACCOUNT_COMMON_NULL_PTR_ERROR, errCode);
|
||||
|
||||
std::shared_ptr<MockPreRemoteAuthCallback> callback = std::make_shared<MockPreRemoteAuthCallback>();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
sptr<TestPreRemoteAuthCallback> testCallback = new(std::nothrow) TestPreRemoteAuthCallback(callback);
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
|
||||
InnerAccountIAMManager::GetInstance().PrepareRemoteAuth("testString", testCallback);
|
||||
}
|
||||
} // namespace AccountTest
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user