Commit f0a41559 authored by Maksim Ivanov's avatar Maksim Ivanov Committed by Commit Bot

Test Ash smart card login wrong PIN failure

Provide test coverage for the scenario when the PIN dialog, triggered
during the challenge-response login (a.k.a. smart card based login),
first receives a wrong PIN and only then the correct one.

Also verify the PIN dialog title in the test for the successful
scenario.

Bug: 1033936
Change-Id: I1813f75b11f1662555271fac2e7aee84cf19dbd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2316865Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarFabian Sommer <fabiansommer@chromium.org>
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792219}
parent c3afda98
......@@ -705,6 +705,17 @@ void LoginScreenTestApi::SetPinRequestWidgetShownCallback(
PinRequestWidget::SetShownCallbackForTesting(on_pin_request_widget_shown);
}
// static
base::string16 LoginScreenTestApi::GetPinRequestWidgetTitle() {
if (!PinRequestWidget::Get()) {
ADD_FAILURE() << "No PIN request widget is shown";
return base::string16();
}
PinRequestWidget::TestApi pin_widget_test(PinRequestWidget::Get());
PinRequestView::TestApi pin_view_test(pin_widget_test.pin_request_view());
return pin_view_test.title_label()->GetText();
}
// static
void LoginScreenTestApi::SubmitPinRequestWidget(const std::string& pin) {
if (!PinRequestWidget::Get())
......
......@@ -85,6 +85,7 @@ class ASH_PUBLIC_EXPORT LoginScreenTestApi {
static void SetPinRequestWidgetShownCallback(
base::RepeatingClosure on_pin_request_widget_shown);
static base::string16 GetPinRequestWidgetTitle();
static void SubmitPinRequestWidget(const std::string& pin);
static void CancelPinRequestWidget();
......
......@@ -25,6 +25,7 @@
#include "chrome/browser/chromeos/login/existing_user_controller.h"
#include "chrome/browser/chromeos/login/test/device_state_mixin.h"
#include "chrome/browser/chromeos/login/test/login_manager_mixin.h"
#include "chrome/browser/chromeos/login/test/test_predicate_waiter.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h"
......@@ -55,11 +56,14 @@ namespace {
// The PIN code that the test certificate provider extension is configured to
// expect.
constexpr char kCorrectPin[] = "17093";
constexpr char kWrongPin[] = "1234";
// UI golden strings in the en-US locale:
constexpr char kChallengeResponseLoginLabel[] = "Sign in with smart card";
constexpr char kChallengeResponseErrorLabel[] =
"Couldn’t recognize your smart card. Try again.";
constexpr char kPinDialogDefaultTitle[] = "Smart card PIN";
constexpr char kPinDialogInvalidPinTitle[] = "Invalid PIN.";
constexpr char kChallengeData[] = "challenge";
......@@ -214,6 +218,16 @@ class SecurityTokenLoginTest : public MixinBasedInProcessBrowserTest,
pin_dialog_waiting_run_loop.Run();
}
void WaitForPinDialogTitle(const std::string& awaited_title) {
test::TestPredicateWaiter waiter(base::BindRepeating(
[](const std::string& awaited_title) {
return LoginScreenTestApi::GetPinRequestWidgetTitle() ==
base::UTF8ToUTF16(awaited_title);
},
awaited_title));
waiter.Wait();
}
void WaitForActiveSession() { login_manager_mixin_.WaitForActiveSession(); }
private:
......@@ -272,6 +286,8 @@ IN_PROC_BROWSER_TEST_F(SecurityTokenLoginTest, Basic) {
// certificate provider extension receives this request and requests the PIN
// dialog.
StartLoginAndWaitForPinDialog();
EXPECT_EQ(LoginScreenTestApi::GetPinRequestWidgetTitle(),
base::UTF8ToUTF16(kPinDialogDefaultTitle));
// The PIN is entered.
LoginScreenTestApi::SubmitPinRequestWidget(kCorrectPin);
......@@ -300,6 +316,20 @@ IN_PROC_BROWSER_TEST_F(SecurityTokenLoginTest, PinCancel) {
base::UTF8ToUTF16(kChallengeResponseLoginLabel));
}
// Test the successful login scenario when the correct PIN was entered only on
// the second attempt.
IN_PROC_BROWSER_TEST_F(SecurityTokenLoginTest, WrongPinThenCorrect) {
StartLoginAndWaitForPinDialog();
// A wrong PIN is entered, and an error is shown in the PIN dialog.
LoginScreenTestApi::SubmitPinRequestWidget(kWrongPin);
WaitForPinDialogTitle(kPinDialogInvalidPinTitle);
// The correct PIN is entered, and the login succeeds.
LoginScreenTestApi::SubmitPinRequestWidget(kCorrectPin);
WaitForActiveSession();
}
// Test the login failure scenario when the extension fails to sign the
// challenge.
IN_PROC_BROWSER_TEST_F(SecurityTokenLoginTest, SigningFailure) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment