Commit 52a83118 authored by Maksim Ivanov's avatar Maksim Ivanov Committed by Commit Bot

Introduce ScopedTestSystemNSSKeySlotMixin

Add a test mixin for the ScopedTestSystemNSSKeySlot class, in order to
simplify its usage in browser tests.

This mixin is used in the WebviewClientCertsLoginTest tests, and will
also be used in the future tests of the Chrome OS smart card user login.

Bug: 1033936
Change-Id: If8f6b578b4dceb9805cc431fd5803f79c2a1d388
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1967246
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarAchuith Bhandarkar <achuith@chromium.org>
Reviewed-by: default avatarPavol Marko <pmarko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727872}
parent 570f192d
......@@ -38,6 +38,7 @@
#include "chrome/browser/chromeos/policy/device_policy_builder.h"
#include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/scoped_test_system_nss_key_slot_mixin.h"
#include "chrome/browser/chromeos/settings/scoped_testing_cros_settings.h"
#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
#include "chrome/browser/ui/login/login_handler.h"
......@@ -69,7 +70,6 @@
#include "crypto/nss_util.h"
#include "crypto/nss_util_internal.h"
#include "crypto/scoped_test_nss_db.h"
#include "crypto/scoped_test_system_nss_key_slot.h"
#include "media/base/media_switches.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/cookies/canonical_cookie.h"
......@@ -603,49 +603,13 @@ class WebviewClientCertsLoginTest : public WebviewClientCertsLoginTestBase {
public:
WebviewClientCertsLoginTest() = default;
// Installs a testing system slot and imports a client certificate into it.
void SetUpClientCertInSystemSlot() {
bool system_slot_constructed_successfully = false;
base::RunLoop loop;
base::PostTaskAndReply(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&WebviewClientCertsLoginTest::SetUpTestSystemSlotOnIO,
base::Unretained(this),
&system_slot_constructed_successfully),
loop.QuitClosure());
loop.Run();
ASSERT_TRUE(system_slot_constructed_successfully);
ASSERT_TRUE(ImportSystemSlotClientCert(test_system_slot_->slot()));
}
protected:
void TearDownOnMainThread() override {
TearDownTestSystemSlot();
WebviewClientCertsLoginTestBase::TearDownOnMainThread();
// Imports a client certificate into the system slot.
bool SetUpClientCertInSystemSlot() {
return ImportSystemSlotClientCert(system_nss_key_slot_mixin_.slot());
}
private:
void SetUpTestSystemSlotOnIO(bool* out_system_slot_constructed_successfully) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
test_system_slot_ = std::make_unique<crypto::ScopedTestSystemNSSKeySlot>();
*out_system_slot_constructed_successfully =
test_system_slot_->ConstructedSuccessfully();
}
void TearDownTestSystemSlot() {
base::RunLoop loop;
base::PostTaskAndReply(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&WebviewClientCertsLoginTest::TearDownTestSystemSlotOnIO,
base::Unretained(this)),
loop.QuitClosure());
loop.Run();
}
void TearDownTestSystemSlotOnIO() { test_system_slot_.reset(); }
std::unique_ptr<crypto::ScopedTestSystemNSSKeySlot> test_system_slot_;
ScopedTestSystemNSSKeySlotMixin system_nss_key_slot_mixin_{&mixin_host_};
DISALLOW_COPY_AND_ASSIGN(WebviewClientCertsLoginTest);
};
......@@ -658,7 +622,7 @@ class WebviewClientCertsLoginTest : public WebviewClientCertsLoginTestBase {
// ASAN/LSAN. crbug.com/1022034
IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
DISABLED_SigninFrameNoAuthorityGiven) {
ASSERT_NO_FATAL_FAILURE(SetUpClientCertInSystemSlot());
ASSERT_TRUE(SetUpClientCertInSystemSlot());
net::SpawnedTestServer::SSLOptions ssl_options;
ssl_options.request_client_certificate = true;
ASSERT_NO_FATAL_FAILURE(StartHttpsServer(ssl_options));
......@@ -684,7 +648,7 @@ IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
// ASAN/LSAN. crbug.com/1022034
IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
DISABLED_SigninFrameCertMultipleFiltersAutoSelected) {
ASSERT_NO_FATAL_FAILURE(SetUpClientCertInSystemSlot());
ASSERT_TRUE(SetUpClientCertInSystemSlot());
net::SpawnedTestServer::SSLOptions ssl_options;
ssl_options.request_client_certificate = true;
ASSERT_NO_FATAL_FAILURE(StartHttpsServer(ssl_options));
......@@ -711,7 +675,7 @@ IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
// ASAN/LSAN. crbug.com/1022034
IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
DISABLED_SigninFrameCertNotAutoSelected) {
ASSERT_NO_FATAL_FAILURE(SetUpClientCertInSystemSlot());
ASSERT_TRUE(SetUpClientCertInSystemSlot());
net::SpawnedTestServer::SSLOptions ssl_options;
ssl_options.request_client_certificate = true;
ASSERT_NO_FATAL_FAILURE(StartHttpsServer(ssl_options));
......@@ -732,7 +696,7 @@ IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
// ASAN/LSAN. crbug.com/1022034
IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
DISABLED_SigninFrameAuthorityGiven) {
ASSERT_NO_FATAL_FAILURE(SetUpClientCertInSystemSlot());
ASSERT_TRUE(SetUpClientCertInSystemSlot());
net::SpawnedTestServer::SSLOptions ssl_options;
ssl_options.request_client_certificate = true;
base::FilePath ca_path =
......@@ -763,7 +727,7 @@ IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
// ASAN/LSAN. crbug.com/1022034
IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
DISABLED_SigninFrameAuthorityGivenNoMatchingCert) {
ASSERT_NO_FATAL_FAILURE(SetUpClientCertInSystemSlot());
ASSERT_TRUE(SetUpClientCertInSystemSlot());
net::SpawnedTestServer::SSLOptions ssl_options;
ssl_options.request_client_certificate = true;
base::FilePath ca_path =
......@@ -790,7 +754,7 @@ IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
// TODO(crbug.com/949511) The test is flaky (timeout) on MSAN.
IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
DISABLED_SigninFrameIntermediateAuthorityUnknown) {
ASSERT_NO_FATAL_FAILURE(SetUpClientCertInSystemSlot());
ASSERT_TRUE(SetUpClientCertInSystemSlot());
net::SpawnedTestServer::SSLOptions ssl_options;
ssl_options.request_client_certificate = true;
base::FilePath ca_path = net::GetTestCertsDirectory().Append(
......@@ -818,7 +782,7 @@ IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
// ASAN/LSAN. crbug.com/1022034
IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
DISABLED_SigninFrameIntermediateAuthorityKnown) {
ASSERT_NO_FATAL_FAILURE(SetUpClientCertInSystemSlot());
ASSERT_TRUE(SetUpClientCertInSystemSlot());
net::SpawnedTestServer::SSLOptions ssl_options;
ssl_options.request_client_certificate = true;
base::FilePath ca_path = net::GetTestCertsDirectory().Append(
......@@ -852,7 +816,7 @@ IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
// deprecated and removed. https://crbug.com/849710.
IN_PROC_BROWSER_TEST_F(WebviewClientCertsLoginTest,
DISABLED_ClientCertRequestedInOtherWebView) {
ASSERT_NO_FATAL_FAILURE(SetUpClientCertInSystemSlot());
ASSERT_TRUE(SetUpClientCertInSystemSlot());
net::SpawnedTestServer::SSLOptions ssl_options;
ssl_options.request_client_certificate = true;
ASSERT_NO_FATAL_FAILURE(StartHttpsServer(ssl_options));
......
// Copyright 2019 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 "chrome/browser/chromeos/scoped_test_system_nss_key_slot_mixin.h"
#include "base/bind.h"
#include "base/run_loop.h"
#include "base/task/post_task.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "crypto/scoped_test_system_nss_key_slot.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
ScopedTestSystemNSSKeySlotMixin::ScopedTestSystemNSSKeySlotMixin(
InProcessBrowserTestMixinHost* host)
: InProcessBrowserTestMixin(host) {}
ScopedTestSystemNSSKeySlotMixin::~ScopedTestSystemNSSKeySlotMixin() = default;
PK11SlotInfo* ScopedTestSystemNSSKeySlotMixin::slot() {
return scoped_test_system_nss_key_slot_->slot();
}
void ScopedTestSystemNSSKeySlotMixin::SetUpOnMainThread() {
bool system_slot_initialized_successfully = false;
base::RunLoop loop;
base::PostTaskAndReply(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&ScopedTestSystemNSSKeySlotMixin::InitializeOnIo,
base::Unretained(this),
&system_slot_initialized_successfully),
loop.QuitClosure());
loop.Run();
ASSERT_TRUE(system_slot_initialized_successfully);
}
void ScopedTestSystemNSSKeySlotMixin::TearDownOnMainThread() {
base::RunLoop loop;
base::PostTaskAndReply(
FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&ScopedTestSystemNSSKeySlotMixin::DestroyOnIo,
base::Unretained(this)),
loop.QuitClosure());
loop.Run();
}
void ScopedTestSystemNSSKeySlotMixin::InitializeOnIo(bool* out_success) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
scoped_test_system_nss_key_slot_ =
std::make_unique<crypto::ScopedTestSystemNSSKeySlot>();
*out_success = scoped_test_system_nss_key_slot_->ConstructedSuccessfully();
}
void ScopedTestSystemNSSKeySlotMixin::DestroyOnIo() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
scoped_test_system_nss_key_slot_.reset();
}
} // namespace chromeos
// Copyright 2019 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.
#ifndef CHROME_BROWSER_CHROMEOS_SCOPED_TEST_SYSTEM_NSS_KEY_SLOT_MIXIN_H_
#define CHROME_BROWSER_CHROMEOS_SCOPED_TEST_SYSTEM_NSS_KEY_SLOT_MIXIN_H_
#include <pk11pub.h>
#include <memory>
#include "chrome/test/base/mixin_based_in_process_browser_test.h"
namespace crypto {
class ScopedTestSystemNSSKeySlot;
}
namespace chromeos {
// Owns a persistent NSS software database in a temporary directory and the
// association of the system slot with this database.
//
// This mixin performs the blocking initialization/destruction in the
// {SetUp|TearDown}OnMainThread methods.
class ScopedTestSystemNSSKeySlotMixin final : public InProcessBrowserTestMixin {
public:
explicit ScopedTestSystemNSSKeySlotMixin(InProcessBrowserTestMixinHost* host);
ScopedTestSystemNSSKeySlotMixin(const ScopedTestSystemNSSKeySlotMixin&) =
delete;
ScopedTestSystemNSSKeySlotMixin& operator=(
const ScopedTestSystemNSSKeySlotMixin&) = delete;
~ScopedTestSystemNSSKeySlotMixin() override;
crypto::ScopedTestSystemNSSKeySlot* scoped_test_system_nss_key_slot() {
return scoped_test_system_nss_key_slot_.get();
}
const crypto::ScopedTestSystemNSSKeySlot* scoped_test_system_nss_key_slot()
const {
return scoped_test_system_nss_key_slot_.get();
}
PK11SlotInfo* slot();
void SetUpOnMainThread() override;
void TearDownOnMainThread() override;
private:
void InitializeOnIo(bool* out_success);
void DestroyOnIo();
std::unique_ptr<crypto::ScopedTestSystemNSSKeySlot>
scoped_test_system_nss_key_slot_;
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_SCOPED_TEST_SYSTEM_NSS_KEY_SLOT_MIXIN_H_
......@@ -890,6 +890,8 @@ if (!is_android) {
"../browser/chrome_worker_browsertest.cc",
"../browser/chromeos/certificate_provider/test_certificate_provider_extension_login_screen_mixin.cc",
"../browser/chromeos/certificate_provider/test_certificate_provider_extension_login_screen_mixin.h",
"../browser/chromeos/scoped_test_system_nss_key_slot_mixin.cc",
"../browser/chromeos/scoped_test_system_nss_key_slot_mixin.h",
"../browser/client_hints/client_hints_browsertest.cc",
"../browser/component_updater/component_patcher_operation_browsertest.cc",
"../browser/content_index/content_index_browsertest.cc",
......
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