Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Unified Diff: chrome/browser/ssl/ssl_error_handler_unittest.cc

Issue 2620203003: Add initial version of captive portal list checking. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ssl/ssl_error_handler_unittest.cc
diff --git a/chrome/browser/ssl/ssl_error_handler_unittest.cc b/chrome/browser/ssl/ssl_error_handler_unittest.cc
index dca4034b046ee402ceae32442d046fed9039e8f5..267c87dad794586db98f7260b0fc4234008ed776 100644
--- a/chrome/browser/ssl/ssl_error_handler_unittest.cc
+++ b/chrome/browser/ssl/ssl_error_handler_unittest.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/captive_portal/captive_portal_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ssl/common_name_mismatch_handler.h"
+#include "chrome/browser/ssl/tls_error_assistant.pb.h"
#include "chrome/common/features.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
@@ -43,6 +44,8 @@ namespace {
const char kCertDateErrorHistogram[] =
"interstitial.ssl_error_handler.cert_date_error_delay";
+const net::SHA256HashValue kCertPublicKeyHashValue = {{0x01, 0x02}};
+
} // namespace
class SSLErrorHandlerForTest : public SSLErrorHandler {
@@ -171,6 +174,8 @@ class SSLErrorHandlerNameMismatchTest : public ChromeRenderViewHostTestHarness {
ssl_info_.cert =
net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
ssl_info_.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID;
+ ssl_info_.public_key_hashes.push_back(
+ net::HashValue(kCertPublicKeyHashValue));
error_handler_.reset(
new SSLErrorHandlerForTest(profile(), web_contents(), ssl_info_));
// Enable finch experiment for captive portal interstitials.
@@ -189,6 +194,8 @@ class SSLErrorHandlerNameMismatchTest : public ChromeRenderViewHostTestHarness {
SSLErrorHandlerForTest* error_handler() { return error_handler_.get(); }
+ const net::SSLInfo& ssl_info() { return ssl_info_; }
+
private:
net::SSLInfo ssl_info_;
std::unique_ptr<SSLErrorHandlerForTest> error_handler_;
@@ -549,3 +556,36 @@ TEST_F(SSLErrorHandlerDateInvalidTest, TimeQueryHangs) {
// Shut down the server to cancel the pending request.
ASSERT_TRUE(test_server()->ShutdownAndWaitUntilComplete());
}
+
+TEST_F(SSLErrorHandlerNameMismatchTest, KnownCaptivePortal) {
+ base::HistogramTester histograms;
+
+ EXPECT_FALSE(error_handler()->IsTimerRunning());
+ EXPECT_EQ(1u, ssl_info().public_key_hashes.size());
estark 2017/01/12 18:54:44 nit: might want to add a test case for when there'
meacer 2017/01/20 21:30:00 Changed this test to use multiple hashes.
+
+ chrome_browser_ssl::TLSErrorAssistantConfig config_proto;
+ config_proto.add_captive_portal_cert()->set_sha256_hash(
+ ssl_info().public_key_hashes[0].ToString());
+ SSLErrorHandler::SetErrorAssistantProtoForTesting(config_proto);
+
+ error_handler()->StartHandlingError();
+
+ // Timer shouldn't start for a known captive portal certificate.
+ EXPECT_FALSE(error_handler()->IsTimerRunning());
+ EXPECT_FALSE(error_handler()->captive_portal_checked());
+ EXPECT_FALSE(error_handler()->ssl_interstitial_shown());
+ EXPECT_TRUE(error_handler()->captive_portal_interstitial_shown());
+
+ base::RunLoop().RunUntilIdle();
estark 2017/01/12 18:54:43 This is a little confusing, why do we run the run
meacer 2017/01/12 23:54:03 This is in case SSLErrorHandler incorrectly starts
meacer 2017/01/20 21:30:00 Added a comment.
+
+ EXPECT_FALSE(error_handler()->IsTimerRunning());
+ EXPECT_FALSE(error_handler()->captive_portal_checked());
+ EXPECT_FALSE(error_handler()->ssl_interstitial_shown());
+ EXPECT_TRUE(error_handler()->captive_portal_interstitial_shown());
+
+ // Check that the histogram for the captive portal cert was recorded.
+ histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(),
+ SSLErrorHandler::HANDLE_ALL, 1);
+ histograms.ExpectBucketCount(SSLErrorHandler::GetHistogramNameForTesting(),
+ SSLErrorHandler::CAPTIVE_PORTAL_CERT_FOUND, 1);
+}
« chrome/browser/ssl/ssl_error_handler.cc ('K') | « chrome/browser/ssl/ssl_error_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698