blob: a0ee9030157296e0844e489344224b4e12e90725 [file] [log] [blame]
calamityaa4a2212019-10-02 04:53:041// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ssl/tls_deprecation_config.h"
6
7#include <memory>
8#include <string>
9
Christopher Thompsonbe9cafe2020-02-05 04:46:1110#include "chrome/browser/ssl/tls_deprecation_test_utils.h"
11#include "services/network/public/proto/tls_deprecation_config.pb.h"
calamityaa4a2212019-10-02 04:53:0412#include "testing/gtest/include/gtest/gtest.h"
13#include "url/gurl.h"
14
15using chrome_browser_ssl::LegacyTLSExperimentConfig;
16
17// Tests the case where no proto has been set by the component installer.
18TEST(TLSDeprecationConfigTest, NoProto) {
Christopher Thompson6f9194222019-10-11 00:20:2219 EXPECT_TRUE(ShouldSuppressLegacyTLSWarning(GURL("https://example.test")));
calamityaa4a2212019-10-02 04:53:0420}
21
22// This tests that when no sites are in the control set,
23// IsTLSDeprecationControlSite() returns false.
24TEST(TLSDeprecationConfigTest, NoControlSites) {
25 GURL control_site("https://control.test");
26 std::string control_site_hex =
27 "f12b47771bb3c2bcc85a5347d195523013ec5a23b4c761b5d6aacf04bafc5e23";
28
29 // Setup proto (as if read from component installer), but don't add any
30 // control sites to it.
31 auto config = std::make_unique<LegacyTLSExperimentConfig>();
Christopher Thompsonbe9cafe2020-02-05 04:46:1132 config->set_version_id(1);
33 SetRemoteTLSDeprecationConfig(config->SerializeAsString());
calamityaa4a2212019-10-02 04:53:0434
Christopher Thompson6f9194222019-10-11 00:20:2235 EXPECT_FALSE(ShouldSuppressLegacyTLSWarning(control_site));
calamityaa4a2212019-10-02 04:53:0436}
37
38// This tests that when only a single control site is in the control set,
39// IsTLSDeprecationControlSite() works correctly for the site in the control and
40// for sites not in the control.
41TEST(TLSDeprecationConfigTest, SingleControlSite) {
42 GURL control_site("https://control.test");
43 std::string control_site_hex =
44 "f12b47771bb3c2bcc85a5347d195523013ec5a23b4c761b5d6aacf04bafc5e23";
45 GURL non_control_site("https://not-control.test");
46 std::string non_control_site_hex =
47 "a11de9f014acb9e53c8997d9c48b10ed23c8b2fa7e790b125ea5fb78af5359cb";
48 GURL http_site("http://noncryptographic.test");
49 std::string http_site_hex =
50 "fd288ddecdac673aedb343e41117443f1ce88114dcc7bfa3c4a65a1e725d8fbe";
51
52 // Setup proto (as if read from component installer).
53 auto config = std::make_unique<LegacyTLSExperimentConfig>();
Christopher Thompsonbe9cafe2020-02-05 04:46:1154 config->set_version_id(1);
calamityaa4a2212019-10-02 04:53:0455 config->add_control_site_hashes(control_site_hex);
56
Christopher Thompsonbe9cafe2020-02-05 04:46:1157 SetRemoteTLSDeprecationConfig(config->SerializeAsString());
calamityaa4a2212019-10-02 04:53:0458
Christopher Thompson6f9194222019-10-11 00:20:2259 EXPECT_TRUE(ShouldSuppressLegacyTLSWarning(control_site));
60 EXPECT_FALSE(ShouldSuppressLegacyTLSWarning(non_control_site));
calamityaa4a2212019-10-02 04:53:0461
62 // And HTTP sites should not count either.
Christopher Thompson6f9194222019-10-11 00:20:2263 EXPECT_FALSE(ShouldSuppressLegacyTLSWarning(http_site));
calamityaa4a2212019-10-02 04:53:0464}
65
66// This tests that the binary search in IsTLSDeprecationControlSite() works for
67// both a site that is in the control set and a site that is not.
68TEST(TLSDeprecationConfigTest, ManyControlSites) {
69 const struct {
70 GURL url;
71 std::string hash;
72 } kControlSites[] = {
73 // These must be in alphanumeric (0-9a-z) order by their hashes.
74 {GURL("https://control6.test"),
75 "27ce26e09cae16b1bd1914678d82e98326362f4a06b1b3e81c8ea96018be3b08"},
76 {GURL("https://control9.test"),
77 "2904bff8d79d14e7b90d7cb499ce0bcd619f76818d9512f4c855d2ab738f42e8"},
78 {GURL("https://control2.test"),
79 "4c37847b9688f807d4853ac9fefca228decbc3bb3851be9f75a8898b5f483435"},
80 {GURL("https://control4.test"),
81 "57e66a432b7661a426f4e9f470f7f5ff259870931277ac4e00853d3a237895f1"},
82 {GURL("https://control0.test"),
83 "7653aed3ed0e08c4abd4035e6f24ad1b4705387bffed42c5955abdcabda5b2fc"},
84 {GURL("https://control5.test"),
85 "8cca9122cb6f459552422aef9536daf9fce3a4648729fe2ab17bc63a5c8cd9d9"},
86 {GURL("https://control7.test"),
87 "8d9ff576c2e4a834dd75b1a0b2acbc0b3ce89035feb1c1645e96d24e803a08a5"},
88 {GURL("https://control1.test"),
89 "d4a33fe8bbb13fce2300bd1788b2df1722605f8f30bc1119c8ca3f8aea32e1e5"},
90 {GURL("https://control8.test"),
91 "e161ddfb174571df3db808e18f8177c9bbfdb545108616bd62434280b5ca2b37"},
92 {GURL("https://control3.test"),
93 "f8bb464ff13462fde12aac03f9e66f3d37a3b9359992fca01428480bd1418e02"}};
94 GURL non_control_site("https://example-not-control.test");
95
96 // Setup proto (as if read from component installer).
97 auto config = std::make_unique<LegacyTLSExperimentConfig>();
Christopher Thompsonbe9cafe2020-02-05 04:46:1198 config->set_version_id(1);
calamityaa4a2212019-10-02 04:53:0499 for (auto& site : kControlSites) {
100 config->add_control_site_hashes(site.hash);
101 }
Christopher Thompsonbe9cafe2020-02-05 04:46:11102 SetRemoteTLSDeprecationConfig(config->SerializeAsString());
calamityaa4a2212019-10-02 04:53:04103
104 for (auto& site : kControlSites) {
Christopher Thompson6f9194222019-10-11 00:20:22105 EXPECT_TRUE(ShouldSuppressLegacyTLSWarning(site.url));
calamityaa4a2212019-10-02 04:53:04106 }
107
Christopher Thompson6f9194222019-10-11 00:20:22108 EXPECT_FALSE(ShouldSuppressLegacyTLSWarning(non_control_site));
calamityaa4a2212019-10-02 04:53:04109}