123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- // Copyright 2020 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "ash/in_session_auth/webauthn_dialog_controller_impl.h"
- #include "ash/in_session_auth/mock_in_session_auth_dialog_client.h"
- #include "ash/shell.h"
- #include "ash/test/ash_test_base.h"
- #include "base/callback.h"
- #include "base/test/bind.h"
- using ::testing::_;
- namespace ash {
- namespace {
- using WebAuthNDialogControllerImplTest = AshTestBase;
- TEST_F(WebAuthNDialogControllerImplTest, PinAuthSuccess) {
- WebAuthNDialogController* controller =
- Shell::Get()->webauthn_dialog_controller();
- auto client = std::make_unique<MockInSessionAuthDialogClient>();
- std::string pin = "123456";
- EXPECT_CALL(*client, AuthenticateUserWithPasswordOrPin(
- pin, /* authenticated_by_pin = */ true, _))
- .WillOnce([](const std::string& pin, bool authenticated_by_pin,
- base::OnceCallback<void(bool success)> controller_callback) {
- std::move(controller_callback).Run(true);
- });
- bool result_success = false;
- controller->AuthenticateUserWithPasswordOrPin(
- pin,
- /*authenticated_by_password=*/true,
- /* View callback will be executed during controller callback. */
- base::BindLambdaForTesting(
- [&result_success](bool success, bool can_use_pin) {
- result_success = success;
- }));
- EXPECT_TRUE(result_success);
- }
- TEST_F(WebAuthNDialogControllerImplTest, PinAuthFail) {
- WebAuthNDialogController* controller =
- Shell::Get()->webauthn_dialog_controller();
- auto client = std::make_unique<MockInSessionAuthDialogClient>();
- std::string pin = "123456";
- EXPECT_CALL(*client, AuthenticateUserWithPasswordOrPin(
- pin, /* authenticated_by_pin = */ true, _))
- .WillOnce([](const std::string& pin, bool authenticated_by_pin,
- base::OnceCallback<void(bool success)> controller_callback) {
- std::move(controller_callback).Run(false);
- });
- EXPECT_CALL(*client, CheckPinAuthAvailability(_, _))
- .WillOnce([](const AccountId& account_id,
- base::OnceCallback<void(bool success)> controller_callback) {
- std::move(controller_callback).Run(true);
- });
- bool result_success = false;
- bool result_can_use_pin = false;
- controller->AuthenticateUserWithPasswordOrPin(
- pin,
- /*authenticated_by_password=*/true,
- /* View callback will be executed during controller callback. */
- base::BindLambdaForTesting([&result_success, &result_can_use_pin](
- bool success, bool can_use_pin) {
- result_success = success;
- result_can_use_pin = can_use_pin;
- }));
- EXPECT_FALSE(result_success);
- EXPECT_TRUE(result_can_use_pin);
- }
- TEST_F(WebAuthNDialogControllerImplTest, PinAuthFailLockout) {
- WebAuthNDialogController* controller =
- Shell::Get()->webauthn_dialog_controller();
- auto client = std::make_unique<MockInSessionAuthDialogClient>();
- std::string pin = "123456";
- EXPECT_CALL(*client, AuthenticateUserWithPasswordOrPin(
- pin, /* authenticated_by_pin = */ true, _))
- .WillOnce([](const std::string& pin, bool authenticated_by_pin,
- base::OnceCallback<void(bool success)> controller_callback) {
- std::move(controller_callback).Run(false);
- });
- EXPECT_CALL(*client, CheckPinAuthAvailability(_, _))
- .WillOnce([](const AccountId& account_id,
- base::OnceCallback<void(bool success)> controller_callback) {
- std::move(controller_callback).Run(false);
- });
- bool result_success = false;
- bool result_can_use_pin = false;
- controller->AuthenticateUserWithPasswordOrPin(
- pin,
- /*authenticated_by_password=*/true,
- /* View callback will be executed during controller callback. */
- base::BindLambdaForTesting([&result_success, &result_can_use_pin](
- bool success, bool can_use_pin) {
- result_success = success;
- result_can_use_pin = can_use_pin;
- }));
- EXPECT_FALSE(result_success);
- EXPECT_FALSE(result_can_use_pin);
- }
- TEST_F(WebAuthNDialogControllerImplTest, PasswordAuthSuccess) {
- WebAuthNDialogController* controller =
- Shell::Get()->webauthn_dialog_controller();
- auto client = std::make_unique<MockInSessionAuthDialogClient>();
- std::string password = "abcdef";
- EXPECT_CALL(*client, AuthenticateUserWithPasswordOrPin(
- password, /* authenticated_by_pin = */ false, _))
- .WillOnce([](const std::string& password, bool authenticated_by_pin,
- base::OnceCallback<void(bool success)> controller_callback) {
- std::move(controller_callback).Run(true);
- });
- bool result_success = false;
- controller->AuthenticateUserWithPasswordOrPin(
- password,
- /*authenticated_by_password=*/false,
- /* View callback will be executed during controller callback. */
- base::BindLambdaForTesting(
- [&result_success](bool success, bool can_use_pin) {
- result_success = success;
- }));
- EXPECT_TRUE(result_success);
- }
- TEST_F(WebAuthNDialogControllerImplTest, PasswordAuthFail) {
- WebAuthNDialogController* controller =
- Shell::Get()->webauthn_dialog_controller();
- auto client = std::make_unique<MockInSessionAuthDialogClient>();
- std::string password = "abcdef";
- EXPECT_CALL(*client, AuthenticateUserWithPasswordOrPin(
- password, /* authenticated_by_pin = */ false, _))
- .WillOnce([](const std::string& password, bool authenticated_by_pin,
- base::OnceCallback<void(bool success)> controller_callback) {
- std::move(controller_callback).Run(false);
- });
- EXPECT_CALL(*client, CheckPinAuthAvailability(_, _))
- .WillOnce([](const AccountId& account_id,
- base::OnceCallback<void(bool success)> controller_callback) {
- std::move(controller_callback).Run(false);
- });
- bool result_success = false;
- controller->AuthenticateUserWithPasswordOrPin(
- password,
- /*authenticated_by_password=*/false,
- /* View callback will be executed during controller callback. */
- base::BindLambdaForTesting(
- [&result_success](bool success, bool can_use_pin) {
- result_success = success;
- }));
- EXPECT_FALSE(result_success);
- }
- } // namespace
- } // namespace ash
|