1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
#include "chrome/browser/policy/safe_browsing_policy_test.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/chrome_test_utils.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_types.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_service.h"
#include "components/security_interstitials/content/security_interstitial_page.h"
#include "components/security_interstitials/content/security_interstitial_tab_helper.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace policy {
void SendInterstitialCommand(
content::WebContents* tab,
security_interstitials::SecurityInterstitialCommand command) {
security_interstitials::SecurityInterstitialTabHelper* helper =
security_interstitials::SecurityInterstitialTabHelper::FromWebContents(
tab);
helper->GetBlockingPageForCurrentlyCommittedNavigationForTesting()
->CommandReceived(base::NumberToString(command));
return;
}
// Test that when SSL error overriding policies are unset, the proceed link
// appears on SSL blocking pages.
IN_PROC_BROWSER_TEST_F(SafeBrowsingPolicyTest,
SSLErrorOverridingAllowedDefaults) {
net::EmbeddedTestServer https_server_expired(
net::EmbeddedTestServer::TYPE_HTTPS);
https_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data");
ASSERT_TRUE(https_server_expired.Start());
const PrefService* const prefs =
chrome_test_utils::GetProfile(this)->GetPrefs();
// Policy should allow overriding by default. Allow list should be empty by
// default.
EXPECT_TRUE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
EXPECT_TRUE(
prefs->GetList(prefs::kSSLErrorOverrideAllowedForOrigins).empty());
// Policy allows overriding - navigate to an SSL error page and expect the
// proceed link.
ASSERT_TRUE(NavigateToUrl(https_server_expired.GetURL("/"), this));
content::WebContents* tab = chrome_test_utils::GetActiveWebContents(this);
ASSERT_TRUE(IsShowingInterstitial(tab));
// The interstitial should display the proceed link.
EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText(
tab->GetPrimaryMainFrame(), "proceed-link"));
}
// Test that when SSL error overriding is allowed, the origin list is ignored
// and the proceed link appears on SSL blocking pages.
IN_PROC_BROWSER_TEST_F(SafeBrowsingPolicyTest,
SSLErrorOverridingAllowedEnabled) {
net::EmbeddedTestServer https_server_expired(
net::EmbeddedTestServer::TYPE_HTTPS);
https_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data");
ASSERT_TRUE(https_server_expired.Start());
const PrefService* const prefs =
chrome_test_utils::GetProfile(this)->GetPrefs();
// Policy should allow overriding by default. Allow list should be empty by
// default.
EXPECT_TRUE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
EXPECT_TRUE(
prefs->GetList(prefs::kSSLErrorOverrideAllowedForOrigins).empty());
// Add a policy to allow overriding on specific sites only. Since
// kSSLErrorOverrideAllowed is enabled, this should do nothing.
base::Value::List allow_list;
allow_list.Append("example.com");
PolicyMap policies;
policies.Set(key::kSSLErrorOverrideAllowedForOrigins, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
base::Value(std::move(allow_list)), nullptr);
UpdateProviderPolicy(policies);
// Policy should be set.
EXPECT_FALSE(
prefs->GetList(prefs::kSSLErrorOverrideAllowedForOrigins).empty());
// Policy allows overriding - navigate to an SSL error page and expect the
// proceed link.
ASSERT_TRUE(NavigateToUrl(https_server_expired.GetURL("/"), this));
content::WebContents* tab = chrome_test_utils::GetActiveWebContents(this);
ASSERT_TRUE(IsShowingInterstitial(tab));
// The interstitial should display the proceed link.
EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText(
tab->GetPrimaryMainFrame(), "proceed-link"));
}
// Test that when SSL error overriding is disabled, the proceed link does not
// appear appear on SSL blocking pages.
IN_PROC_BROWSER_TEST_F(SafeBrowsingPolicyTest,
SSLErrorOverridingAllowedDisabled) {
net::EmbeddedTestServer https_server_expired(
net::EmbeddedTestServer::TYPE_HTTPS);
https_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data");
ASSERT_TRUE(https_server_expired.Start());
const PrefService* const prefs =
chrome_test_utils::GetProfile(this)->GetPrefs();
EXPECT_TRUE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
// Disallowing the proceed link by setting the policy to |false|.
PolicyMap policies;
policies.Set(key::kSSLErrorOverrideAllowed, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, base::Value(false),
nullptr);
UpdateProviderPolicy(policies);
// Policy should not allow overriding.
EXPECT_FALSE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
// Policy disallows overriding - navigate to an SSL error page and expect no
// proceed link.
ASSERT_TRUE(NavigateToUrl(https_server_expired.GetURL("/"), this));
content::WebContents* tab = chrome_test_utils::GetActiveWebContents(this);
ASSERT_TRUE(IsShowingInterstitial(tab));
// The interstitial should not display the proceed link.
EXPECT_FALSE(chrome_browser_interstitials::IsInterstitialDisplayingText(
tab->GetPrimaryMainFrame(), "proceed-link"));
// The interstitial should not proceed, even if the command is sent in
// some other way (e.g., via the keyboard shortcut).
SendInterstitialCommand(tab, security_interstitials::CMD_PROCEED);
EXPECT_TRUE(IsShowingInterstitial(tab));
}
// Test that when SSL error overriding is disallowed by policy and the origin
// list is configured, the proceed link does not appear on SSL blocking pages if
// the page is not on the origin list.
IN_PROC_BROWSER_TEST_F(SafeBrowsingPolicyTest,
SSLErrorOverridingAllowedForOriginsWrongOrigin) {
net::EmbeddedTestServer https_server_expired(
net::EmbeddedTestServer::TYPE_HTTPS);
https_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data");
ASSERT_TRUE(https_server_expired.Start());
const PrefService* const prefs =
chrome_test_utils::GetProfile(this)->GetPrefs();
// Policy should allow overriding by default. Allow list should be empty by
// default.
EXPECT_TRUE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
EXPECT_TRUE(
prefs->GetList(prefs::kSSLErrorOverrideAllowedForOrigins).empty());
// Disallowing the proceed link by setting the policy to |false|.
PolicyMap policies;
policies.Set(key::kSSLErrorOverrideAllowed, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, base::Value(false),
nullptr);
// Add a policy to allow overriding on specific sites only.
base::Value::List allow_list;
allow_list.Append("example.com");
policies.Set(key::kSSLErrorOverrideAllowedForOrigins, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
base::Value(std::move(allow_list)), nullptr);
UpdateProviderPolicy(policies);
// Policy should be set.
EXPECT_FALSE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
EXPECT_FALSE(
prefs->GetList(prefs::kSSLErrorOverrideAllowedForOrigins).empty());
// Policy disallows overriding - navigate to an SSL error page and expect no
// proceed link.
ASSERT_TRUE(NavigateToUrl(https_server_expired.GetURL("/"), this));
content::WebContents* tab = chrome_test_utils::GetActiveWebContents(this);
ASSERT_TRUE(IsShowingInterstitial(tab));
// The interstitial should not display the proceed link.
EXPECT_FALSE(chrome_browser_interstitials::IsInterstitialDisplayingText(
tab->GetPrimaryMainFrame(), "proceed-link"));
// The interstitial should not proceed, even if the command is sent in
// some other way (e.g., via the keyboard shortcut).
SendInterstitialCommand(tab, security_interstitials::CMD_PROCEED);
EXPECT_TRUE(IsShowingInterstitial(tab));
}
// Test that when SSL error overriding is disallowed by policy and the origin
// list is configured incorrectly, the proceed link does not appear on SSL
// blocking pages.
IN_PROC_BROWSER_TEST_F(SafeBrowsingPolicyTest,
SSLErrorOverridingForOriginsBadInput) {
net::EmbeddedTestServer https_server_expired(
net::EmbeddedTestServer::TYPE_HTTPS);
https_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data");
ASSERT_TRUE(https_server_expired.Start());
const PrefService* const prefs =
chrome_test_utils::GetProfile(this)->GetPrefs();
EXPECT_TRUE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
EXPECT_TRUE(
prefs->GetList(prefs::kSSLErrorOverrideAllowedForOrigins).empty());
// Disallowing the proceed link by setting the policy to |false|.
PolicyMap policies;
policies.Set(key::kSSLErrorOverrideAllowed, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, base::Value(false),
nullptr);
base::Value::List allow_list;
// We ignore "*" or badly formed patterns as inputs.
allow_list.Append("*");
allow_list.Append("bad 127.0.0.1 input");
policies.Set(key::kSSLErrorOverrideAllowedForOrigins, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
base::Value(std::move(allow_list)), nullptr);
UpdateProviderPolicy(policies);
// Policy should not allow overriding.
EXPECT_FALSE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
EXPECT_FALSE(
prefs->GetList(prefs::kSSLErrorOverrideAllowedForOrigins).empty());
// Policy disallows overriding - navigate to an SSL error page and expect no
// proceed link.
ASSERT_TRUE(NavigateToUrl(https_server_expired.GetURL("/"), this));
content::WebContents* tab = chrome_test_utils::GetActiveWebContents(this);
ASSERT_TRUE(IsShowingInterstitial(tab));
// The interstitial should not display the proceed link.
EXPECT_FALSE(chrome_browser_interstitials::IsInterstitialDisplayingText(
tab->GetPrimaryMainFrame(), "proceed-link"));
// The interstitial should not proceed, even if the command is sent in
// some other way (e.g., via the keyboard shortcut).
SendInterstitialCommand(tab, security_interstitials::CMD_PROCEED);
EXPECT_TRUE(IsShowingInterstitial(tab));
}
// Test that when SSL error overriding is disallowed by policy and the origin
// list is empty, the proceed link does not appear on SSL blocking pages.
IN_PROC_BROWSER_TEST_F(SafeBrowsingPolicyTest,
SSLErrorOverridingForOriginsEmptyList) {
net::EmbeddedTestServer https_server_expired(
net::EmbeddedTestServer::TYPE_HTTPS);
https_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data");
ASSERT_TRUE(https_server_expired.Start());
const PrefService* const prefs =
chrome_test_utils::GetProfile(this)->GetPrefs();
EXPECT_TRUE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
EXPECT_TRUE(
prefs->GetList(prefs::kSSLErrorOverrideAllowedForOrigins).empty());
// Disallowing the proceed link by setting the policy to |false|.
PolicyMap policies;
policies.Set(key::kSSLErrorOverrideAllowed, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, base::Value(false),
nullptr);
// The policy is intentionally configured with an empty list for this test.
base::Value::List allow_list;
policies.Set(key::kSSLErrorOverrideAllowedForOrigins, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
base::Value(std::move(allow_list)), nullptr);
UpdateProviderPolicy(policies);
// Policy should not allow overriding.
EXPECT_FALSE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
EXPECT_TRUE(
prefs->GetList(prefs::kSSLErrorOverrideAllowedForOrigins).empty());
// Policy disallows overriding - navigate to an SSL error page and expect no
// proceed link.
ASSERT_TRUE(NavigateToUrl(https_server_expired.GetURL("/"), this));
content::WebContents* tab = chrome_test_utils::GetActiveWebContents(this);
ASSERT_TRUE(IsShowingInterstitial(tab));
// The interstitial should not display the proceed link.
EXPECT_FALSE(chrome_browser_interstitials::IsInterstitialDisplayingText(
tab->GetPrimaryMainFrame(), "proceed-link"));
// The interstitial should not proceed, even if the command is sent in
// some other way (e.g., via the keyboard shortcut).
SendInterstitialCommand(tab, security_interstitials::CMD_PROCEED);
EXPECT_TRUE(IsShowingInterstitial(tab));
}
// Test that when SSL error overriding is disallowed by policy and the origin
// list is configured, the proceed link appears on SSL blocking pages if the
// page is on the origin list.
IN_PROC_BROWSER_TEST_F(SafeBrowsingPolicyTest,
SSLErrorOverridingAllowedForOrigins) {
net::EmbeddedTestServer https_server_expired(
net::EmbeddedTestServer::TYPE_HTTPS);
https_server_expired.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
https_server_expired.ServeFilesFromSourceDirectory("chrome/test/data");
ASSERT_TRUE(https_server_expired.Start());
const PrefService* const prefs =
chrome_test_utils::GetProfile(this)->GetPrefs();
// Policy should allow overriding by default. Allow list should be empty by
// default.
EXPECT_TRUE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
EXPECT_TRUE(
prefs->GetList(prefs::kSSLErrorOverrideAllowedForOrigins).empty());
// Disallowing the proceed link by setting the policy to |false|.
PolicyMap policies;
policies.Set(key::kSSLErrorOverrideAllowed, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, base::Value(false),
nullptr);
// Add a policy to allow overriding on specific sites only. The path should be
// ignored.
base::Value::List allow_list;
allow_list.Append("127.0.0.1/my/path/to/file.ext");
policies.Set(key::kSSLErrorOverrideAllowedForOrigins, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
base::Value(std::move(allow_list)), nullptr);
UpdateProviderPolicy(policies);
// Policy should be set.
EXPECT_FALSE(prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed));
EXPECT_FALSE(
prefs->GetList(prefs::kSSLErrorOverrideAllowedForOrigins).empty());
// Policy allows overriding - navigate to an SSL error page and expect the
// proceed link.
ASSERT_TRUE(NavigateToUrl(https_server_expired.GetURL("/"), this));
content::WebContents* tab = chrome_test_utils::GetActiveWebContents(this);
ASSERT_TRUE(IsShowingInterstitial(tab));
// The interstitial should display the proceed link.
EXPECT_TRUE(chrome_browser_interstitials::IsInterstitialDisplayingText(
tab->GetPrimaryMainFrame(), "proceed-link"));
}
} // namespace policy
|