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

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

Issue 1223233002: Common Name Mismatch Handler For WWW Subdomain Mismatch case (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unittests Created 5 years, 5 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 e93908e9cf7847c2c9e4af7c9bdf3641b9bd0249..3532ff914115cd8bc8c40f1438264ebdbde3dbda 100644
--- a/chrome/browser/ssl/ssl_error_handler_unittest.cc
+++ b/chrome/browser/ssl/ssl_error_handler_unittest.cc
@@ -11,12 +11,15 @@
#include "base/time/time.h"
#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/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "components/captive_portal/captive_portal_testing_utils.h"
#include "content/public/browser/notification_service.h"
#include "net/base/net_errors.h"
+#include "net/cert/x509_certificate.h"
#include "net/ssl/ssl_info.h"
+#include "net/test/test_certificate_data.h"
#include "testing/gtest/include/gtest/gtest.h"
class TestSSLErrorHandler : public SSLErrorHandler {
@@ -33,8 +36,11 @@ class TestSSLErrorHandler : public SSLErrorHandler {
base::Callback<void(bool)>()),
profile_(profile),
captive_portal_checked_(false),
+ suggested_url_exists_(false),
+ suggested_url_checked_(false),
ssl_interstitial_shown_(false),
- captive_portal_interstitial_shown_(false) {}
+ captive_portal_interstitial_shown_(false),
+ common_name_mismatch_interstitial_shown_(false) {}
~TestSSLErrorHandler() override {
}
@@ -52,6 +58,15 @@ class TestSSLErrorHandler : public SSLErrorHandler {
content::Details<CaptivePortalService::Results>(&results));
}
+ void SendSuggestedUrlCheckResult(
+ const CommonNameMismatchHandler::SuggestedUrlCheckResult& result,
+ const GURL new_url) {
meacer 2015/07/15 20:11:46 const GURL&
Bhanu Dev 2015/07/16 23:38:06 Done.
+ CommonNameMismatchHandler::Results results;
+ results.result = result;
+ results.new_url = new_url;
+ CommonNameMismatchHandlerCallback(results);
+ }
+
bool IsTimerRunning() const {
return get_timer().IsRunning();
}
@@ -68,10 +83,30 @@ class TestSSLErrorHandler : public SSLErrorHandler {
return captive_portal_interstitial_shown_;
}
+ void SetSuggestedUrl() { suggested_url_exists_ = true; }
meacer 2015/07/15 20:11:47 I suggest changing this to SetSuggestedUrlExists(b
Bhanu Dev 2015/07/16 23:38:06 Done.
+
+ bool GetSuggestedUrl(const GURL& request_url,
+ const std::vector<std::string>& dns_names,
+ GURL* suggested_url) override {
+ if (!suggested_url_exists_)
+ return false;
+ *suggested_url = GURL("www.example.com");
+ return true;
+ }
+
+ int suggested_url_checked() const { return suggested_url_checked_; }
meacer 2015/07/15 20:11:46 bool return type
Bhanu Dev 2015/07/16 23:38:06 Done.
+
+ int common_name_mismatch_interstitial_shown() const {
meacer 2015/07/15 20:11:46 bool return type
Bhanu Dev 2015/07/16 23:38:06 Done.
+ return common_name_mismatch_interstitial_shown_;
+ }
+
void Reset() {
captive_portal_checked_ = false;
+ suggested_url_exists_ = false;
+ suggested_url_checked_ = false;
ssl_interstitial_shown_ = false;
captive_portal_interstitial_shown_ = false;
+ common_name_mismatch_interstitial_shown_ = false;
}
private:
@@ -79,18 +114,28 @@ class TestSSLErrorHandler : public SSLErrorHandler {
captive_portal_checked_ = true;
}
- void ShowSSLInterstitial() override {
- ssl_interstitial_shown_ = true;
+ void ShowSSLInterstitial(const GURL& suggested_url) override {
+ if (!suggested_url.is_empty())
+ common_name_mismatch_interstitial_shown_ = true;
+ else
+ ssl_interstitial_shown_ = true;
}
void ShowCaptivePortalInterstitial(const GURL& landing_url) override {
captive_portal_interstitial_shown_ = true;
}
+ void CheckSuggestedUrl(const GURL& suggested_url) override {
+ suggested_url_checked_ = true;
+ }
+
Profile* profile_;
bool captive_portal_checked_;
+ bool suggested_url_exists_;
+ bool suggested_url_checked_;
meacer 2015/07/15 20:11:46 nit: Put these in opposite order here in other pla
Bhanu Dev 2015/07/16 23:38:06 If the suggested URL exists, we check for the vali
bool ssl_interstitial_shown_;
bool captive_portal_interstitial_shown_;
+ bool common_name_mismatch_interstitial_shown_;
DISALLOW_COPY_AND_ASSIGN(TestSSLErrorHandler);
};
@@ -104,13 +149,15 @@ class SSLErrorHandlerTest : public ChromeRenderViewHostTestHarness {
void SetUp() override {
ChromeRenderViewHostTestHarness::SetUp();
SSLErrorHandler::SetInterstitialDelayTypeForTest(SSLErrorHandler::NONE);
+ ssl_info_.cert = net::X509Certificate::CreateFromBytes(
+ reinterpret_cast<const char*>(google_der), sizeof(google_der));
meacer 2015/07/15 20:11:46 Do you need an actual cert here? If not, you can c
Bhanu Dev 2015/07/16 23:38:06 |SSLErrorHandler| calls method like |GetDNSNames|
error_handler_.reset(new TestSSLErrorHandler(profile(),
web_contents(),
ssl_info_));
// Enable finch experiment for captive portal interstitials.
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
"CaptivePortalInterstitial", "Enabled"));
-}
+ }
void TearDown() override {
EXPECT_FALSE(error_handler()->IsTimerRunning());
@@ -191,6 +238,32 @@ TEST_F(SSLErrorHandlerTest,
EXPECT_FALSE(error_handler()->captive_portal_interstitial_shown());
}
+TEST_F(SSLErrorHandlerTest,
+ ShouldNotCheckSuggestedUrlIfGetSuggestedUrlIsFalse) {
meacer 2015/07/15 20:11:46 nit: name this ShouldNotCheckSuggestedUrlIfNoSugge
Bhanu Dev 2015/07/16 23:38:06 Done.
+ EXPECT_FALSE(error_handler()->IsTimerRunning());
+ error_handler()->StartHandlingError();
meacer 2015/07/15 20:11:46 Looks like you are using |SetSuggestedURL| to enab
Bhanu Dev 2015/07/16 23:38:06 It is good to add a bool param to |SetSuggestedURL
+
+ EXPECT_TRUE(error_handler()->IsTimerRunning());
+ EXPECT_FALSE(error_handler()->suggested_url_checked());
+ base::MessageLoop::current()->RunUntilIdle();
+
+ EXPECT_TRUE(error_handler()->ssl_interstitial_shown());
meacer 2015/07/15 20:11:46 EXPECT_FALSE(error_handler()->IsTimerRunning()); b
Bhanu Dev 2015/07/16 23:38:06 Done.
+}
+
+TEST_F(SSLErrorHandlerTest,
+ ShouldNotCheckForCaptivePortalIfSuggestedUrlExists) {
meacer 2015/07/15 20:11:46 nit: This name uses CheckFor while the previous on
Bhanu Dev 2015/07/16 23:38:06 Done.
+ EXPECT_FALSE(error_handler()->IsTimerRunning());
+ error_handler()->SetSuggestedUrl();
+ error_handler()->StartHandlingError();
+
+ EXPECT_TRUE(error_handler()->IsTimerRunning());
+ EXPECT_TRUE(error_handler()->suggested_url_checked());
+ EXPECT_FALSE(error_handler()->captive_portal_checked());
+ base::MessageLoop::current()->RunUntilIdle();
+
+ EXPECT_TRUE(error_handler()->ssl_interstitial_shown());
meacer 2015/07/15 20:11:47 EXPECT_FALSE(error_handler()->IsTimerRunning()); b
Bhanu Dev 2015/07/16 23:38:06 Done.
+}
+
#else // #if !defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
TEST_F(SSLErrorHandlerTest,
@@ -204,3 +277,62 @@ TEST_F(SSLErrorHandlerTest,
}
#endif // defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
+
+TEST_F(SSLErrorHandlerTest,
+ ShouldShowSSLInterstitialOnTimerExpiredWhenSuggestedUrlExists) {
+ EXPECT_FALSE(error_handler()->IsTimerRunning());
+ error_handler()->SetSuggestedUrl();
+ error_handler()->StartHandlingError();
+
+ EXPECT_TRUE(error_handler()->IsTimerRunning());
+ EXPECT_TRUE(error_handler()->suggested_url_checked());
+ EXPECT_FALSE(error_handler()->ssl_interstitial_shown());
+ EXPECT_FALSE(error_handler()->common_name_mismatch_interstitial_shown());
+
+ base::MessageLoop::current()->RunUntilIdle();
+
+ EXPECT_FALSE(error_handler()->IsTimerRunning());
+ EXPECT_TRUE(error_handler()->ssl_interstitial_shown());
+ EXPECT_FALSE(error_handler()->common_name_mismatch_interstitial_shown());
+}
+
+TEST_F(SSLErrorHandlerTest,
+ ShouldShowCommonNameMismatchInterstitialOnSuggestedUrlCheckResult) {
+ EXPECT_FALSE(error_handler()->IsTimerRunning());
+ error_handler()->SetSuggestedUrl();
+ error_handler()->StartHandlingError();
+
+ EXPECT_TRUE(error_handler()->IsTimerRunning());
+ EXPECT_TRUE(error_handler()->suggested_url_checked());
+ EXPECT_FALSE(error_handler()->ssl_interstitial_shown());
+ EXPECT_FALSE(error_handler()->common_name_mismatch_interstitial_shown());
+ // Fake a Valid Suggested URL Check result.
meacer 2015/07/15 20:11:46 nit: don't capitalize "Valid Suggested URL Check"
Bhanu Dev 2015/07/16 23:38:06 Done.
+ error_handler()->SendSuggestedUrlCheckResult(
+ CommonNameMismatchHandler::SuggestedUrlCheckResult::
+ RESULT_SUGGESTED_URL_VALID,
+ GURL("https://random.example.com"));
meacer 2015/07/15 20:11:46 Why is this URL different than the return value of
meacer 2015/07/15 20:11:46 indent 4 more spaces
Bhanu Dev 2015/07/16 23:38:06 Done.
Bhanu Dev 2015/07/16 23:38:06 This URL is the new landing page and this can be d
Bhanu Dev 2015/07/16 23:38:06 I tried to indent it, but |git cl format| is rever
+
+ EXPECT_FALSE(error_handler()->IsTimerRunning());
+ EXPECT_FALSE(error_handler()->ssl_interstitial_shown());
+ EXPECT_TRUE(error_handler()->common_name_mismatch_interstitial_shown());
+}
+
+TEST_F(SSLErrorHandlerTest, ShouldShowSSLInterstitialOnInvalidUrlCheckResult) {
+ EXPECT_FALSE(error_handler()->IsTimerRunning());
+ error_handler()->SetSuggestedUrl();
+ error_handler()->StartHandlingError();
+
+ EXPECT_TRUE(error_handler()->IsTimerRunning());
+ EXPECT_TRUE(error_handler()->suggested_url_checked());
+ EXPECT_FALSE(error_handler()->ssl_interstitial_shown());
+ EXPECT_FALSE(error_handler()->common_name_mismatch_interstitial_shown());
+ // Fake an Invalid Suggested URL Check result.
+ error_handler()->SendSuggestedUrlCheckResult(
+ CommonNameMismatchHandler::SuggestedUrlCheckResult::
+ RESULT_SUGGESTED_URL_INVALID,
+ GURL());
meacer 2015/07/15 20:11:47 indent 4 more spaces
Bhanu Dev 2015/07/16 23:38:06 Done.
+
+ EXPECT_FALSE(error_handler()->IsTimerRunning());
+ EXPECT_TRUE(error_handler()->ssl_interstitial_shown());
+ EXPECT_FALSE(error_handler()->common_name_mismatch_interstitial_shown());
+}

Powered by Google App Engine
This is Rietveld 408576698